-
{{ user.displayName }}
@@ -30,9 +35,14 @@
class="transition inline-flex items-center w-full py-3 px-4 hover:bg-zinc-800"
>
-
{{ user.displayName }}
diff --git a/server/pages/account/index.vue b/server/pages/account/index.vue
index 38070ff7..205231eb 100644
--- a/server/pages/account/index.vue
+++ b/server/pages/account/index.vue
@@ -1,89 +1,77 @@
-
-
-
-
diff --git a/server/pages/user/[id]/index.vue b/server/pages/user/[id]/index.vue
index 74855a10..14b6be24 100644
--- a/server/pages/user/[id]/index.vue
+++ b/server/pages/user/[id]/index.vue
@@ -1,10 +1,14 @@
-
diff --git a/server/server/api/v1/user/avatar.post.ts b/server/server/api/v1/user/avatar.post.ts
new file mode 100644
index 00000000..faa21a63
--- /dev/null
+++ b/server/server/api/v1/user/avatar.post.ts
@@ -0,0 +1,54 @@
+import aclManager from "~/server/internal/acls";
+import prisma from "~/server/internal/db/database";
+import objectHandler from "~/server/internal/objects";
+import { handleFileUpload } from "~/server/internal/utils/handlefileupload";
+
+export default defineEventHandler(async (h3) => {
+ const userId = await aclManager.getUserIdACL(h3, ["object:update"]);
+ if (!userId) throw createError({ statusCode: 403 });
+
+ const result = await handleFileUpload(h3, {}, ["anonymous:read"], 1);
+ if (!result) {
+ throw createError({
+ statusCode: 400,
+ statusMessage: "File upload required (multipart form)",
+ });
+ }
+
+ const [ids, , pull, dump] = result;
+ const id = ids.at(0);
+ if (!id) {
+ dump();
+ throw createError({
+ statusCode: 400,
+ statusMessage: "Upload at least one file.",
+ });
+ }
+
+ const current = await prisma.user.findUnique({
+ where: { id: userId },
+ select: { profilePictureObjectId: true },
+ });
+ if (!current) {
+ dump();
+ throw createError({ statusCode: 404, statusMessage: "User not found." });
+ }
+
+ const { count } = await prisma.user.updateMany({
+ where: { id: userId },
+ data: { profilePictureObjectId: id },
+ });
+ if (count === 0) {
+ dump();
+ throw createError({ statusCode: 404, statusMessage: "User not found." });
+ }
+
+ await pull();
+
+ const previous = current.profilePictureObjectId?.trim();
+ if (previous && previous !== id) {
+ await objectHandler.deleteAsSystem(previous).catch(() => {});
+ }
+
+ return { id };
+});