Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions webapp/js/layout/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<i class="fa-solid fa-sitemap"></i>
</Button>
<Button v-if="showDownload" @click="handleDownload" severity="secondary" size="small" text
:title="selectedFiles.length > 0 ? `Download ${selectedFiles.length} file${selectedFiles.length !== 1 ? 's' : ''}` : 'Download'" :disabled="isDownloading">
:title="downloadTitle" :disabled="isDownloading || downloadBlocked">
<i class="fa-solid fa-download"></i>
<span v-if="selectedFiles.length > 0" style="line-height: 1;" class="ms-1">{{ selectedFiles.length }}</span>
</Button>
Expand Down Expand Up @@ -84,7 +84,7 @@
</template>

<script>
import { utils } from 'ddb';
import ddb, { utils } from 'ddb';
import reg from '@/libs/api/sharedRegistry';
import { Features } from '@/libs/features';
import Alert from '@/components/Alert';
Expand Down Expand Up @@ -224,6 +224,25 @@ export default {
}
return 'Are you sure you want to download the entire dataset?';
},
downloadIsBulk: function () {
// Whole-dataset download or multi-file selection is always bulk.
if (this.selectedFiles.length !== 1) return true;
const sel = this.selectedFiles[0];
// Single selection counts as bulk only when it is a directory.
if (sel && sel.entry) return ddb.entry.isDirectory(sel.entry);
// Conservative fallback: treat as bulk when entry metadata is missing.
return true;
},
downloadBlocked: function () {
return !this.loggedIn
&& reg.getFeature(Features.DISABLE_ANONYMOUS_BULK_DOWNLOADS)
&& this.downloadIsBulk;
},
downloadTitle: function () {
if (this.downloadBlocked) return 'Login required to download multiple files or the entire dataset';
if (this.selectedFiles.length > 0) return `Download ${this.selectedFiles.length} file${this.selectedFiles.length !== 1 ? 's' : ''}`;
return 'Download';
},
userMenuItems: function () {
const items = [];

Expand Down
18 changes: 17 additions & 1 deletion webapp/js/libs/contextMenuItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,27 @@ function shareEmbedItem(ctx) {
}

function downloadItem(ctx) {
const isBulkSelection = () => {
const sel = ctx.getSelectedEntries();
if (sel.length === 0) return false;
if (sel.length > 1) return true;
// single selection: bulk if it's a directory
return ddb.entry.isDirectory(sel[0].entry);
};
const isBulkBlocked = () =>
!reg.isLoggedIn() &&
reg.getFeature(Features.DISABLE_ANONYMOUS_BULK_DOWNLOADS) &&
isBulkSelection();

return {
label: 'Download',
icon: 'fa-solid fa-download',
isVisible: () => ctx.getSelectedEntries().length > 0,
click: () => ctx.emit('downloadItems', ctx.getSelectedEntries())
isEnabled: () => !isBulkBlocked(),
click: () => {
if (isBulkBlocked()) return;
ctx.emit('downloadItems', ctx.getSelectedEntries());
}
};
}

Expand Down
3 changes: 2 additions & 1 deletion webapp/js/libs/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const Features = {
STORAGE_LIMITER: 'storageLimiter',
PASSWORD_POLICY: 'passwordPolicy',
DATASET_THUMBNAIL_CANDIDATES: 'datasetThumbnailCandidates',
MAX_EXPORT_SIZE_BYTES: 'maxExportSizeBytes'
MAX_EXPORT_SIZE_BYTES: 'maxExportSizeBytes',
DISABLE_ANONYMOUS_BULK_DOWNLOADS: 'disableAnonymousBulkDownloads'
};