From d29badd0fe1aa23698edc3b5f2af112024563d03 Mon Sep 17 00:00:00 2001 From: Karl Date: Mon, 28 Jul 2025 13:27:52 +0100 Subject: [PATCH] serve favourites.json file --- ai_frame_image_server.py | 2 ++ routes/__init__.py | 3 ++- routes/favourites_routes.py | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 routes/favourites_routes.py diff --git a/ai_frame_image_server.py b/ai_frame_image_server.py index e9dcae2..872450a 100644 --- a/ai_frame_image_server.py +++ b/ai_frame_image_server.py @@ -4,6 +4,7 @@ import os from routes import ( auth_routes, + favourites_routes, gallery_routes, image_routes, index_routes, @@ -24,6 +25,7 @@ auth_routes.init_app(user_config) # Register blueprints app.register_blueprint(index_routes.bp) app.register_blueprint(auth_routes.bp) +app.register_blueprint(favourites_routes.bp) app.register_blueprint(gallery_routes.bp) app.register_blueprint(image_routes.bp) app.register_blueprint(job_routes.bp) diff --git a/routes/__init__.py b/routes/__init__.py index 808a9b3..092fc22 100644 --- a/routes/__init__.py +++ b/routes/__init__.py @@ -1,8 +1,9 @@ -from . import auth_routes, create_routes, gallery_routes, image_routes, index_routes, job_routes, settings_routes +from . import auth_routes, create_routes, favourites_routes, gallery_routes, image_routes, index_routes, job_routes, settings_routes __all__ = [ "auth_routes", "create_routes", + "favourites_routes", "gallery_routes", "image_routes", "index_routes", diff --git a/routes/favourites_routes.py b/routes/favourites_routes.py new file mode 100644 index 0000000..9f1f7c3 --- /dev/null +++ b/routes/favourites_routes.py @@ -0,0 +1,23 @@ +from flask import Blueprint, jsonify, send_file +import os +import json + +bp = Blueprint("favourites_routes", __name__) +favourites_file = "./favourites.json" + +def get_favourites(): + if not os.path.exists(favourites_file): + return [] + with open(favourites_file, 'r') as f: + return json.load(f) + +@bp.route("/favourites", methods=["GET"]) +def favourites(): + """ + Route to return the favourites.json file + """ + if os.path.exists(favourites_file): + return send_file(favourites_file, mimetype='application/json') + else: + # If the file doesn't exist, return an empty array as JSON + return jsonify([]) \ No newline at end of file