aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-08-02 12:32:59 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2024-09-06 03:38:47 +0200
commita84de3c755b25bdff0a4131dd552eb78715dd131 (patch)
treee5a492c27d3912ebe33f6bdf75f4e91cc09abbb6 /apps
parentada6a61688a7bfacf0a9d8ef4ec58d3cb56c9acc (diff)
downloadnextcloud-server-a84de3c755b25bdff0a4131dd552eb78715dd131.tar.gz
nextcloud-server-a84de3c755b25bdff0a4131dd552eb78715dd131.zip
feat(files): Allow to download files on public shares
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps')
-rw-r--r--apps/files/src/actions/downloadAction.ts23
-rw-r--r--apps/files/src/components/FileEntryMixin.ts30
2 files changed, 36 insertions, 17 deletions
diff --git a/apps/files/src/actions/downloadAction.ts b/apps/files/src/actions/downloadAction.ts
index cce1e48579a..f1bcb97e279 100644
--- a/apps/files/src/actions/downloadAction.ts
+++ b/apps/files/src/actions/downloadAction.ts
@@ -7,6 +7,8 @@ import type { ShareAttribute } from '../../../files_sharing/src/sharing'
import { FileAction, Permission, Node, FileType, View, DefaultType } from '@nextcloud/files'
import { t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
+import { getSharingToken, isPublicShare } from '@nextcloud/sharing/public'
+import { basename } from 'path'
import ArrowDownSvg from '@mdi/svg/svg/arrow-down.svg?raw'
@@ -19,11 +21,22 @@ const triggerDownload = function(url: string) {
const downloadNodes = function(dir: string, nodes: Node[]) {
const secret = Math.random().toString(36).substring(2)
- const url = generateUrl('/apps/files/ajax/download.php?dir={dir}&files={files}&downloadStartSecret={secret}', {
- dir,
- secret,
- files: JSON.stringify(nodes.map(node => node.basename)),
- })
+ let url: string
+ if (isPublicShare()) {
+ url = generateUrl('/s/{token}/download/{filename}?path={dir}&files={files}&downloadStartSecret={secret}', {
+ dir,
+ secret,
+ files: JSON.stringify(nodes.map(node => node.basename)),
+ token: getSharingToken(),
+ filename: `${basename(dir)}.zip}`,
+ })
+ } else {
+ url = generateUrl('/apps/files/ajax/download.php?dir={dir}&files={files}&downloadStartSecret={secret}', {
+ dir,
+ secret,
+ files: JSON.stringify(nodes.map(node => node.basename)),
+ })
+ }
triggerDownload(url)
}
diff --git a/apps/files/src/components/FileEntryMixin.ts b/apps/files/src/components/FileEntryMixin.ts
index f2a6f89cf22..73c6ce19387 100644
--- a/apps/files/src/components/FileEntryMixin.ts
+++ b/apps/files/src/components/FileEntryMixin.ts
@@ -10,6 +10,7 @@ import { showError } from '@nextcloud/dialogs'
import { FileType, Permission, Folder, File as NcFile, NodeStatus, Node, getFileActions } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
+import { isPublicShare } from '@nextcloud/sharing/public'
import { vOnClickOutside } from '@vueuse/components'
import { extname } from 'path'
import Vue, { defineComponent } from 'vue'
@@ -281,21 +282,26 @@ export default defineComponent({
}
// if ctrl+click or middle mouse button, open in new tab
- if (event.ctrlKey || event.metaKey || event.button === 1) {
- event.preventDefault()
- window.open(generateUrl('/f/{fileId}', { fileId: this.fileid }))
- return false
- }
-
- if (this.defaultFileAction) {
+ // also if there is no default action use this as a fallback
+ const metaKeyPressed = event.ctrlKey || event.metaKey || event.button === 1
+ if (metaKeyPressed || !this.defaultFileAction) {
event.preventDefault()
event.stopPropagation()
- // Execute the first default action if any
- this.defaultFileAction.exec(this.source, this.currentView, this.currentDir)
- } else {
- // fallback to open in current tab
- window.open(generateUrl('/f/{fileId}', { fileId: this.fileid }), '_self')
+ let url: string
+ if (isPublicShare()) {
+ url = this.source.encodedSource
+ } else {
+ url = generateUrl('/f/{fileId}', { fileId: this.fileid })
+ }
+ window.open(url, metaKeyPressed ? '_self' : undefined)
+ return
}
+
+ // every special case handled so just execute the default action
+ event.preventDefault()
+ event.stopPropagation()
+ // Execute the first default action if any
+ this.defaultFileAction.exec(this.source, this.currentView, this.currentDir)
},
openDetailsIfAvailable(event) {