chore: adhoc setup to remove database

This commit is contained in:
2025-05-31 17:06:16 +02:00
parent 8ef1e62e76
commit 8aeba1e87c
5 changed files with 23 additions and 69 deletions

4
src/app.d.ts vendored
View File

@@ -7,8 +7,8 @@ declare global {
// interface PageData {}
// interface PageState {}
interface Platform {
caches: CacheStorage & { default: Cache };
}
caches: CacheStorage & { default: Cache }
}
}
}

View File

@@ -1,6 +1,7 @@
import type { Song } from '@/types';
import { getChillhopStation } from './chillhop';
import { getSleepStationSongs } from './sleep';
import { getChillhopData } from '@/utils';
const customStations: Record<number, () => Promise<Song[]>> = {
50000: getSleepStationSongs,
@@ -26,3 +27,8 @@ export const stations: Record<number, () => Promise<Song[]>> = 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
])

View File

@@ -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');
}

View File

@@ -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 });
}

View File

@@ -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',
},
});
};
};