Add starred cloud photos and opt-in seven-day random upload retention

This commit is contained in:
Pigway
2026-10-06 09:10:36 +08:00
parent 0a5b859ca0
commit c005a9444a
16 changed files with 643 additions and 7 deletions
+22
View File
@@ -5,6 +5,7 @@ import time
from datetime import UTC, datetime, timedelta
from uuid import uuid4
from pigway_frame_flow.display.retention import Retention
from pigway_frame_flow.drivers.base import DriverRegistry
from pigway_frame_flow.errors import ErrorCode as E
from pigway_frame_flow.errors import FlowError
@@ -36,6 +37,7 @@ class DisplayService:
renderer,
)
self.lock = threading.RLock()
self.retention = Retention(self)
self.expiration_checked: dict[str, float] = {}
# A killed write cannot be replayed safely; pre-write work can resume.
db.execute(
@@ -400,6 +402,16 @@ class DisplayService:
state = self.state(device_id)
if action == "delete":
image_id = payload["image_id"]
if payload.get("retention") and (
not self.retention.eligible(device_id, image_id) or image_id == previous
):
self.db.execute(
"UPDATE image_retention SET cleanup_operation=NULL WHERE device_id=? AND image_id=?",
(device_id, image_id),
)
self.update(id, "COMPLETED", {"image_id": image_id, "deferred": True})
self.db.history(op, "RETENTION_PROTECTED")
return
protected = {state["previous_image_id"], state["base_image_id"]} | {
x["image_id"]
for x in self.db.all(
@@ -420,6 +432,10 @@ class DisplayService:
"DELETE FROM image_sources WHERE device_id=? AND image_id=?",
(device_id, image_id),
)
self.db.execute(
"DELETE FROM image_retention WHERE device_id=? AND image_id=?",
(device_id, image_id),
)
driver.invalidate()
self.update(id, "COMPLETED", {"image_id": image_id})
self.db.history(op, "COMPLETED")
@@ -478,6 +494,12 @@ class DisplayService:
if asset:
self.update(id, "UPLOADING")
image_id = driver.upload(self.assets.path(asset["asset_id"]), asset["name"])
if (
request.options.cleanup_unstarred
and isinstance(content, PhotoSourceContent)
and content.item_id is None
):
self.retention.register(device_id, image_id, id)
elif isinstance(content, ImageContent) and content.image_name:
driver.display_by_name(content.image_name)
else: