From c4a5166e3bd97e9786210a5356738cfc30bb85ae Mon Sep 17 00:00:00 2001 From: Tilman Date: Wed, 8 Oct 2025 15:32:45 +0200 Subject: [PATCH] Support downloading directories as a zip archive (#106) * Add directory download as zip feature Implements the ability for users to download directories as zip files if enabled in config. Adds a new API route for directory zipping, updates UI components to show a download button for directories, and introduces related config and type changes. Also includes a new download icon. * Windows path bugfix * Include empty directories in zip archive * Address feedback - `isDirectoryDownloadsAllowed` -> `areDirectoryDownloadsAllowed` - send `parentPath` & `name` to API instead of resolving `fullPath` on client - call `ensureUserPathIsValidAndSecurelyAccessible` before zipping - set config `allowDirectoryDownloads` default to `false` - add `zip` to Dockerfile and replace in-house zip algorithm - replace `download.svg` with heroicon's `arrow-down-tray` - `replace` with glob -> `replaceAll` with string * Cleanup apt-get command * Remove unused zip archive and directory functions --- Dockerfile | 2 +- bewcloud.config.sample.ts | 1 + components/files/ListFiles.tsx | 25 +++++++-- components/files/MainFiles.tsx | 18 ++++++ fresh.gen.ts | 2 + islands/files/FilesWrapper.tsx | 3 + lib/config.ts | 7 +++ lib/models/files.ts | 6 +- lib/types.ts | 2 + routes/api/files/download-directory.tsx | 74 +++++++++++++++++++++++++ routes/file-share/[fileShareId].tsx | 1 + routes/files.tsx | 4 ++ static/images/download.svg | 14 +++++ 13 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 routes/api/files/download-directory.tsx create mode 100644 static/images/download.svg diff --git a/Dockerfile b/Dockerfile index 40f2e8b..2a0f7ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM denoland/deno:ubuntu-2.5.2 EXPOSE 8000 -RUN apt-get update && apt-get install -y make +RUN apt-get update && apt-get install -y make zip WORKDIR /app diff --git a/bewcloud.config.sample.ts b/bewcloud.config.sample.ts index 84ffba8..a22412e 100644 --- a/bewcloud.config.sample.ts +++ b/bewcloud.config.sample.ts @@ -18,6 +18,7 @@ const config: PartialDeep = { // files: { // rootPath: 'data-files', // allowPublicSharing: false, // If true, public file sharing will be allowed (still requires a user to enable sharing for a given file or directory) + // allowDirectoryDownloads: false, // If true, directories can be downloaded as zip files // }, // core: { // enabledApps: ['news', 'notes', 'photos', 'expenses', 'contacts', 'calendar'], // dashboard and files cannot be disabled diff --git a/components/files/ListFiles.tsx b/components/files/ListFiles.tsx index 371e526..b4077a9 100644 --- a/components/files/ListFiles.tsx +++ b/components/files/ListFiles.tsx @@ -18,6 +18,7 @@ interface ListFilesProps { onClickDeleteFile?: (parentPath: string, name: string) => Promise; onClickCreateShare?: (filePath: string) => void; onClickOpenManageShare?: (fileShareId: string) => void; + onClickDownloadDirectory?: (parentPath: string, name: string) => void; isShowingNotes?: boolean; isShowingPhotos?: boolean; fileShareId?: string; @@ -39,6 +40,7 @@ export default function ListFiles( onClickDeleteFile, onClickCreateShare, onClickOpenManageShare, + onClickDownloadDirectory, isShowingNotes, isShowingPhotos, fileShareId, @@ -165,10 +167,26 @@ export default function ListFiles( typeof onClickOpenMoveDirectory === 'undefined') ? null : ( -
+
+ {typeof onClickDownloadDirectory === 'undefined' ? null : ( + + )}