1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
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/<key>")
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")
|