diff options
| author | Tim Keller <tjk@tjkeller.xyz> | 2025-06-15 15:06:34 -0500 |
|---|---|---|
| committer | Tim Keller <tjk@tjkeller.xyz> | 2025-06-15 15:06:34 -0500 |
| commit | cd1657ece1fa199964abd6544b81b394ab9369aa (patch) | |
| tree | 5b9448f8fb720d5be4ae8105ff543cdff0fe047a /flaskapi.py | |
| parent | e1a6fc09afc088dcb67263ed5923f5be41c32c31 (diff) | |
| download | immich-frame-cd1657ece1fa199964abd6544b81b394ab9369aa.tar.xz immich-frame-cd1657ece1fa199964abd6544b81b394ab9369aa.zip | |
callbacks on lctl, websocket controls
Diffstat (limited to 'flaskapi.py')
| -rw-r--r-- | flaskapi.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/flaskapi.py b/flaskapi.py index 0791016..a537192 100644 --- a/flaskapi.py +++ b/flaskapi.py @@ -1,7 +1,9 @@ -from flask import Flask, Blueprint, request, send_from_directory, send_file, abort +from flask import Flask, Blueprint, request, send_from_directory, send_file, abort, redirect +from flask_socketio import SocketIO, emit from flask_cors import CORS app = Flask(__name__, static_folder="static/dist", static_url_path="/") +socketio = SocketIO(app, cors_allowed_origins="*") # TODO remove later @app.route("/") @app.route("/slideshow") @@ -13,11 +15,11 @@ def home(): api = Blueprint("api", __name__) CORS(api, origins="*") # For debugging TODO remove later -@api.route("/seek") -def seek(): +#@api.route("/seek") +@socketio.on("seek") +def seek(increment): pd = app.config["pix_display"] - increment = request.args.get("increment", default=1, type=int) pd.queue.put(lambda: pd.seek(increment)) while not pd.queue.empty(): pass @@ -26,7 +28,7 @@ def seek(): "imageIndex": pd.current_texture_index, } -@api.route("/albums/get") +@api.route("/albums") def get_albums(): ic = app.config["immich_connector"] keys = [ "albumName", "albumThumbnailAssetId", "id", "startDate", "endDate", "assetCount", "shared", ] @@ -34,14 +36,20 @@ def get_albums(): key: album[key] for key in keys } for album in ic.load_all_albums() ] -@api.route("/albums/thumb/<key>") -def get_album_thumb(key): +@api.route("/asset/<key>/thumbnail", defaults={ "size": "thumbnail" }) +@api.route("/asset/<key>", defaults={ "size": "preview" }) +def get_asset(key, size): # TODO ensure getting actual album thumb ic = app.config["immich_connector"] - image_data, mimetype = ic.load_image(key, size="thumbnail") + image_data, mimetype = ic.load_image(key, size=size) if image_data is None: abort(400) return send_file(image_data, mimetype=mimetype) +@api.route("/redirect/<path:path>") +def immich_redirect(path): + ic = app.config["immich_connector"] + return redirect(f"{ic.server_url}/{path}") + app.register_blueprint(api, url_prefix="/api") |
