18 lines
651 B
TypeScript
18 lines
651 B
TypeScript
import { getDatabase } from '$lib/server/database';
|
|
import { readUploadedAvatar } from '$lib/server/avatars';
|
|
import { error } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
|
|
export const GET: RequestHandler = async ({ params }) => {
|
|
if (!/^[0-9a-f-]{36}$/i.test(params.id)) error(404, 'Avatar not found');
|
|
const image = await readUploadedAvatar(await getDatabase(), params.id);
|
|
if (!image) error(404, 'Avatar not found');
|
|
return new Response(new Uint8Array(image), {
|
|
headers: {
|
|
'content-type': 'image/webp',
|
|
'cache-control': 'public, max-age=31536000, immutable',
|
|
'x-content-type-options': 'nosniff'
|
|
}
|
|
});
|
|
};
|