mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-06-22 04:11:32 +10:00
finished object endpoints
Added writing (tested) and deleting (untested) endpoints
This commit is contained in:
@@ -41,7 +41,7 @@ export default defineEventHandler(async (h3) => {
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
username,
|
||||
displayName: "",
|
||||
displayName: "DecDuck",
|
||||
email: "",
|
||||
profilePicture: profilePictureObject,
|
||||
},
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const id = getRouterParam(h3, "id");
|
||||
if (!id) throw createError({ statusCode: 400, statusMessage: "Invalid ID" });
|
||||
|
||||
const userId = await h3.context.session.getUserId(h3);
|
||||
|
||||
const result = await h3.context.objects.deleteWithPermission(id, userId);
|
||||
return { success: result };
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
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 };
|
||||
});
|
||||
@@ -131,11 +131,12 @@ export abstract class ObjectBackend {
|
||||
userId?: string
|
||||
) {
|
||||
const metadata = await this.fetchMetadata(id);
|
||||
if (!metadata) return;
|
||||
if (!metadata) return false;
|
||||
|
||||
const myPermissions = metadata.permissions
|
||||
.filter((e) => {
|
||||
if (userId !== undefined && e.startsWith(userId)) return true;
|
||||
if (userId !== undefined && e.startsWith("internal")) return true;
|
||||
if (e.startsWith("anonymous")) return true;
|
||||
return false;
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user