Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

refactor: keep File Manager download operations in the action hook

Juan Denisdd93f01fd6d9
diff --git a/frontend/scripts/check-file-manager-boundaries.mjs b/frontend/scripts/check-file-manager-boundaries.mjs
index 6baa16bb..62044db3 100644
--- a/frontend/scripts/check-file-manager-boundaries.mjs
+++ b/frontend/scripts/check-file-manager-boundaries.mjs
@@ -29,10 +29,14 @@ export function inspectFileManagerSource(path, source) {
}
function visit(node) {
if (!node || typeof node !== 'object') return;
- if (page && node.type === 'AwaitExpression') errors.push(`${path}: asynchronous work belongs in hooks`);
+ if ((page || view) && node.type === 'AwaitExpression') errors.push(`${path}: asynchronous work belongs in hooks`);
if ((page || view) && node.type === 'CallExpression' && node.callee?.object?.name === 'api') {
errors.push(`${path}: views must not call API methods`);
}
+ if ((page || view) && node.type === 'CallExpression' && node.callee?.object?.name === 'fileApi'
+ && node.callee?.property?.name !== 'supports') {
+ errors.push(`${path}: file operations belong in feature hooks`);
+ }
if ((page || view) && node.type === 'CallExpression' && node.callee?.name === 'fetch') {
errors.push(`${path}: views must not fetch`);
}
diff --git a/frontend/src/components/file-manager/__tests__/boundaries.test.js b/frontend/src/components/file-manager/__tests__/boundaries.test.js
index 94950f06..585fc02b 100644
--- a/frontend/src/components/file-manager/__tests__/boundaries.test.js
+++ b/frontend/src/components/file-manager/__tests__/boundaries.test.js
@@ -13,6 +13,8 @@ test('boundary guard rejects dependencies that would recombine the feature', ()
for (const [path, source] of [
['pages/FileManager.jsx', 'async function load() { await api.browseFiles(); }'],
['pages/FileManager.jsx', "fetch('/api/v1/files').then(render);"],
+ ['pages/FileManager.jsx', "fileApi.browse('/home');"],
+ ['components/file-manager/FileManagerListing.jsx', 'async function load() { await request(); }'],
['components/file-manager/FileManagerListing.jsx', "import { api } from '@/services/api';"],
['components/file-manager/hooks/useFileEditor.js', "import Page from '@/pages/FileManager';"],
['components/file-manager/FileManagerSidebar.jsx', "import useFileTree from './hooks/useFileTree';"],
diff --git a/frontend/src/components/file-manager/hooks/useFileActions.js b/frontend/src/components/file-manager/hooks/useFileActions.js
index f998a23b..82258f36 100644
--- a/frontend/src/components/file-manager/hooks/useFileActions.js
+++ b/frontend/src/components/file-manager/hooks/useFileActions.js
@@ -134,6 +134,12 @@ export default function useFileActions({
const openRenameModal = (entry) => setDialog({ kind: 'rename', entry });
const openPermissionsModal = (entry) => setDialog({ kind: 'permissions', entry });
+ const handleDownload = (entry) => {
+ if (!remoteGuard('download')) fileApi.download(entry);
+ };
+ const downloadSelected = (entries) => {
+ if (!remoteGuard('download')) entries.filter(entry => !entry.is_dir).forEach(fileApi.download);
+ };
return {
dialog,
@@ -143,6 +149,8 @@ export default function useFileActions({
handleDelete,
handleRename,
handleChangePermissions,
+ handleDownload,
+ downloadSelected,
openRenameModal,
openPermissionsModal,
};
diff --git a/frontend/src/pages/FileManager.jsx b/frontend/src/pages/FileManager.jsx
index 40cf619b..4e56eb96 100644
--- a/frontend/src/pages/FileManager.jsx
+++ b/frontend/src/pages/FileManager.jsx
@@ -168,6 +168,8 @@ function FileManager() {
handleDelete,
handleRename,
handleChangePermissions,
+ handleDownload,
+ downloadSelected,
openRenameModal,
openPermissionsModal,
} = useFileActions({
@@ -275,9 +277,6 @@ function FileManager() {
const rowOpen = useStableHandler(handleOpen);
const rowToggleSelect = useStableHandler(handleToggleSelect);
const rowContext = useStableHandler(openContextMenu);
- const handleDownload = (entry) => {
- if (!remoteGuard('download')) fileApi.download(entry);
- };
const rowDownload = useStableHandler(handleDownload);
const rowRename = useStableHandler(openRenameModal);
const rowPermissions = useStableHandler(openPermissionsModal);
@@ -285,11 +284,6 @@ function FileManager() {
const copyPathToClipboard = (path) => copyText(path);
- const downloadSelected = () => {
- if (!remoteGuard('download'))
- selectedEntries.filter((e) => !e.is_dir).forEach((e) => fileApi.download(e));
- };
-
useTopbarActions(
() => (
<>
@@ -409,7 +403,7 @@ function FileManager() {
variant="unstyled"
type="button"
className="bulk-btn"
- onClick={downloadSelected}
+ onClick={() => downloadSelected(selectedEntries)}
>
<Download size={14} /> {t('common.actions.download', 'Download')}
</Button>