Files
pigway-frame-flow/pigway_frame_flow/display/thumbnail_gallery.py
T

38 lines
1.3 KiB
Python
Raw Normal View History

"""Separate watch gallery metadata; image files retain existing asset access rules."""
import json
from pigway_frame_flow.storage.database import encode
TARGET_ID = "watch"
def record(service, asset_id, metadata):
service.db.execute(
"INSERT OR REPLACE INTO asset_sources VALUES(?,?)",
(asset_id, encode({**metadata, "type": "thumbnail", "target_id": TARGET_ID})),
)
def recover(service):
# Earlier automatic thumbnails have authoritative operation receipts. Never
# guess that an unrelated image is a thumbnail from its name or dimensions.
rows = service.db.all("SELECT result FROM operations WHERE result IS NOT NULL")
receipts = [json.loads(row["result"]).get("wrist_thumbnail") for row in rows]
receipts += [
json.loads(row["payload"])
for row in service.db.all(
"SELECT payload FROM app_config WHERE key LIKE 'wrist-thumbnail:%'"
)
]
for receipt in receipts:
if not isinstance(receipt, dict) or not receipt.get("asset_id"):
continue
asset_id = receipt["asset_id"]
if service.db.one(
"SELECT id FROM assets WHERE id=?", (asset_id,)
) and not service.db.one(
"SELECT asset_id FROM asset_sources WHERE asset_id=?", (asset_id,)
):
record(service, asset_id, receipt)