2024-05-28 00:46:34 -04:00
|
|
|
import type { RequestHandler } from '@sveltejs/kit'
|
2024-07-04 02:54:24 -04:00
|
|
|
import { ConnectionFactory } from '$lib/server/api-helper'
|
2024-05-28 00:46:34 -04:00
|
|
|
|
|
|
|
|
export const GET: RequestHandler = async ({ params, url }) => {
|
|
|
|
|
const connectionId = params.connectionId!
|
2024-07-04 02:54:24 -04:00
|
|
|
const connection = await ConnectionFactory.getConnection(connectionId).catch(() => null)
|
2024-05-28 00:46:34 -04:00
|
|
|
if (!connection) return new Response('Invalid connection id', { status: 400 })
|
|
|
|
|
|
|
|
|
|
const albumId = url.searchParams.get('id')
|
|
|
|
|
if (!albumId) return new Response(`Missing id search parameter`, { status: 400 })
|
|
|
|
|
|
|
|
|
|
const album = await connection.getAlbum(albumId).catch(() => undefined)
|
|
|
|
|
if (!album) return new Response(`Failed to fetch album with id: ${albumId}`, { status: 400 })
|
|
|
|
|
|
|
|
|
|
return Response.json({ album })
|
|
|
|
|
}
|