mirror of
https://github.com/SrIzan10/lofi.git
synced 2026-06-06 00:56:53 +00:00
chore: adhoc setup to remove database
This commit is contained in:
4
src/app.d.ts
vendored
4
src/app.d.ts
vendored
@@ -7,8 +7,8 @@ declare global {
|
||||
// interface PageData {}
|
||||
// interface PageState {}
|
||||
interface Platform {
|
||||
caches: CacheStorage & { default: Cache };
|
||||
}
|
||||
caches: CacheStorage & { default: Cache }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
])
|
||||
@@ -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');
|
||||
}
|
||||
@@ -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 });
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user