feat: account sessions and usable template editors

This commit is contained in:
Pigway
2026-10-02 08:43:07 +08:00
parent 186b56c495
commit 141849d682
12 changed files with 515 additions and 33 deletions
+33
View File
@@ -1,3 +1,4 @@
import calendar
import json
from datetime import datetime
from io import BytesIO
@@ -99,6 +100,38 @@ class TemplateRenderer:
x, y, w, h = block["box"]
if block["kind"] == "rule":
draw.rectangle((x, y, x + w, y + h), fill=accent)
elif block["kind"] == "month":
try:
shown = datetime.strptime(str(values["date"]), "%Y-%m-%d")
except ValueError:
raise FlowError(
E.INVALID_REQUEST, "Calendar date must be YYYY-MM-DD"
) from None
text(shown.strftime("%Y-%m"), x, y, w, 70, 48)
cells = calendar.Calendar(firstweekday=0).monthdayscalendar(
shown.year, shown.month
)
cell_w, cell_h = w // 7, (h - 140) // len(cells)
for col, label in enumerate(
["一 M", "二 T", "三 W", "四 T", "五 F", "六 S", "日 S"]
):
text(label, x + col * cell_w + 10, y + 80, cell_w - 20, 60, 30)
for row, week in enumerate(cells):
for col, day in enumerate(week):
if not day:
continue
left, top = x + col * cell_w, y + 140 + row * cell_h
if (shown.year, shown.month, day) == (
current.year,
current.month,
current.day,
):
draw.rectangle(
(left, top, left + cell_w - 6, top + cell_h - 6),
outline=accent,
width=5,
)
text(day, left + 25, top + 10, cell_w - 35, cell_h, 38)
elif block["kind"] == "photo":
asset_id = values.get("photo_id")
if asset_id: