Add SQLite library with API, library desktop apps and MobyGames scraper
This commit is contained in:
1 parent
6674428346
commit
a16444451a
69 files changed
+2988
-1026
No files matched your search
@@ -1,25 +1,14 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { loadCovers, savedCoverPath } from '#lib/server/lastfm/covers';
|
||||
import { readCoverImage } from '#lib/server/lastfm/covers';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
const contentTypes: Record<string, string> = {
|
||||
'.jpg': 'image/jpeg',
|
||||
'.jpeg': 'image/jpeg',
|
||||
'.png': 'image/png',
|
||||
'.webp': 'image/webp',
|
||||
'.gif': 'image/gif'
|
||||
};
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
await loadCovers();
|
||||
const filePath = savedCoverPath(params.id);
|
||||
if (!filePath) error(404, 'Cover not found');
|
||||
const image = await readCoverImage(params.id);
|
||||
if (!image) error(404, 'Cover not found');
|
||||
|
||||
return new Response(await readFile(filePath), {
|
||||
return new Response(new Uint8Array(image.data), {
|
||||
headers: {
|
||||
'Content-Type': contentTypes[path.extname(filePath)] ?? 'image/jpeg',
|
||||
'Content-Type': image.contentType,
|
||||
'Cache-Control': 'public, max-age=31536000, immutable'
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user