fix: make photo retention and exclusion mutually exclusive
Community checks / verify (push) Skipped
Verify Frame Flow / verify (push) Successful in 6m10s

This commit is contained in:
渡口浪人
2026-10-20 19:19:30 +08:00
parent b770626a66
commit 95625c5857
9 changed files with 187 additions and 34 deletions
@@ -1,5 +1,17 @@
"""Persistent selection preferences scoped to a library and its stable item ID."""
from pigway_frame_flow.errors import ErrorCode as E
from pigway_frame_flow.errors import FlowError
def ensure_compatible(starred, excluded):
if starred and excluded:
raise FlowError(
E.CONFLICT,
"Starred photos cannot be excluded; clear the existing mark first",
409,
)
def flags(db, source_id, item_id):
row = db.one(
@@ -11,6 +23,16 @@ def flags(db, source_id, item_id):
def set_flags(db, source_id, item_id, *, starred=None, excluded=None):
with db.transaction() as connection:
current = flags(db, source_id, item_id)
if source_id == "@assets":
meta = db.one(
"SELECT starred FROM asset_metadata WHERE asset_id=?", (item_id,)
)
current["starred"] = bool(meta and meta["starred"])
ensure_compatible(
current["starred"] if starred is None else starred,
current["excluded"] if excluded is None else excluded,
)
connection.execute(
"INSERT INTO photo_preferences(source_id,item_id,starred,excluded) VALUES(?,?,?,?) ON CONFLICT(source_id,item_id) DO UPDATE SET starred=coalesce(?,starred),excluded=coalesce(?,excluded)",
(