from flask import Flask, Blueprint, request, send_from_directory, send_file, abort from flask_cors import CORS app = Flask(__name__, static_folder="static/dist", static_url_path="/") @app.route("/") @app.route("/slideshow") @app.route("/albums") @app.route("/settings") 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") def seek(): 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 return { "imageTime": pd.image_time, "imageIndex": pd.current_texture_index, } @api.route("/albums/get") def get_albums(): ic = app.config["immich_connector"] 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("/albums/thumb/") def get_album_thumb(key): # TODO ensure getting actual album thumb ic = app.config["immich_connector"] image_data, mimetype = ic.load_image(key, size="thumbnail") if image_data is None: abort(400) return send_file(image_data, mimetype=mimetype) app.register_blueprint(api, url_prefix="/api")