feat: add Immich API client and photo proxy routes
Implements ImmichClient with list_albums, get_album, get_thumbnail, get_original methods; wraps connection errors as ConnectionError. Adds /proxy/thumb/<asset_id> and /proxy/original/<asset_id> Flask routes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,29 @@
|
||||
from flask import Blueprint
|
||||
from flask import Blueprint, current_app, Response, abort
|
||||
from app.immich import ImmichClient
|
||||
|
||||
bp = Blueprint("proxy", __name__)
|
||||
|
||||
|
||||
def _client() -> ImmichClient:
|
||||
return ImmichClient(
|
||||
base_url=current_app.config["IMMICH_URL"],
|
||||
api_key=current_app.config["IMMICH_API_KEY"],
|
||||
)
|
||||
|
||||
|
||||
@bp.get("/proxy/thumb/<asset_id>")
|
||||
def thumb(asset_id):
|
||||
try:
|
||||
data = _client().get_thumbnail(asset_id)
|
||||
except ConnectionError:
|
||||
abort(502)
|
||||
return Response(data, content_type="image/jpeg")
|
||||
|
||||
|
||||
@bp.get("/proxy/original/<asset_id>")
|
||||
def original(asset_id):
|
||||
try:
|
||||
data = _client().get_original(asset_id)
|
||||
except ConnectionError:
|
||||
abort(502)
|
||||
return Response(data, content_type="image/jpeg")
|
||||
|
||||
Reference in New Issue
Block a user