You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.0 KiB
41 lines
1.0 KiB
from __future__ import annotations |
|
|
|
import json |
|
import secrets |
|
from pathlib import Path |
|
|
|
from flask import Flask |
|
|
|
from .routes import ui |
|
|
|
|
|
def _load_secret_key(conf_path: Path) -> str: |
|
default_key = secrets.token_hex(32) |
|
|
|
if not conf_path.exists(): |
|
return default_key |
|
|
|
try: |
|
payload = json.loads(conf_path.read_text(encoding="utf-8")) |
|
except Exception: |
|
return default_key |
|
|
|
value = payload.get("secret_key") if isinstance(payload, dict) else None |
|
if isinstance(value, str) and value.strip(): |
|
return value.strip() |
|
return default_key |
|
|
|
|
|
def create_app() -> Flask: |
|
app = Flask(__name__) |
|
|
|
frontend_root = Path(__file__).resolve().parents[1] |
|
project_root = Path(__file__).resolve().parents[2] |
|
conf_path = frontend_root / "data" / "conf.json" |
|
|
|
app.config["PROJECT_ROOT"] = project_root |
|
app.config["MUSIC_DIR"] = project_root / "backend" / "data" / "musiques" |
|
app.secret_key = _load_secret_key(conf_path) |
|
|
|
app.register_blueprint(ui) |
|
return app
|
|
|