fix: make photo retention and exclusion mutually exclusive
This commit is contained in:
@@ -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)",
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user