Files
drop/server/api/v1/object/[id]/index.post.ts
DecDuck 486bce8bc7 finished object endpoints
Added writing (tested) and deleting (untested) endpoints
2024-10-09 15:08:55 +11:00

22 lines
566 B
TypeScript

export default defineEventHandler(async (h3) => {
const id = getRouterParam(h3, "id");
if (!id) throw createError({ statusCode: 400, statusMessage: "Invalid ID" });
const body = await readRawBody(h3, "binary");
if (!body)
throw createError({
statusCode: 400,
statusMessage: "Invalid upload",
});
const userId = await h3.context.session.getUserId(h3);
const buffer = Buffer.from(body);
const result = await h3.context.objects.writeWithPermissions(
id,
async () => buffer,
userId
);
return { success: result };
});