Going to try out some OOP/DI patterns and see where that takes me
This commit is contained in:
@@ -1,22 +1,15 @@
|
||||
import { Connections } from '$lib/server/users'
|
||||
import { Jellyfin } from '$lib/services'
|
||||
import { YouTubeMusic } from '$lib/service-managers/youtube-music'
|
||||
import type { RequestHandler } from '@sveltejs/kit'
|
||||
import { Connections } from '$lib/server/connections'
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
const userId = params.userId!
|
||||
|
||||
const connections = Connections.getUserConnections(userId)
|
||||
for (const connection of connections) {
|
||||
switch (connection.type) {
|
||||
case 'jellyfin':
|
||||
connection.service = await Jellyfin.fetchSerivceInfo(connection.service.userId, connection.service.urlOrigin, connection.tokens.accessToken)
|
||||
break
|
||||
case 'youtube-music':
|
||||
const youTubeMusic = new YouTubeMusic(connection)
|
||||
connection.service = await youTubeMusic.fetchServiceInfo()
|
||||
break
|
||||
}
|
||||
const connections: ConnectionInfo[] = []
|
||||
for (const connection of Connections.getUserConnections(userId)) {
|
||||
await connection
|
||||
.getConnectionInfo()
|
||||
.then((info) => connections.push(info))
|
||||
.catch((reason) => console.log(`Failed to fetch connection info: ${reason}`))
|
||||
}
|
||||
|
||||
return Response.json({ connections })
|
||||
|
||||
Reference in New Issue
Block a user