oops went on a massive code sesh and theres like a whole website now
This commit is contained in:
32
src/routes/artwork/[itemId]/+server.ts
Normal file
32
src/routes/artwork/[itemId]/+server.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
import { JELLYFIN_URL, JELLYFIN_API_KEY } from '$app/env/private';
|
||||
|
||||
export const GET: RequestHandler = async ({ params, fetch }) => {
|
||||
const { itemId } = params;
|
||||
|
||||
if (!/^[a-zA-Z0-9-]+$/.test(itemId)) {
|
||||
error(400, 'Invalid item ID');
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`${JELLYFIN_URL}/Items/${encodeURIComponent(itemId)}/Images/Primary`,
|
||||
{
|
||||
headers: {
|
||||
'X-Emby-Token': JELLYFIN_API_KEY
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
error(response.status, 'Artwork unavailable');
|
||||
}
|
||||
|
||||
return new Response(response.body, {
|
||||
headers: {
|
||||
'Content-Type': response.headers.get('Content-Type') ?? 'image/jpeg',
|
||||
'Cache-Control': 'private, max-age=3600'
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user