Initial commit
This commit is contained in:
30
server/api/drops/[id]/chunks/[index].put.ts
Normal file
30
server/api/drops/[id]/chunks/[index].put.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import {
|
||||
createError,
|
||||
defineEventHandler,
|
||||
getRouterParam,
|
||||
setResponseStatus,
|
||||
} from "h3";
|
||||
import { requireAuth } from "../../../../utils/auth";
|
||||
import { dropStore, DropStoreError } from "../../../../utils/drop-store";
|
||||
import { readBounded, requireContentType } from "../../../../utils/http";
|
||||
export default defineEventHandler(async (event) => {
|
||||
requireAuth(event);
|
||||
requireContentType(event, "application/octet-stream");
|
||||
const id = String(getRouterParam(event, "id") || "").toUpperCase();
|
||||
const index = Number(getRouterParam(event, "index"));
|
||||
try {
|
||||
const result = await dropStore.putChunk(
|
||||
id,
|
||||
index,
|
||||
await readBounded(event, 8388624),
|
||||
);
|
||||
setResponseStatus(event, result === "created" ? 201 : 204);
|
||||
} catch (error) {
|
||||
if (error instanceof DropStoreError) {
|
||||
const status =
|
||||
error.code === "not-found" ? 404 : error.code === "expired" ? 410 : 409;
|
||||
throw createError({ statusCode: status, statusMessage: error.message });
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user