Änderung Controller

This commit is contained in:
Erik Thiele
2026-05-27 23:08:12 +02:00
parent 08b57d447f
commit 186b778051
3 changed files with 115 additions and 24 deletions

26
app.py
View File

@@ -1,6 +1,7 @@
from __future__ import annotations
import os
import time
from pathlib import Path
from flask import Flask, abort, jsonify, redirect, render_template, request, send_from_directory, url_for
@@ -17,6 +18,17 @@ ALLOWED_EXTENSIONS = {
app = Flask(__name__)
app.config["UPLOAD_FOLDER"] = str(UPLOAD_DIR)
APP_VERSION = "1.0.0"
@app.context_processor
def inject_globals():
return {
"app_year": time.localtime().tm_year,
"app_version": APP_VERSION,
"app_host": request.host.split(":")[0],
}
# ── Player State ──────────────────────────────────────────────────────
player_state = {
@@ -27,6 +39,9 @@ player_state = {
"volume": 1.0,
}
_display_last_seen = 0.0
DISPLAY_TIMEOUT = 8
def _bump():
player_state["version"] += 1
@@ -102,7 +117,9 @@ def controller():
# ── Player API ────────────────────────────────────────────────────────
@app.route("/api/state")
def api_state():
return jsonify(player_state)
resp = dict(player_state)
resp["display_online"] = (time.time() - _display_last_seen) < DISPLAY_TIMEOUT
return jsonify(resp)
@app.route("/api/play", methods=["POST"])
@@ -179,6 +196,13 @@ def api_seek_ack():
return jsonify({"ok": True})
@app.route("/api/display/ping", methods=["POST"])
def api_display_ping():
global _display_last_seen
_display_last_seen = time.time()
return jsonify({"ok": True})
@app.route("/api/volume", methods=["POST"])
def api_volume():
data = request.get_json(silent=True) or {}