From a9125609bdda44efa8b77a036da6c1dd088cdc50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o?= <leopold.chappuis@savoirfairelinux.com> Date: Fri, 7 Feb 2025 11:34:37 -0500 Subject: [PATCH] accounts-overview: simplify delete account logic and add upload cache deletion The function is now streamlined with easier access to accountId, allowing for a more efficient implementation. Additionally, the logic includes the deletion of the upload cache. Change-Id: I262980e770f0d6757a307e18850457a1df117b1b --- server/src/routers/admin-router.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/server/src/routers/admin-router.ts b/server/src/routers/admin-router.ts index 67a09ba1..12463199 100644 --- a/server/src/routers/admin-router.ts +++ b/server/src/routers/admin-router.ts @@ -20,6 +20,7 @@ import envPaths from 'env-paths' import { Router } from 'express' import asyncHandler from 'express-async-handler' import { ParamsDictionary, Request, Response } from 'express-serve-static-core' +import fs from 'fs' import { readdir, stat } from 'fs/promises' import { AccessToken, @@ -51,6 +52,11 @@ export const adminRouter = Router() const paths = envPaths('jami', { suffix: '' }) const dataPath = paths.data +const multerPath = adminAccount.getUploadPath() +if (!fs.existsSync(multerPath)) { + fs.mkdirSync(multerPath) +} + adminRouter.get('/check', (_req, res) => { const isSetupComplete = adminAccount.getPasswordHash() !== undefined res.send({ isSetupComplete }) @@ -399,18 +405,13 @@ adminRouter.delete( asyncHandler(async (req, res) => { const users = req.body for (const user of users) { - if (user.auth === 'local') { - const accountId = jamid.getAccountIdFromUsername(user.username) - if (accountId) { - jamid.removeAccount(accountId) - } - } else if (user.auth === 'jams') { - const account = accounts.get(user.username, user.auth) - if (typeof account === 'object') { - jamid.removeAccount(account.accountId) - } - } + const accountId = user.accountId + jamid.removeAccount(accountId) accounts.remove(user.username, user.auth) + const userFilePath = multerPath + accountId + '/' + if (fs.existsSync(userFilePath)) { + fs.rmdirSync(userFilePath, { recursive: true }) + } } res.sendStatus(HttpStatusCode.Ok) }), -- GitLab