diff options
| author | Tim Keller <tjk@tjkeller.xyz> | 2025-06-24 19:26:15 -0500 |
|---|---|---|
| committer | Tim Keller <tjk@tjkeller.xyz> | 2025-06-24 19:26:15 -0500 |
| commit | 4be4fd53b3f71d1da55fc7f4c31640bf6f1c4992 (patch) | |
| tree | 2a930728b4d5d81820211bd7790d9684f0a9f252 /flaskapi.py | |
| parent | ffa5ff333eabffe07394fb21bc413d7d238ee651 (diff) | |
| parent | 4c3d572eb850c32a45ec9cbaf82688d45c1eebf4 (diff) | |
| download | immich-frame-4be4fd53b3f71d1da55fc7f4c31640bf6f1c4992.tar.xz immich-frame-4be4fd53b3f71d1da55fc7f4c31640bf6f1c4992.zip | |
merge pixpy repo into this repo
Diffstat (limited to 'flaskapi.py')
| -rw-r--r-- | flaskapi.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/flaskapi.py b/flaskapi.py new file mode 100644 index 0000000..633eed2 --- /dev/null +++ b/flaskapi.py @@ -0,0 +1,88 @@ +from flask import Flask, Blueprint, request, send_from_directory, send_file, abort, redirect, jsonify +from flask_socketio import SocketIO, emit +from flask_cors import CORS + +from manager import PixMan +from settings import Config + + +app = Flask(__name__, static_folder="static/dist", static_url_path="/") +api = Blueprint("api", __name__) +socketio = SocketIO(app, cors_allowed_origins="*") # NOTE debug +CORS(api, origins="*") # NOTE debug + + +@app.route("/") +@app.route("/slideshow") +@app.route("/albums") +@app.route("/settings") +def home(): + return send_from_directory("static/public", "index.html") + + +@socketio.on("seek") +def seek(increment): + if not (display := PixMan().display): + return {} + display.queue.put(lambda: display.seek(increment)) + while not display.queue.empty(): + pass + return { "imageIndex": display.current_texture_index } + + +@api.route("/albums/update", methods=["POST"]) +def albums_update(): + return { "success": PixMan().update_config({ "album_list": request.json }) } + +@api.route("/albums") +def albums_get(): + if not (ic := PixMan().immich_connector): + return {} + keys = [ "albumName", "albumThumbnailAssetId", "id", "startDate", "endDate", "assetCount", "shared", ] + selected_albums = PixMan().config.album_list + return [{ + key: album.get(key, None) for key in keys + } | { "selected": album["id"] in selected_albums } for album in ic.load_all_albums() if album["assetCount"] ] + + +@api.route("/asset/<key>/filename") +def get_asset_name(key): + if not (ic := PixMan().immich_connector): + return {} + # TODO ensure getting actual album thumb + name = ic.load_image_filename(key) + if name is None: + abort(400) + return { "filename": name } + + +@api.route("/asset/<key>/fullsize", defaults={ "size": "fullsize" }) +@api.route("/asset/<key>/thumbnail", defaults={ "size": "thumbnail" }) +@api.route("/asset/<key>", defaults={ "size": "preview" }) +def get_asset(key, size): + if not (ic := PixMan().immich_connector): + return {} + # TODO ensure getting actual album thumb + 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): + 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) } + +@api.route("/config") +def config_get(): + return jsonify(PixMan().config) + + +app.register_blueprint(api, url_prefix="/api") |
