203737cc3f
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>
30 lines
735 B
Python
30 lines
735 B
Python
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")
|