make all responses from /api json

This commit is contained in:
deneb 2025-02-25 22:15:25 +01:00
parent 16b8b3fcc4
commit bc83fa7848

14
app.py
View file

@ -1,5 +1,5 @@
from typing import Any, Mapping
from flask import Flask, render_template, send_file, Response
from flask import Flask, render_template, send_file, jsonify
import os
import subprocess
import signal
@ -125,24 +125,24 @@ def filemgr(path=""):
@app.route("/api/start", methods=["POST"])
def api_start():
if is_playing():
return Response("Laas is already lofi'ing", 400)
return jsonify("Laas is already lofi'ing"), 400
else:
playback_start()
return Response("ok", 200)
return jsonify('ok'), 200
@app.route("/api/stop", methods=["POST"])
def api_stop():
if not is_playing():
return Response("You cant stop when theres no playback, womp womp!", 400)
return jsonify("You cant stop when theres no playback, womp womp!"), 400
else:
playback_stop()
return Response("ok", 200)
return jsonify('ok'), 200
@app.route("/api/status", methods=["GET"])
def api_status():
return Response(str(is_playing()).lower(), headers={"Content-Type": "text/json"})
return jsonify(is_playing())
@app.route("/api/nowplaying", methods=["GET"])
@ -181,7 +181,7 @@ def api_nowplaying():
reply_json: Mapping[str, Any] = json.loads(reply.decode())
response[key] = reply_json["data"] if "data" in reply_json else "Unknown"
return Response(json.dumps(response), headers={"Content-Type": "text/json"})
return jsonify(response)
signal.signal(signal.SIGTERM, sigh)