support adding to spotify playlist

This commit is contained in:
2025-07-03 18:38:40 +02:00
parent a8b6a309f0
commit a0757ea3ff
11 changed files with 478 additions and 213 deletions

View File

@ -0,0 +1,28 @@
import { log } from '$lib/log';
import { SpotifyPlaylistAdder } from '$lib/server/spotifyPlaylistAdder';
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ url }) => {
const adder = new SpotifyPlaylistAdder();
let redirectUri = url;
if (url.hostname === 'localhost') {
redirectUri.hostname = '127.0.0.1';
}
log.debug(url.searchParams, url.hostname);
if (url.searchParams.has('code')) {
await adder.receivedAuthCode(url.searchParams.get('code') || '', url);
redirect(307, '/');
} else if (url.searchParams.has('error')) {
log.error('received error', url.searchParams.get('error'));
return;
}
if (await adder.authCodeExists()) {
redirect(307, '/');
}
const authUrl = adder.constructAuthUrl(url);
log.debug('+page.server.ts', authUrl.toString());
redirect(307, authUrl);
};

View File

@ -0,0 +1 @@
<h1>Something went wrong</h1>

View File

@ -1,2 +1 @@
<h1>Hello and welcome to my site!</h1>
<a href="/about">About my site</a>
<h1>Something went wrong</h1>