Match photo selection and rendered canvas to device rotation

This commit is contained in:
Pigway
2026-10-05 22:44:41 +08:00
parent 8139a646d7
commit 59345f12a7
13 changed files with 249 additions and 35 deletions
+15 -6
View File
@@ -247,12 +247,22 @@ class PhotoSources:
pass
return None
def catalog(self, source_id, refresh=False):
def catalog(self, source_id, refresh=False, *, target_size=(1200, 1600)):
source = self.get(source_id)
if not source.enabled:
raise FlowError(E.CONFLICT, "Photo source is disabled", 409)
wanted = (
orientation(*target_size)
if source.orientation == "auto"
else source.orientation
)
cached = self.cache.get(source_id)
if cached and not refresh and time.monotonic() - cached[0] < 60:
if (
cached
and not refresh
and time.monotonic() - cached[0] < 60
and cached[2] == wanted
):
return cached[1]
allowed = (
self.synology.paths(source.person_ids, source.person_match, refresh=refresh)
@@ -266,7 +276,6 @@ class PhotoSources:
else {}
)
size_updates = []
wanted = "portrait" if source.orientation == "auto" else source.orientation
if source.kind == "local":
directory = self.local_directory(source.location)
root = self.settings.photo_root.resolve()
@@ -418,12 +427,12 @@ class PhotoSources:
"INSERT OR REPLACE INTO photo_dimensions(path,mtime,bytes,width,height) VALUES(?,?,?,?,?)",
size_updates,
)
self.cache[source_id] = (time.monotonic(), items)
self.cache[source_id] = (time.monotonic(), items, wanted)
return items
def read(self, source_id, item_id=None):
def read(self, source_id, item_id=None, *, target_size=(1200, 1600)):
source = self.get(source_id)
items = self.catalog(source_id)
items = self.catalog(source_id, target_size=target_size)
if not items:
raise FlowError(
E.NOT_FOUND, "Photo source contains no supported images", 404