From 8aeba1e87c7c0716b5756763be39fd10f0d30856 Mon Sep 17 00:00:00 2001 From: Izan Gil <66965250+SrIzan10@users.noreply.github.com> Date: Sat, 31 May 2025 17:06:16 +0200 Subject: [PATCH] chore: adhoc setup to remove database --- src/app.d.ts | 4 +- src/lib/stations/index.ts | 6 +++ .../api/dev/populateStations/+server.ts | 48 ------------------- src/routes/api/live/[stationId]/+server.ts | 2 +- src/routes/api/stations/+server.ts | 32 ++++++------- 5 files changed, 23 insertions(+), 69 deletions(-) delete mode 100644 src/routes/api/dev/populateStations/+server.ts diff --git a/src/app.d.ts b/src/app.d.ts index b992e0d..dab9943 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -7,8 +7,8 @@ declare global { // interface PageData {} // interface PageState {} interface Platform { - caches: CacheStorage & { default: Cache }; - } + caches: CacheStorage & { default: Cache } + } } } diff --git a/src/lib/stations/index.ts b/src/lib/stations/index.ts index 1503179..3a0c8d5 100644 --- a/src/lib/stations/index.ts +++ b/src/lib/stations/index.ts @@ -1,6 +1,7 @@ import type { Song } from '@/types'; import { getChillhopStation } from './chillhop'; import { getSleepStationSongs } from './sleep'; +import { getChillhopData } from '@/utils'; const customStations: Record Promise> = { 50000: getSleepStationSongs, @@ -26,3 +27,8 @@ export const stations: Record Promise> = new Proxy(customS 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 diff --git a/src/routes/api/dev/populateStations/+server.ts b/src/routes/api/dev/populateStations/+server.ts deleted file mode 100644 index 1bbca1f..0000000 --- a/src/routes/api/dev/populateStations/+server.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { getChillhopData } from '@/utils'; -import type { RequestHandler } from './$types'; -import { BASEROW_ENDPOINT, BASEROW_TOKEN } from '$env/static/private' -import { dev } from '$app/environment'; -import type { BRStation } from '@/types'; - -export const GET: RequestHandler = async () => { - if (!dev) { - return new Response('Not allowed', { - status: 403 - }); - } - const generalData = await getChillhopData(); - const existingRows = await fetch(`${BASEROW_ENDPOINT}/api/database/rows/table/685/?user_field_names=true`, { - headers: { - Authorization: `Token ${BASEROW_TOKEN}` - } - }).then(async (res) => await res.json()).then(d => d.results as BRStation[]); - const chillhopStations = existingRows.filter(r => r.Source === 'chillhop'); - await fetch(`${BASEROW_ENDPOINT}/api/database/rows/table/685/batch-delete/ `, { - method: 'POST', - headers: { - Authorization: `Token ${BASEROW_TOKEN}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - items: chillhopStations.map(r => r.id) - }) - }) - - const stations = generalData.stations.map((station) => ({ - ID: station.id, - Name: station.name, - Source: 'chillhop' - })); - await fetch(`${BASEROW_ENDPOINT}/api/database/rows/table/685/batch/?user_field_names=true`, { - method: 'POST', - headers: { - Authorization: `Token ${BASEROW_TOKEN}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - items: stations - }) - }); - - return new Response('done'); -} diff --git a/src/routes/api/live/[stationId]/+server.ts b/src/routes/api/live/[stationId]/+server.ts index c3d101e..27bb558 100644 --- a/src/routes/api/live/[stationId]/+server.ts +++ b/src/routes/api/live/[stationId]/+server.ts @@ -7,7 +7,7 @@ export async function GET(event) { return new Response('Invalid station ID', { status: 400 }); } - const stationFunction = stations[stationIdInt]; + const stationFunction = stations[stationIdInt]; if (!stationFunction) { return new Response('Station not found', { status: 404 }); } diff --git a/src/routes/api/stations/+server.ts b/src/routes/api/stations/+server.ts index 23f3c7d..a89f26a 100644 --- a/src/routes/api/stations/+server.ts +++ b/src/routes/api/stations/+server.ts @@ -1,27 +1,23 @@ -import { BASEROW_ENDPOINT, BASEROW_TOKEN } from "$env/static/private" -import type { BRStation } from "@/types"; -import { getChillhopData } from "@/utils"; -import type { RequestHandler } from "@sveltejs/kit"; +import { stationMetadata } from '@/stations'; +import { getChillhopData } from '@/utils'; +import type { RequestHandler } from '@sveltejs/kit'; export const GET: RequestHandler = async () => { const responses = await Promise.all([ - fetch(`${BASEROW_ENDPOINT}/api/database/rows/table/685/?user_field_names=true`, { - headers: { - Authorization: `Token ${BASEROW_TOKEN}` - } - }).then(async (res) => await res.json()).then(d => d.results as BRStation[]).then(stations => stations.map(stations => { - return { - id: stations.ID, - name: stations.Name, - } - })), + stationMetadata, getChillhopData(), ]); - return new Response(JSON.stringify({ stations: responses[0], backgrounds: responses[1].backgrounds, atmospheres: responses[1].atmospheres }), { + const responseJson = JSON.stringify({ + stations: responses[0], + backgrounds: responses[1].backgrounds, + atmospheres: responses[1].atmospheres, + }); + + return new Response(responseJson, { status: 200, headers: { - "Content-Type": "application/json" - } + 'Content-Type': 'application/json', + }, }); -}; \ No newline at end of file +};