feat(immich): write-back (upsert_tag, tag_assets) + _pipeline tag conventions
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from photoflow.immich.client import ImmichClient
|
||||
from photoflow.immich import pipeline
|
||||
|
||||
__all__ = ["ImmichClient"]
|
||||
__all__ = ["ImmichClient", "pipeline"]
|
||||
|
||||
@@ -72,3 +72,22 @@ class ImmichClient:
|
||||
timeout=self.timeout)
|
||||
r.raise_for_status()
|
||||
return r.content
|
||||
|
||||
def upsert_tag(self, name: str) -> str:
|
||||
r = self.session.put(self._url("/api/tags"),
|
||||
json={"tags": [name]}, timeout=self.timeout)
|
||||
r.raise_for_status()
|
||||
for tag in r.json():
|
||||
if tag.get("value") == name or tag.get("name") == name:
|
||||
return tag["id"]
|
||||
resolved = self.resolve_tag_id(name)
|
||||
if resolved is None:
|
||||
raise RuntimeError(f"upsert_tag: could not resolve id for {name!r}")
|
||||
return resolved
|
||||
|
||||
def tag_assets(self, tag_id: str, asset_ids: list[str]) -> None:
|
||||
if not asset_ids:
|
||||
return
|
||||
r = self.session.put(self._url(f"/api/tags/{tag_id}/assets"),
|
||||
json={"ids": asset_ids}, timeout=self.timeout)
|
||||
r.raise_for_status()
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
ROOT = "_pipeline"
|
||||
PROCESSED = f"{ROOT}/processed"
|
||||
NON_TRIP = f"{ROOT}/non-trip"
|
||||
|
||||
|
||||
def ai_rating(n: int) -> str:
|
||||
return f"{ROOT}/ai-rating/{n}"
|
||||
|
||||
|
||||
def is_pipeline_tag(name: str) -> bool:
|
||||
return name == ROOT or name.startswith(ROOT + "/")
|
||||
Reference in New Issue
Block a user