fix: restore photo captions and place recognized people after date [skip ci]

This commit is contained in:
渡口浪人
2026-10-17 23:28:04 +08:00
parent bda5229183
commit a86a9e2080
15 changed files with 143 additions and 16 deletions
@@ -2,6 +2,7 @@
import base64
import json
import logging
import os
import posixpath
import random
@@ -618,6 +619,19 @@ class PhotoSources:
data = self.synology.download(
self.api_items[source_id][item["id"]], space=source.people_space
)
if source.folder_caption:
caption = dict(item.get("caption") or {})
caption["filename"] = item["name"]
try:
caption["people"] = " · ".join(
self.synology.item_people(item["id"], space=source.people_space)
)
except FlowError:
# Optional labels must not prevent displaying a valid photo.
logging.getLogger(__name__).warning(
"Photos person labels unavailable; keeping photo caption"
)
item = {**item, "caption": caption}
elif source.kind in ("google-drive", "alipan", "baidu"):
from pigway_frame_flow.providers.cloud_drives import CloudDrives
@@ -315,6 +315,26 @@ class SynologyPhotos:
merged = {key: row for group in groups for key, row in group.items()}
return [merged[key] for key in sorted(selected, key=int)][:limit]
def item_people(self, item_id, *, space="shared"):
"""Reuse verified person albums; never label an unnamed face by its ID."""
prefix = "SYNO.FotoTeam" if space == "shared" else "SYNO.Foto"
with self.lock:
key = ("caption-people", self.sid(), space)
cached = self.cache.get(key)
if not cached or time.monotonic() - cached[0] >= 900:
names: dict[str, list[str]] = {}
for person in self.people(space):
if not person["named"]:
continue
for row in self.pages(
prefix + ".Browse.Item", 7, person_id=person["id"]
):
item_names = names.setdefault(str(row["id"]), [])
if person["name"] not in item_names:
item_names.append(person["name"])
self.cache[key] = (time.monotonic(), names)
return list(self.cache[key][1].get(str(item_id), []))
def download(self, row, *, space="shared", rendition="thumbnail"):
from pigway_frame_flow.providers.photos_cache import PhotosCache