-
Notifications
You must be signed in to change notification settings - Fork 25
fix: archive download on password protected links #1523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||
| import { RuntimeError } from '../errors' | ||||||||||||||||
| import { urlJoin } from '@opencloud-eu/web-client' | ||||||||||||||||
| import { HttpError, urlJoin } from '@opencloud-eu/web-client' | ||||||||||||||||
| import { ClientService } from '../services' | ||||||||||||||||
| import { triggerDownloadWithFilename } from '../helpers/download' | ||||||||||||||||
| import { Ref, ref, computed, unref } from 'vue' | ||||||||||||||||
|
|
@@ -11,6 +11,7 @@ interface TriggerDownloadOptions { | |||||||||||||||
| files?: string[] | ||||||||||||||||
| fileIds?: string[] | ||||||||||||||||
| publicToken?: string | ||||||||||||||||
| publicLinkPassword?: string | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| export class ArchiverService { | ||||||||||||||||
|
|
@@ -55,14 +56,38 @@ export class ArchiverService { | |||||||||||||||
| throw new RuntimeError('download url could not be built') | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const url = options.publicToken | ||||||||||||||||
| let url = options.publicToken | ||||||||||||||||
| ? downloadUrl | ||||||||||||||||
| : await this.clientService.ocs.signUrl( | ||||||||||||||||
| downloadUrl, | ||||||||||||||||
| this.userStore.user?.onPremisesSamAccountName | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| triggerDownloadWithFilename(url) | ||||||||||||||||
| let fileName: string | ||||||||||||||||
| if (options.publicLinkPassword) { | ||||||||||||||||
| // FIXME: remove as soon as we remove client-side URL signing https://github.com/opencloud-eu/opencloud/issues/1197 | ||||||||||||||||
| try { | ||||||||||||||||
| const response = await fetch(url, { | ||||||||||||||||
| headers: { | ||||||||||||||||
| ...this.clientService.getRequestHeaders({ useAuth: false }), | ||||||||||||||||
| Authorization: | ||||||||||||||||
| 'Basic ' + | ||||||||||||||||
| Buffer.from(['public', options.publicLinkPassword].join(':')).toString('base64') | ||||||||||||||||
| } | ||||||||||||||||
| }) | ||||||||||||||||
|
|
||||||||||||||||
| if (!response.ok) { | ||||||||||||||||
| throw new HttpError('', response) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const blob = await response.blob() | ||||||||||||||||
| url = URL.createObjectURL(blob) | ||||||||||||||||
| fileName = decodeURI(response.headers.get('content-disposition')?.split('"')[1]) | ||||||||||||||||
|
||||||||||||||||
| fileName = decodeURI(response.headers.get('content-disposition')?.split('"')[1]) | |
| { | |
| const contentDisposition = response.headers.get('content-disposition'); | |
| // Try to extract filename from header (handles quoted and unquoted) | |
| const match = contentDisposition && contentDisposition.match(/filename\*?=(?:UTF-8'')?("?)([^";]+)\1/); | |
| fileName = match ? decodeURI(match[2]) : 'archive'; | |
| } |
Uh oh!
There was an error while loading. Please reload this page.