1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-03 20:25:18 +02:00

chore: Add authorization check in upload server endpoint

This commit is contained in:
Sean Morley 2024-06-13 14:11:18 +00:00
parent 819e130133
commit 2dfa5674d5

View file

@ -14,6 +14,15 @@ import { generateId } from "lucia";
*/
export async function POST(event: RequestEvent): Promise<Response> {
try {
if (!event.locals.user) {
return new Response(JSON.stringify({ error: "Unauthorized" }), {
status: 401,
headers: {
"Content-Type": "application/json",
},
});
}
const contentType = event.request.headers.get("content-type") ?? "";
const fileExtension = contentType.split("/").pop();
const fileName = `${generateId(75)}.${fileExtension}`;