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
48
49
50
51
52
53
54
55
|
from flask import Flask, Blueprint, request, send_from_directory, send_file, abort, redirect
from flask_socketio import SocketIO, emit
from flask_cors import CORS
app = Flask(__name__, static_folder="static/dist", static_url_path="/")
socketio = SocketIO(app, cors_allowed_origins="*") # TODO remove later
@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")
@socketio.on("seek")
def seek(increment):
pd = app.config["pix_display"]
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")
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("/asset/<key>/thumbnail", defaults={ "size": "thumbnail" })
@api.route("/asset/<key>", defaults={ "size": "preview" })
def get_asset(key, size):
# 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"]
return redirect(f"{ic.server_url}/{path}")
app.register_blueprint(api, url_prefix="/api")
|