remove HomeDirSelector, use HOME_DIR for super admin file browser root

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 19:05:29 +00:00
co-authored by Claude Opus 4.6
parent ebebac0114
commit d62280176a
5 changed files with 9 additions and 55 deletions
+5 -6
View File
@@ -2,7 +2,6 @@ import { createRouter } from '@@/create-router';
import { resolve, dirname, join, parse as parsePath } from 'node:path';
import { readdir, stat, mkdir, rm, rename, readFile, cp, unlink } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { homedir } from 'node:os';
import { getHomeDir, DATA_PATH, getUserSettingsFile } from '@@/data-path';
import * as errors from '@@/custom-errors';
import { readTtsConfig } from '@@/api/server-settings/tts';
@@ -64,11 +63,11 @@ function getUserDataDir(email: string): string {
}
function getRootDir(user: UserCtx, root?: string): string {
if (!root || root === 'home') return getHomeDir(user.email);
if (!root || root === 'home') {
if (user.role === 'Super Admin' && process.env.HOME_DIR) return process.env.HOME_DIR;
return getHomeDir(user.email);
}
if (root === 'user-data') return getUserDataDir(user.email);
if (user.role !== 'Super Admin') throw errors.FORBIDDEN('Only Super Admin can access this root');
if (root === '~') return homedir();
if (root === 'officer.dev') return resolve(process.cwd(), '..');
throw errors.BAD_REQUEST(`Invalid root: ${root}`);
}
@@ -374,7 +373,7 @@ router.post('/save-result', async (ctx) => {
const srcAbs = resolve(userDataDir, cachedPath);
if (!existsSync(srcAbs)) throw errors.BAD_REQUEST('Cached file not found');
const homeDir = getHomeDir(user.email);
const homeDir = getRootDir(user, 'home');
const destAbs = resolve(homeDir, relativePath);
if (!destAbs.startsWith(homeDir)) throw errors.FORBIDDEN('Path outside home directory');