From 99f3c26ed52fb89d78cd64250792dcf98acda78e Mon Sep 17 00:00:00 2001 From: Izan Gil <66965250+SrIzan10@users.noreply.github.com> Date: Sat, 31 May 2025 18:09:58 +0200 Subject: [PATCH] chore: copilot review nitpicks --- src/lib/fisheryates.ts | 2 +- src/lib/stations/index.ts | 18 +++++++++--------- src/lib/stations/sleep.ts | 2 +- src/lib/types.ts | 2 +- src/routes/api/live/[stationId]/+server.ts | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lib/fisheryates.ts b/src/lib/fisheryates.ts index f2804b6..c296361 100644 --- a/src/lib/fisheryates.ts +++ b/src/lib/fisheryates.ts @@ -3,7 +3,7 @@ import type { SIMDMersenneTwister } from "./mersenne"; -export const fisherYates = (sfml: SIMDMersenneTwister, ...arr: any[]) => { +export const fisherYates = (arr: any[], sfml: SIMDMersenneTwister) => { let m = arr.length; while (m) { const i = Math.floor(sfml.random() * m--); diff --git a/src/lib/stations/index.ts b/src/lib/stations/index.ts index 3a0c8d5..81a3da9 100644 --- a/src/lib/stations/index.ts +++ b/src/lib/stations/index.ts @@ -1,4 +1,4 @@ -import type { Song } from '@/types'; +import type { Song, Station } from '@/types'; import { getChillhopStation } from './chillhop'; import { getSleepStationSongs } from './sleep'; import { getChillhopData } from '@/utils'; @@ -10,25 +10,25 @@ const customStations: Record Promise> = { export const stations: Record Promise> = new Proxy(customStations, { get(target, prop) { const stationId = Number(prop); - + if (target[stationId]) { return target[stationId]; } - + if (stationId >= 10000 && stationId < 20000) { return () => getChillhopStation(stationId); } - + return undefined; }, - + has(target, prop) { const stationId = Number(prop); return target[stationId] !== undefined || (stationId >= 10000 && stationId < 20000); - } + }, }); export const stationMetadata = Promise.resolve([ - { id: 50000, name: 'Lofi Sleep', description: 'Custom station with relaxing lofi beats' }, - ...(await getChillhopData()).stations -]) \ No newline at end of file + { id: 50000, name: 'Lofi Sleep' }, + ...(await getChillhopData()).stations, +]) as Promise; diff --git a/src/lib/stations/sleep.ts b/src/lib/stations/sleep.ts index a570446..01ef14b 100644 --- a/src/lib/stations/sleep.ts +++ b/src/lib/stations/sleep.ts @@ -21,6 +21,6 @@ export async function getSleepStationSongs(): Promise { }; }) as Song[]; - const shuffled = fisherYates(m, mapped).slice(0, 5); + const shuffled = fisherYates(mapped, m).slice(0, 5); return shuffled; } diff --git a/src/lib/types.ts b/src/lib/types.ts index 1e97caa..f96442b 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -57,7 +57,7 @@ export interface DecodedStationMeta { export interface Station { name: string; id: number; - meta: string; // Base64 encoded JSON string (DecodedStationMeta) + meta?: string; // Base64 encoded JSON string (DecodedStationMeta) } export interface Background { diff --git a/src/routes/api/live/[stationId]/+server.ts b/src/routes/api/live/[stationId]/+server.ts index 27bb558..6fb0b96 100644 --- a/src/routes/api/live/[stationId]/+server.ts +++ b/src/routes/api/live/[stationId]/+server.ts @@ -1,4 +1,4 @@ -import { stations } from '@/stations/index.js'; +import { stations } from '@/stations'; export async function GET(event) { const { stationId } = event.params;