mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-04 04:35:19 +02:00
chore: Add authorization check in upload server endpoint
This commit is contained in:
parent
819e130133
commit
2dfa5674d5
1 changed files with 9 additions and 0 deletions
|
@ -14,6 +14,15 @@ import { generateId } from "lucia";
|
||||||
*/
|
*/
|
||||||
export async function POST(event: RequestEvent): Promise<Response> {
|
export async function POST(event: RequestEvent): Promise<Response> {
|
||||||
try {
|
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 contentType = event.request.headers.get("content-type") ?? "";
|
||||||
const fileExtension = contentType.split("/").pop();
|
const fileExtension = contentType.split("/").pop();
|
||||||
const fileName = `${generateId(75)}.${fileExtension}`;
|
const fileName = `${generateId(75)}.${fileExtension}`;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue