v1 review pass: fixed some minor bugs

This commit is contained in:
khannurien
2026-03-16 11:08:39 +00:00
parent e88fed4e98
commit 867e64cb5b
37 changed files with 1228 additions and 400 deletions

View File

@@ -39,7 +39,11 @@ router.post("/api/avatars/me", authMiddleware, async (ctx) => {
const authPayload = ctx.state.user;
const contentType = ctx.request.headers.get("content-type") ?? "";
if (!contentType.includes("multipart/form-data")) {
throw new APIException(APIErrorCode.BAD_REQUEST, 400, "Expected multipart/form-data");
throw new APIException(
APIErrorCode.BAD_REQUEST,
400,
"Expected multipart/form-data",
);
}
const body = await ctx.request.body.formData();
@@ -58,13 +62,21 @@ router.post("/api/avatars/me", authMiddleware, async (ctx) => {
}
if (file.size > MAX_AVATAR_SIZE) {
throw new APIException(APIErrorCode.BAD_REQUEST, 400, "File too large (max 5 MB)");
throw new APIException(
APIErrorCode.BAD_REQUEST,
400,
"File too large (max 5 MB)",
);
}
const data = new Uint8Array(await file.arrayBuffer());
if (!checkMagicBytes(data, file.type)) {
throw new APIException(APIErrorCode.BAD_REQUEST, 400, "File content does not match declared type");
throw new APIException(
APIErrorCode.BAD_REQUEST,
400,
"File content does not match declared type",
);
}
await Deno.mkdir(AVATARS_DIR, { recursive: true });