feat: manage saved thumbnail plans and select plans for tasks
Community checks / verify (push) Skipped
Verify Frame Flow / verify (push) Failing after 5m58s

This commit is contained in:
渡口浪人
2026-10-23 14:47:27 +08:00
parent d94031eb50
commit 7178235022
17 changed files with 1736 additions and 37 deletions
+14 -6
View File
@@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
SIZE = (410, 502)
def publish(service, device_id, asset_id, data=None):
def publish(service, device_id, asset_id, data=None, plan_id=None):
# Templates and old gallery assets have no verified undecorated source.
row = service.db.one(
"SELECT payload FROM asset_sources WHERE asset_id=?", (asset_id,)
@@ -23,25 +23,33 @@ def publish(service, device_id, asset_id, data=None):
if source.get("type") != "photo_source":
return None
try:
from pigway_frame_flow.display.thumbnail_plans import get_plan, render
plan = get_plan(service, plan_id) if plan_id else None
size = (plan.width, plan.height) if plan else SIZE
if data is None:
data, _, _ = service.photo_sources.read(
source["source_id"], source["item_id"], target_size=SIZE
source["source_id"], source["item_id"], target_size=size
)
rendered = convert(data, "cover", "color", size=SIZE)
rendered = (
render(data, plan) if plan else convert(data, "cover", "color", size=SIZE)
)
asset = service.assets.put(rendered, "watch.jpg", "cache")
now = datetime.now(ZoneInfo(service.settings.timezone))
result = {
"asset_id": asset["asset_id"],
"url": asset["url"],
"width": SIZE[0],
"height": SIZE[1],
"width": size[0],
"height": size[1],
"date": now.date().isoformat(),
"timezone": service.settings.timezone,
"generated_at": now.isoformat(),
"sha256": hashlib.sha256(rendered).hexdigest(),
"bytes": len(rendered),
"source": source,
"fit": "cover",
"fit": plan.fit if plan else "cover",
"plan_id": plan_id,
"plan": plan.model_dump() if plan else None,
"source_rendition": "preview"
if service.photo_sources.get(source["source_id"]).kind == "synology-photos"
else "source",