A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
fix: Delete user's assets when the user is deleted
MohamedBassem91b088db868e
diff --git a/packages/shared/assetdb.ts b/packages/shared/assetdb.tsindex 8fd4da16..2973673f 100644--- a/packages/shared/assetdb.ts+++ b/packages/shared/assetdb.ts@@ -67,3 +67,15 @@ export async function deleteAsset({const assetDir = getAssetDir(userId, assetId);await fs.promises.rm(path.join(assetDir), { recursive: true });}++export async function deleteUserAssets({ userId }: { userId: string }) {+ const userDir = path.join(ROOT_PATH, userId);+ const dirExists = await fs.promises+ .access(userDir)+ .then(() => true)+ .catch(() => false);+ if (!dirExists) {+ return;+ }+ await fs.promises.rm(userDir, { recursive: true });+}diff --git a/packages/trpc/routers/users.ts b/packages/trpc/routers/users.tsindex 1e7a83a6..e7f0a59d 100644--- a/packages/trpc/routers/users.ts+++ b/packages/trpc/routers/users.ts@@ -5,6 +5,7 @@ import { z } from "zod";import { SqliteError } from "@hoarder/db";import { users } from "@hoarder/db/schema";+import { deleteUserAssets } from "@hoarder/shared/assetdb";import serverConfig from "@hoarder/shared/config";import { hashPassword, validatePassword } from "../auth";@@ -127,6 +128,7 @@ export const usersAppRouter = router({if (res.changes == 0) {throw new TRPCError({ code: "NOT_FOUND" });}+ await deleteUserAssets({ userId: input.userId });}),whoami: authedProcedure.output(