Lazuli, now with openapi!

This commit is contained in:
Eclypsed
2024-02-18 00:01:54 -05:00
parent 85a17dcd89
commit 1608e03b97
14 changed files with 177 additions and 291 deletions

View File

@@ -5,15 +5,15 @@ import { Jellyfin } from '$lib/service-managers/jellyfin'
// This is temporary functionally for the sake of developing the app.
// In the future will implement more robust algorithm for offering recommendations
export const GET: RequestHandler = async ({ params, fetch }) => {
const userId = params.userId as string
const userId = params.userId!
const connectionsResponse = await fetch(`/api/users/${userId}/connections`, { headers: { apikey: SECRET_INTERNAL_API_KEY } })
const userConnections: Connection[] = await connectionsResponse.json()
const userConnections = await connectionsResponse.json()
const recommendations: Song[] = []
const recommendations: MediaItem[] = []
for (const connection of userConnections) {
const { service, tokens } = connection
for (const connection of userConnections.connections) {
const { service, accessToken } = connection as Connection
switch (service.type) {
case 'jellyfin':
@@ -26,12 +26,12 @@ 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="${tokens.accessToken}"` })
const requestHeaders = new Headers({ Authorization: `MediaBrowser Token="${accessToken}"` })
const mostPlayedResponse = await fetch(mostPlayedSongsURL, { headers: requestHeaders })
const mostPlayedData = await mostPlayedResponse.json()
mostPlayedData.Items.forEach((song: Jellyfin.Song) => recommendations.push(Jellyfin.songFactory(song, connection as Jellyfin.JFConnection)))
for (const song of mostPlayedData.Items) recommendations.push(Jellyfin.songFactory(song, connection))
break
}
}