Add selection download function
parent
13da56a2f6
commit
97a1dcddda
|
@ -72,6 +72,14 @@
|
||||||
{{ selection.size }} item(s) selected
|
{{ selection.size }} item(s) selected
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<NcActions>
|
||||||
|
<NcActionButton
|
||||||
|
:aria-label="t('memories', 'Download selection')"
|
||||||
|
@click="downloadSelection"
|
||||||
|
class="icon-download">
|
||||||
|
{{ t('memories', 'Download') }}
|
||||||
|
</NcActionButton>
|
||||||
|
</NcActions>
|
||||||
<NcActions>
|
<NcActions>
|
||||||
<NcActionButton
|
<NcActionButton
|
||||||
:aria-label="t('memories', 'Delete selection')"
|
:aria-label="t('memories', 'Delete selection')"
|
||||||
|
@ -752,6 +760,17 @@ export default {
|
||||||
await this.deleteFromViewWithAnimation(delIds, updatedDays);
|
await this.deleteFromViewWithAnimation(delIds, updatedDays);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** Download the selected files */
|
||||||
|
async downloadSelection() {
|
||||||
|
if (this.selection.size === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get files to download
|
||||||
|
const fileInfos = await dav.getFiles([...this.selection].map(p => p.fileid));
|
||||||
|
await dav.downloadFiles(fileInfos.map(f => f.filename));
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete elements from main view with some animation
|
* Delete elements from main view with some animation
|
||||||
* This function looks horribly slow, probably isn't that bad
|
* This function looks horribly slow, probably isn't that bad
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { getCurrentUser } from '@nextcloud/auth'
|
import { getCurrentUser } from '@nextcloud/auth'
|
||||||
|
import { generateUrl } from '@nextcloud/router'
|
||||||
import { genFileInfo } from './FileUtils'
|
import { genFileInfo } from './FileUtils'
|
||||||
import client from './DavClient';
|
import client from './DavClient';
|
||||||
|
|
||||||
|
@ -135,3 +136,37 @@ export async function deleteFile(path) {
|
||||||
const prefixPath = `/files/${getCurrentUser().uid}`;
|
const prefixPath = `/files/${getCurrentUser().uid}`;
|
||||||
return await client.deleteFile(`${prefixPath}${path}`);
|
return await client.deleteFile(`${prefixPath}${path}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download a file
|
||||||
|
*
|
||||||
|
* @param {string[]} fileNames - The file's names
|
||||||
|
*/
|
||||||
|
export async function downloadFiles(fileNames) {
|
||||||
|
const randomToken = Math.random().toString(36).substring(2)
|
||||||
|
|
||||||
|
const params = new URLSearchParams()
|
||||||
|
params.append('files', JSON.stringify(fileNames))
|
||||||
|
params.append('downloadStartSecret', randomToken)
|
||||||
|
|
||||||
|
const downloadURL = generateUrl(`/apps/files/ajax/download.php?${params}`)
|
||||||
|
|
||||||
|
window.location = `${downloadURL}downloadStartSecret=${randomToken}`
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const waitForCookieInterval = setInterval(
|
||||||
|
() => {
|
||||||
|
const cookieIsSet = document.cookie
|
||||||
|
.split(';')
|
||||||
|
.map(cookie => cookie.split('='))
|
||||||
|
.findIndex(([cookieName, cookieValue]) => cookieName === 'ocDownloadStarted' && cookieValue === randomToken)
|
||||||
|
|
||||||
|
if (cookieIsSet) {
|
||||||
|
clearInterval(waitForCookieInterval)
|
||||||
|
resolve(true)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
50
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue