Skip to content

Commit

Permalink
Sketch for fixing owncloud#8456
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalwengerter committed May 16, 2023
1 parent 43c9c45 commit e00649a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
8 changes: 8 additions & 0 deletions changelog/unreleased/enhancement-respect-archiver-limits
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Respect archiver limits

The archiver service can now announce a limit for both the amount of resources and
the size of the currently selected resources. The web UI now respects those limits
and shows a disabled download button once the limit has been reached.

https://github.com/owncloud/web/pull/9055
https://github.com/owncloud/web/issues/8456
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,45 @@ export const useFileActionsDownloadArchive = ({ store }: { store?: Store<any> }
})
}

const archiverLimitsExceeded = computed(() => {
const archiverCapabilities = archiverService.capability
if (!archiverCapabilities) {
return
}

const selectedFiles: Resource[] = store.getters['Files/selectedFiles']

const selectedFilesAmount = selectedFiles.length

// TODO: selectedFilesSize doesn't traverse into folders
const selectedFilesSize = selectedFiles.reduce(
(accumulator, currentValue) =>
accumulator +
(typeof currentValue.size === 'string' ? parseInt(currentValue.size) : currentValue.size),
0
)

return (
// TODO: "Mocking" low capability for easy testing
selectedFilesAmount > 2 ||
// selectedFilesAmount > parseInt(archiverCapabilities.max_num_files) ||
// TODO: Check whether archiver and web use the same base for filesize calculation
selectedFilesSize > parseInt(archiverCapabilities.max_size)
)
})

const actions = computed((): FileAction[] => {
return [
{
name: 'download-archive',
icon: 'inbox-archive',
handler: (args) => loadingService.addTask(() => handler(args)),
label: () => {
return $gettext('Download')
return archiverLimitsExceeded.value
? $gettext('Unable to download that many files at once')
: $gettext('Download')
},
isDisabled: () => archiverLimitsExceeded.value,
isEnabled: ({ resources }) => {
if (
unref(isFilesAppActive) &&
Expand Down
2 changes: 2 additions & 0 deletions packages/web-app-files/src/services/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface ArchiverCapability {
formats: string[]
// eslint-disable-next-line camelcase
archiver_url: string
max_num_files: string
max_size: string
}

interface TriggerDownloadOptions {
Expand Down

0 comments on commit e00649a

Please sign in to comment.