Add Last.fm music stats to about page
This commit is contained in:
1 parent
3122bc4bf9
commit
2d84d68c46
27 files changed
+1618
-4
No files matched your search
@@ -0,0 +1,26 @@
|
||||
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 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');
|
||||
|
||||
return new Response(await readFile(filePath), {
|
||||
headers: {
|
||||
'Content-Type': contentTypes[path.extname(filePath)] ?? 'image/jpeg',
|
||||
'Cache-Control': 'public, max-age=31536000, immutable'
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user