mirror of
https://github.com/nextcloud/server.git
synced 2026-03-03 14:01:34 -05:00
feat(files): Allow to download files on public shares
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
ada6a61688
commit
a84de3c755
2 changed files with 36 additions and 17 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue