feat: add ImmichClient
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from app.clients.base import BaseHTTPClient
|
||||
from app.config import Settings
|
||||
from app.models.sources import ImmichSnapshot
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ImmichClient(BaseHTTPClient):
|
||||
def __init__(self, settings: Settings) -> None:
|
||||
super().__init__(settings, "immich", settings.immich_base_url)
|
||||
|
||||
async def fetch_stats(self) -> ImmichSnapshot:
|
||||
snapshot = ImmichSnapshot()
|
||||
if not self.base_url or not self.settings.immich_api_key:
|
||||
logger.info("immich skipped: base URL or API key missing")
|
||||
return snapshot
|
||||
|
||||
headers = {"x-api-key": self.settings.immich_api_key}
|
||||
|
||||
try:
|
||||
data = await self._request_json("GET", "/api/server/statistics", headers=headers)
|
||||
except Exception as exc:
|
||||
logger.warning("immich fetch_stats failed: %s", exc)
|
||||
return snapshot
|
||||
|
||||
if not isinstance(data, dict):
|
||||
logger.warning("immich unexpected response type: %s", type(data))
|
||||
return snapshot
|
||||
|
||||
photos = int(data.get("photos", 0))
|
||||
videos = int(data.get("videos", 0))
|
||||
usage_bytes = int(data.get("usage", 0))
|
||||
usage_gb = round(usage_bytes / (1024 ** 3), 1)
|
||||
|
||||
return ImmichSnapshot(
|
||||
source_status="online",
|
||||
photos=photos,
|
||||
videos=videos,
|
||||
storage_gb=usage_gb,
|
||||
)
|
||||
Reference in New Issue
Block a user