Initial commit
This commit is contained in:
25
server/api/drops/[id].get.ts
Normal file
25
server/api/drops/[id].get.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import {
|
||||
createError,
|
||||
defineEventHandler,
|
||||
getRequestHeader,
|
||||
getRouterParam,
|
||||
} from "h3";
|
||||
import { dropStore, DropStoreError } from "../../utils/drop-store";
|
||||
import { publicHeaders } from "../../utils/http";
|
||||
export default defineEventHandler(async (event) => {
|
||||
publicHeaders(event);
|
||||
const id = String(getRouterParam(event, "id") || "").toUpperCase();
|
||||
const access = getRequestHeader(event, "x-quickdrop-access") || "";
|
||||
try {
|
||||
return await dropStore.descriptor(id, access);
|
||||
} catch (error) {
|
||||
if (error instanceof DropStoreError && error.code === "expired")
|
||||
throw createError({ statusCode: 410, statusMessage: "Drop expired." });
|
||||
if (error instanceof DropStoreError && error.code === "forbidden")
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: "Invalid access capability.",
|
||||
});
|
||||
throw createError({ statusCode: 404, statusMessage: "Drop not found." });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user