summaryrefslogtreecommitdiff
path: root/flaskapi.py
diff options
context:
space:
mode:
authorTim Keller <tjk@tjkeller.xyz>2025-06-16 21:50:38 -0500
committerTim Keller <tjk@tjkeller.xyz>2025-06-16 21:50:38 -0500
commitb8df4605b42d9a61bb4ae4731efabbdc38166063 (patch)
treed0044ca3c47c00442d15a99da6e309c08601b99e /flaskapi.py
parentcd1657ece1fa199964abd6544b81b394ab9369aa (diff)
downloadimmich-frame-b8df4605b42d9a61bb4ae4731efabbdc38166063.tar.xz
immich-frame-b8df4605b42d9a61bb4ae4731efabbdc38166063.zip
add config and add application thread manager
Diffstat (limited to 'flaskapi.py')
-rw-r--r--flaskapi.py41
1 files changed, 26 insertions, 15 deletions
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/<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
- 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/<path:path>")
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")