This commit is contained in:
Mat12143 2025-08-02 10:28:38 +02:00
commit e045e11023
9 changed files with 62 additions and 68 deletions

View file

@ -1,18 +1,17 @@
import uuid
from dataclasses import asdict
import dotenv
from connect import get_connection
from flask import Flask, Response, jsonify, request
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, leave_room
from state import State
from connect import get_connection
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 gps import Coordinates, distance_between_coords
from qrcode_gen import generate_qr
from gps import is_within_range, distance_between_coords, Coordinates
from room import Room
from song import Song, add_song_in_db, get_song_by_title_artist, get_song_by_uuid, init_db
from song_fetch import query_search, yt_get_audio_url, yt_search_song
from state import State
dotenv.load_dotenv()
@ -33,7 +32,7 @@ state.rooms[1000] = Room(
name="Test Room",
pin=None,
tags=set(),
range_size=100,
range_size=150,
songs={},
history=[],
playing=[],

View file

@ -1,15 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover" class="h-max">
<div style="display: contents">%sveltekit.body%</div>
</body>
<body data-sveltekit-preload-data="hover" class="h-max">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>

View file

@ -3,8 +3,9 @@
let { room }: { room: Room } = $props()
</script>
<button
<a
class="flex w-82 cursor-pointer flex-row items-center rounded-md border border-dark-pine-muted bg-light-pine-overlay p-3 hover:bg-dark-pine-base/20 dark:bg-dark-pine-overlay hover:dark:bg-light-pine-base/20"
href="/room/{room.id}"
>
<div class="flex flex-row">
{room.name}
@ -12,7 +13,7 @@
</div>
<div class="grow"></div>
<div class="flex flex-row items-center gap-2">
<div class="font-mono">64m</div>
<div class="font-mono">{Math.round(room.distance)}m</div>
<div class="rounded bg-light-pine-blue px-2 py-0.5 text-dark-pine-text dark:bg-dark-pine-blue">Join</div>
</div>
</button>
</a>

View file

@ -1,8 +1,9 @@
<script lang="ts">
let { roomId } = $props()
import { LoaderCircle } from "@lucide/svelte"
let { roomId } = $props()
let input = $state("")
let disabled = $state(false)
let disabled: boolean = $state(false)
async function sendSong() {
disabled = true
@ -23,7 +24,14 @@
sendSong()
}
}}
{disabled}
/>
{#if disabled}
<span class="animate-spin">
<LoaderCircle />
</span>
{/if}
<button
class="i-lucide-check h-[40px] w-1/4 cursor-pointer rounded border-2 border-lime-700 bg-lime-600 font-semibold text-white shadow-xl duration-100 hover:scale-105 active:scale-90"
onclick={sendSong}>Add</button

View file

@ -37,11 +37,12 @@ export const parseSuggestion = async function (sugg: any): Promise<Suggestion> {
}
const RoomSchema = z.object({
id: z.string(),
id: z.number(),
name: z.string(),
private: z.boolean(),
coords: z.tuple([z.number(), z.number()]),
coords: z.object({ latitude: z.number(), longitude: z.number() }),
range: z.number().int(),
distance: z.number()
})
export type Room = z.infer<typeof RoomSchema>

View file

@ -1,16 +1,21 @@
import { get_coords } from "./gps"
import { parseSong, parseSuggestion, type FetchError, type Song, type Suggestion } from "./types"
export const joinRoom = async function (roomId: string, lat: number, lon: number): Promise<[FetchError | null, string]> {
let resp = await fetch(`/api/join?room=${roomId}&lat=${lat}&lon=${lon}`)
export const joinRoom = async function(roomId: string): Promise<[FetchError | null, string]> {
let { coords, error } = await get_coords()
if (error != null) return [{ code: 400, message: "Cannot join the room due to GPS error" }, ""]
if (coords == null) return [{ code: 400, message: "Cannot join the room due to GPS error" }, ""]
if (resp.status != 200) {
let res = await fetch(`/api/join?room=${roomId}&lat=${coords.latitude}&lon=${coords.longitude}`)
if (res.status != 200) {
return [{ code: 400, message: "Cannot join the room" }, ""]
}
return [null, "test"]
}
export const getSuggestions = async function (roomId: string): Promise<[FetchError | null, Suggestion[]]> {
export const getSuggestions = async function(roomId: string): Promise<[FetchError | null, Suggestion[]]> {
let resp = await fetch("/api/room/suggestions?room=" + roomId)
if (resp.status != 200) {
@ -31,7 +36,7 @@ export const getSuggestions = async function (roomId: string): Promise<[FetchErr
return [null, suggestions]
}
export const getQueueSongs = async function (roomId: string): Promise<[FetchError | null, Song[], number]> {
export const getQueueSongs = async function(roomId: string): Promise<[FetchError | null, Song[], number]> {
let resp = await fetch("/api/queue?room=" + roomId)
if (resp.status != 200) {
return [{ code: 400, message: "Failed to load queue songs" }, [], 0]
@ -49,7 +54,7 @@ export const getQueueSongs = async function (roomId: string): Promise<[FetchErro
return [null, songs, playingId]
}
export const triggerPlayNext = async function (roomId: string): Promise<[FetchError | null, Song[], number]> {
export const triggerPlayNext = async function(roomId: string): Promise<[FetchError | null, Song[], number]> {
let resp = await fetch("/api/queue/next?room=" + roomId, { method: "POST" })
if (resp.status != 200) {
@ -66,7 +71,7 @@ export const triggerPlayNext = async function (roomId: string): Promise<[FetchEr
return [null, songs, json["index"]]
}
export const getStreamingUrl = async function (uuid: string) {
export const getStreamingUrl = async function(uuid: string) {
let resp = await fetch("/api/song/audio?song=" + uuid)
let json = await resp.json()

View file

@ -1,9 +1,21 @@
<script lang="ts">
import RoomComponent from "$lib/components/RoomComponent.svelte"
import { get_coords } from "$lib/gps"
import { parseRoom, type Room } from "$lib/types"
import { Plus } from "@lucide/svelte"
import { onMount } from "svelte"
let room: Room = { id: "asd", coords: [0.123, 0.456], name: "scatolame party", private: true, range: 124 }
let rooms: Room[] = $state([])
onMount(async () => {
let { coords, error } = await get_coords()
if (error != null) return console.log(error)
if (coords == null) return
let res = await fetch(`/api/room?lat=${coords.latitude}&lon=${coords.longitude}`)
let json = await res.json()
for (let room of json) rooms.push(await parseRoom(room))
})
</script>
<div class="flex flex-col items-center gap-2">
@ -21,37 +33,8 @@
</button>
<div class="flex flex-col gap-2">
<RoomComponent {room}></RoomComponent>
<RoomComponent {room}></RoomComponent>
<RoomComponent {room}></RoomComponent>
<RoomComponent {room}></RoomComponent>
<RoomComponent {room}></RoomComponent>
<RoomComponent {room}></RoomComponent>
<RoomComponent {room}></RoomComponent>
<RoomComponent {room}></RoomComponent>
<RoomComponent {room}></RoomComponent>
<RoomComponent {room}></RoomComponent>
<RoomComponent {room}></RoomComponent>
<RoomComponent {room}></RoomComponent>
{#each rooms as room}
<RoomComponent {room} />
{/each}
</div>
</div>
<!-- <div class="h-full w-full flex-row justify-center p-4"> -->
<!-- <div class="relative min-h-screen justify-center justify-items-center"> -->
<!-- <h1>Scan your nearby rooms</h1> -->
<!-- <img src="/smerdoradar.gif" alt="radar" class="h-64 w-64" /> -->
<!-- <div class="max-h-50 w-full overflow-y-auto"> -->
<!-- <RoomComponent {room} /> -->
<!-- <RoomComponent {room} /> -->
<!-- <RoomComponent {room} /> -->
<!-- <RoomComponent {room} /> -->
<!-- <RoomComponent {room} /> -->
<!-- <RoomComponent {room} /> -->
<!-- <RoomComponent {room} /> -->
<!-- <RoomComponent {room} /> -->
<!-- <RoomComponent {room} /> -->
<!-- </div> -->
<!-- <div class="fixed right-0 bottom-0"> -->
<!-- <button class="mt-4 justify-end rounded bg-blue-500 px-6 py-2 text-white transition-colors hover:bg-blue-600 active:bg-blue-700"> + </button> -->
<!-- </div> -->
<!-- </div> -->
<!-- </div> -->

BIN
frontend/static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="107" height="128" viewBox="0 0 107 128"><title>svelte-logo</title><path d="M94.157 22.819c-10.4-14.885-30.94-19.297-45.792-9.835L22.282 29.608A29.92 29.92 0 0 0 8.764 49.65a31.5 31.5 0 0 0 3.108 20.231 30 30 0 0 0-4.477 11.183 31.9 31.9 0 0 0 5.448 24.116c10.402 14.887 30.942 19.297 45.791 9.835l26.083-16.624A29.92 29.92 0 0 0 98.235 78.35a31.53 31.53 0 0 0-3.105-20.232 30 30 0 0 0 4.474-11.182 31.88 31.88 0 0 0-5.447-24.116" style="fill:#ff3e00"/><path d="M45.817 106.582a20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.503 18 18 0 0 1 .624-2.435l.49-1.498 1.337.981a33.6 33.6 0 0 0 10.203 5.098l.97.294-.09.968a5.85 5.85 0 0 0 1.052 3.878 6.24 6.24 0 0 0 6.695 2.485 5.8 5.8 0 0 0 1.603-.704L69.27 76.28a5.43 5.43 0 0 0 2.45-3.631 5.8 5.8 0 0 0-.987-4.371 6.24 6.24 0 0 0-6.698-2.487 5.7 5.7 0 0 0-1.6.704l-9.953 6.345a19 19 0 0 1-5.296 2.326 20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.502 17.99 17.99 0 0 1 8.13-12.052l26.081-16.623a19 19 0 0 1 5.3-2.329 20.72 20.72 0 0 1 22.237 8.243 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-.624 2.435l-.49 1.498-1.337-.98a33.6 33.6 0 0 0-10.203-5.1l-.97-.294.09-.968a5.86 5.86 0 0 0-1.052-3.878 6.24 6.24 0 0 0-6.696-2.485 5.8 5.8 0 0 0-1.602.704L37.73 51.72a5.42 5.42 0 0 0-2.449 3.63 5.79 5.79 0 0 0 .986 4.372 6.24 6.24 0 0 0 6.698 2.486 5.8 5.8 0 0 0 1.602-.704l9.952-6.342a19 19 0 0 1 5.295-2.328 20.72 20.72 0 0 1 22.237 8.242 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-8.13 12.053l-26.081 16.622a19 19 0 0 1-5.3 2.328" style="fill:#fff"/></svg>

Before

Width:  |  Height:  |  Size: 1.5 KiB