From b8df4605b42d9a61bb4ae4731efabbdc38166063 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Mon, 16 Jun 2025 21:50:38 -0500 Subject: add config and add application thread manager --- flaskapi.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'flaskapi.py') diff --git a/flaskapi.py b/flaskapi.py index a537192..45616ec 100644 --- a/flaskapi.py +++ b/flaskapi.py @@ -2,8 +2,14 @@ from flask import Flask, Blueprint, request, send_from_directory, send_file, abo from flask_socketio import SocketIO, emit from flask_cors import CORS +from manager import PixMan + + app = Flask(__name__, static_folder="static/dist", static_url_path="/") -socketio = SocketIO(app, cors_allowed_origins="*") # TODO remove later +api = Blueprint("api", __name__) +socketio = SocketIO(app, cors_allowed_origins="*") # NOTE debug +CORS(api, origins="*") # NOTE debug + @app.route("/") @app.route("/slideshow") @@ -12,44 +18,49 @@ socketio = SocketIO(app, cors_allowed_origins="*") # TODO remove later def home(): return send_from_directory("static/public", "index.html") -api = Blueprint("api", __name__) -CORS(api, origins="*") # For debugging TODO remove later -#@api.route("/seek") @socketio.on("seek") def seek(increment): - pd = app.config["pix_display"] - - pd.queue.put(lambda: pd.seek(increment)) - while not pd.queue.empty(): + if not (display := PixMan().display): + return {} + display.queue.put(lambda: display.seek(increment)) + while not display.queue.empty(): pass - return { - "imageTime": pd.image_time, - "imageIndex": pd.current_texture_index, - } + return { "imageIndex": display.current_texture_index } + @api.route("/albums") def get_albums(): - ic = app.config["immich_connector"] + if not (ic := PixMan().immich_connector): + return {} keys = [ "albumName", "albumThumbnailAssetId", "id", "startDate", "endDate", "assetCount", "shared", ] return [{ key: album[key] for key in keys } for album in ic.load_all_albums() ] + @api.route("/asset//thumbnail", defaults={ "size": "thumbnail" }) @api.route("/asset/", defaults={ "size": "preview" }) def get_asset(key, size): + if not (ic := PixMan().immich_connector): + return {} # TODO ensure getting actual album thumb - ic = app.config["immich_connector"] 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/") def immich_redirect(path): - ic = app.config["immich_connector"] + if not (ic := PixMan().immich_connector): + return {} return redirect(f"{ic.server_url}/{path}") +@api.route("/config/update", methods=["POST"]) +def config_update(): + return { "success": PixMan().update_config(request.json) } + + app.register_blueprint(api, url_prefix="/api") -- cgit v1.2.3