FINALLY, Beautiful connection types!
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
import { Connections } from '$lib/server/users'
|
||||
import { Jellyfin, YouTubeMusic } from '$lib/services'
|
||||
import type { RequestHandler } from '@sveltejs/kit'
|
||||
|
||||
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':
|
||||
connection.service = await YouTubeMusic.fetchServiceInfo(connection.service.userId, connection.tokens.accessToken)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return Response.json({ connections })
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { RequestHandler } from '@sveltejs/kit'
|
||||
import { SECRET_INTERNAL_API_KEY } from '$env/static/private'
|
||||
import { Jellyfin } from '$lib/service-managers/jellyfin'
|
||||
import { Jellyfin } from '$lib/services'
|
||||
|
||||
// This is temporary functionally for the sake of developing the app.
|
||||
// In the future will implement more robust algorithm for offering recommendations
|
||||
@@ -13,9 +13,9 @@ export const GET: RequestHandler = async ({ params, fetch }) => {
|
||||
const recommendations: MediaItem[] = []
|
||||
|
||||
for (const connection of userConnections.connections) {
|
||||
const { service, accessToken } = connection as Connection
|
||||
const { type, service, tokens } = connection as Connection<serviceType>
|
||||
|
||||
switch (service.type) {
|
||||
switch (type) {
|
||||
case 'jellyfin':
|
||||
const mostPlayedSongsSearchParams = new URLSearchParams({
|
||||
SortBy: 'PlayCount',
|
||||
@@ -26,7 +26,7 @@ export const GET: RequestHandler = async ({ params, fetch }) => {
|
||||
})
|
||||
|
||||
const mostPlayedSongsURL = new URL(`/Users/${service.userId}/Items?${mostPlayedSongsSearchParams.toString()}`, service.urlOrigin).href
|
||||
const requestHeaders = new Headers({ Authorization: `MediaBrowser Token="${accessToken}"` })
|
||||
const requestHeaders = new Headers({ Authorization: `MediaBrowser Token="${tokens.accessToken}"` })
|
||||
|
||||
const mostPlayedResponse = await fetch(mostPlayedSongsURL, { headers: requestHeaders })
|
||||
const mostPlayedData = await mostPlayedResponse.json()
|
||||
|
||||
Reference in New Issue
Block a user