Skip to content

Commit

Permalink
Switch to resource id based archiver backend
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Sep 24, 2021
1 parent 56aa196 commit c169c63
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ export default {
async downloadAsArchive() {
await triggerDownloadAsArchive({
folderPath: this.currentFolder.path,
fileNames: this.selectedFiles.map(f => f.name),
fileIds: this.selectedFiles.map(r => r.fileId),
token: this.getToken
}).catch(e => {
console.error(e)
Expand Down
14 changes: 7 additions & 7 deletions packages/web-app-files/src/helpers/download/downloadAsArchive.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { archiverService, clientService } from '../../services'
import { AxiosResponse } from 'axios'
import { major } from 'semver'
import { RuntimeError } from 'web-runtime/src/container/error'

interface TriggerDownloadAsArchiveOptions {
folderPath: string
fileNames?: string[]
fileIds: string[]
token: string // TODO: solve download from a) public link b) public link with password
}

export const triggerDownloadAsArchive = async (
options: TriggerDownloadAsArchiveOptions
): Promise<AxiosResponse> => {
if (!isDownloadAsArchiveAvailable()) {
return
throw new RuntimeError('no archiver capability available')
}
if (options.fileIds.length === 0) {
throw new RuntimeError('requested archive with empty list of resources')
}
const majorVersion = major(archiverService.capability.version)
switch (majorVersion) {
case 2: {
const queryParams = [
'dir=' + options.folderPath,
...(options.fileNames || []).map(f => 'file=' + f)
]
const queryParams = [...options.fileIds.map(id => `file=${id}`)]
const url = archiverService.url + '?' + queryParams.join('&')
return await clientService.httpAuthenticated(options.token).get(url)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default {
methods: {
async $_downloadFolder_trigger(resource) {
await triggerDownloadAsArchive({
folderPath: resource.path,
fileIds: [resource.fileId],
token: this.getToken
})
}
Expand Down

0 comments on commit c169c63

Please sign in to comment.