Add dummy room

This commit is contained in:
Leonardo Segala 2025-08-02 00:19:07 +02:00
parent 96fbe8058b
commit bc9bf71824
3 changed files with 30 additions and 2 deletions

View file

@ -9,6 +9,8 @@ from .room import Room
from .song import Song, init_db, get_song_by_title_artist, add_song_in_db
from .song_fetch import lastfm_query_search, download_song_mp3
from typing import Any
dotenv.load_dotenv()
@ -21,6 +23,18 @@ db_conn = get_connection()
state = State(app, db_conn.cursor())
init_db(state.db)
state.rooms[1000] = Room(
id=1000,
coord=(1.0, 5.5),
name="Test Room",
pin=None,
tags=set(),
songs={},
history=[],
playing=[Song(uuid="<uuid>", title="<title>", artist="<artist>", tags=[], image_id="<img>", youtube_id="<yt>")],
playing_idx=0,
)
def error(msg: str, status: int = 400) -> Response:
res = jsonify({"success": False, "error": msg})
@ -28,6 +42,17 @@ def error(msg: str, status: int = 400) -> Response:
return res
def ws_broadcast(event: str, *, room_id: int | None = None, data: Any) -> None:
final = {}
if room_id is not None:
final["room_id"] = room_id
final["data"] = data
emit(event, final, broadcast=True, namespace="/")
@app.get("/api/join")
def join():
room_id = request.args.get("room")
@ -144,6 +169,8 @@ def add_song():
## add in DB
add_song_in_db(info.artist, info.title, info.tags, info.img_id, yt_id)
## HERE: add song in the room list
return {"artist": info.artist, "title": info.title, "tags": info.tags, "image_id": info.img_id}