Initial commit
This commit is contained in:
26
server/api/drops/index.post.ts
Normal file
26
server/api/drops/index.post.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { createError, defineEventHandler, setResponseStatus } from "h3";
|
||||
import { requireAuth } from "../../utils/auth";
|
||||
import { dropStore } from "../../utils/drop-store";
|
||||
import { readJson } from "../../utils/http";
|
||||
import { validateReservation } from "../../../shared/utils/drop-contract";
|
||||
export default defineEventHandler(async (event) => {
|
||||
requireAuth(event);
|
||||
const body = readJson(event, 4096);
|
||||
let request;
|
||||
try {
|
||||
request = validateReservation(await body);
|
||||
} catch (error) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage:
|
||||
error instanceof Error ? error.message : "Invalid reservation.",
|
||||
});
|
||||
}
|
||||
const result = await dropStore.reserve(request);
|
||||
setResponseStatus(event, 201);
|
||||
return {
|
||||
id: result.id,
|
||||
uploadExpiresAt: new Date(result.uploadExpiresAt).toISOString(),
|
||||
access: result.access,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user