Merge pull request #89 from seanmorley15/development
chore: Add authorization check in upload server endpoint
This commit is contained in:
@@ -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}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user