Add queue next endpoint
This commit is contained in:
parent
51aafb9771
commit
2df62ff714
3 changed files with 24 additions and 4 deletions
|
@ -1,6 +1,8 @@
|
|||
import dotenv
|
||||
from flask import Flask, Response, jsonify, request
|
||||
|
||||
from flask_cors import CORS
|
||||
from flask_socketio import SocketIO, emit
|
||||
|
||||
from .room import Room
|
||||
from .song import Song, init_db
|
||||
|
@ -11,6 +13,8 @@ dotenv.load_dotenv()
|
|||
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config["SECRET_KEY"] = "your_secret_key"
|
||||
socketio = SocketIO(app)
|
||||
CORS(app)
|
||||
|
||||
|
||||
|
@ -24,6 +28,7 @@ ROOMS: dict[int, Room] = {
|
|||
{},
|
||||
[],
|
||||
[Song(mbid="test", title="<title placeholder>", artist="<artist placeholder>", tags=["Metal"], image_id="img-id", youtube_id="yt-id")],
|
||||
playing_idx=1,
|
||||
)
|
||||
} # { room_id: room, ... }
|
||||
|
||||
|
@ -63,13 +68,26 @@ def queue():
|
|||
|
||||
|
||||
@app.post("/api/queue/next")
|
||||
def queue_next(): ...
|
||||
def queue_next():
|
||||
if (room_id := request.args.get("room")) is None:
|
||||
return error("Missing room id")
|
||||
|
||||
if (room := ROOMS.get(int(room_id))) is None:
|
||||
return error("Invalid room")
|
||||
|
||||
@app.post("/api/queue/renew")
|
||||
def queue_renew(): ...
|
||||
room.playing_idx += 1
|
||||
|
||||
if room.playing_idx >= len(room.playing):
|
||||
## queue ended
|
||||
|
||||
# room.renew_queue()
|
||||
emit("update_songs", {"songs": [1, 2, 3]}, broadcast=True, namespace="/")
|
||||
|
||||
return {"success": True, "ended": True, "index": room.playing_idx, "queue": []}
|
||||
|
||||
return {"success": True, "ended": False, "index": room.playing_idx}
|
||||
|
||||
|
||||
init_db()
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
socketio.run(app, debug=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue