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_fetch import query_search, yt_get_audio_url, yt_search_song
|
||||
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()
|
||||
|
@ -75,7 +75,6 @@ def on_leave(data):
|
|||
def join():
|
||||
room_id = request.args.get("room")
|
||||
code = request.args.get("code")
|
||||
user_location = request.args.get("location")
|
||||
|
||||
if room_id is None:
|
||||
return error("Missing room id")
|
||||
|
@ -86,7 +85,7 @@ def join():
|
|||
if room.pin is not None and room.pin != 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 {"success": True, "ws": f"/ws/{room_id}"}
|
||||
|
@ -164,6 +163,14 @@ def room_new():
|
|||
|
||||
@app.get("/api/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 [
|
||||
{
|
||||
"id": room.id,
|
||||
|
@ -171,8 +178,10 @@ def room():
|
|||
"private": room.pin is not None,
|
||||
"coords": room.coord,
|
||||
"range": room.range_size,
|
||||
"distance": distance,
|
||||
}
|
||||
for room in state.rooms.values()
|
||||
if distance <= room.range_size
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue