FINALLY, Beautiful connection types!

This commit is contained in:
Eclypsed
2024-02-23 00:53:54 -05:00
parent c2236ab8ac
commit c7b9b214b7
16 changed files with 200 additions and 214 deletions

View File

@@ -1,12 +1,23 @@
import type { RequestHandler } from '@sveltejs/kit'
import { Jellyfin, YouTubeMusic } from '$lib/services'
import { Connections } from '$lib/server/users'
export const GET: RequestHandler = async ({ url }) => {
const ids = url.searchParams.get('ids')?.replace(/\s/g, '').split(',')
if (!ids) return new Response('Missing ids query parameter', { status: 400 })
const connections: Connection[] = []
for (const connectionId of ids) connections.push(Connections.getConnection(connectionId))
const connections: Connection<serviceType>[] = []
for (const connectionId of ids) {
const connection = Connections.getConnection(connectionId)
switch (connection.type) {
case 'jellyfin':
connection.service = await Jellyfin.fetchSerivceInfo(connection.service.userId, connection.service.urlOrigin, connection.tokens.accessToken)
break
case 'youtube-music':
connection.service = await YouTubeMusic.fetchServiceInfo(connection.service.userId, connection.tokens.accessToken)
break
}
}
return Response.json({ connections })
}