add filter to room list
This commit is contained in:
parent
adc362562e
commit
4bf93b565b
2 changed files with 13 additions and 3 deletions
|
@ -11,7 +11,7 @@ from .room import Room
|
||||||
from .song import Song, init_db, get_song_by_title_artist, add_song_in_db, get_song_by_uuid
|
from .song import Song, init_db, get_song_by_title_artist, add_song_in_db, get_song_by_uuid
|
||||||
from .song_fetch import query_search, yt_get_audio_url, yt_search_song
|
from .song_fetch import query_search, yt_get_audio_url, yt_search_song
|
||||||
from .qrcode_gen import generate_qr
|
from .qrcode_gen import generate_qr
|
||||||
from .gps import is_within_range
|
from .gps import is_within_range, distance_between_coords, Coordinates
|
||||||
|
|
||||||
|
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
|
@ -75,7 +75,6 @@ def on_leave(data):
|
||||||
def join():
|
def join():
|
||||||
room_id = request.args.get("room")
|
room_id = request.args.get("room")
|
||||||
code = request.args.get("code")
|
code = request.args.get("code")
|
||||||
user_location = request.args.get("location")
|
|
||||||
|
|
||||||
if room_id is None:
|
if room_id is None:
|
||||||
return error("Missing room id")
|
return error("Missing room id")
|
||||||
|
@ -86,7 +85,7 @@ def join():
|
||||||
if room.pin is not None and room.pin != code:
|
if room.pin is not None and room.pin != code:
|
||||||
return error("Invalid code")
|
return error("Invalid code")
|
||||||
|
|
||||||
if is_within_range(user_location, room.coord, room.range_size) is False:
|
if room.distance > room.range_size:
|
||||||
return error("You are not within the room range")
|
return error("You are not within the room range")
|
||||||
|
|
||||||
return {"success": True, "ws": f"/ws/{room_id}"}
|
return {"success": True, "ws": f"/ws/{room_id}"}
|
||||||
|
@ -164,6 +163,14 @@ def room_new():
|
||||||
|
|
||||||
@app.get("/api/room")
|
@app.get("/api/room")
|
||||||
def room():
|
def room():
|
||||||
|
lat = request.args.get("lat")
|
||||||
|
lon = request.args.get("lon")
|
||||||
|
if lat and lon:
|
||||||
|
user_coords = Coordinates(latitude=float(lat), longitude=float(lon))
|
||||||
|
else:
|
||||||
|
return error("Missing user coordinates")
|
||||||
|
|
||||||
|
distance = distance_between_coords(user_coords, room.coord)
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"id": room.id,
|
"id": room.id,
|
||||||
|
@ -171,8 +178,10 @@ def room():
|
||||||
"private": room.pin is not None,
|
"private": room.pin is not None,
|
||||||
"coords": room.coord,
|
"coords": room.coord,
|
||||||
"range": room.range_size,
|
"range": room.range_size,
|
||||||
|
"distance": distance,
|
||||||
}
|
}
|
||||||
for room in state.rooms.values()
|
for room in state.rooms.values()
|
||||||
|
if distance <= room.range_size
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Room:
|
||||||
pin: int | None
|
pin: int | None
|
||||||
tags: set[str]
|
tags: set[str]
|
||||||
range_size: int # in meters ??
|
range_size: int # in meters ??
|
||||||
|
distance: float
|
||||||
|
|
||||||
songs: dict[str, UserScoredSong] # all songs + user score (the playlist)
|
songs: dict[str, UserScoredSong] # all songs + user score (the playlist)
|
||||||
history: list[Song] # all songs previously played
|
history: list[Song] # all songs previously played
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue