From 86b16e8376cef5e54a364d4f28d3af83c969d62e Mon Sep 17 00:00:00 2001 From: Diogo Castro Date: Wed, 15 Dec 2021 23:20:56 +0100 Subject: [PATCH] testing public link token --- .../src/components/AppBar/AppBar.vue | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/packages/web-app-files/src/components/AppBar/AppBar.vue b/packages/web-app-files/src/components/AppBar/AppBar.vue index 06542f7d1b6..8d695ed401d 100644 --- a/packages/web-app-files/src/components/AppBar/AppBar.vue +++ b/packages/web-app-files/src/components/AppBar/AppBar.vue @@ -546,23 +546,32 @@ export default { async addAppProviderFile(fileName) { try { const parent = this.currentFolder.fileId + const publicToken = (this.$router.currentRoute.params.item || '').split('/')[0] const configUrl = this.configuration.server - const appNewUrl = this.capabilities.files.app_providers[0].new_url.replace(/^\/+/, '') - const url = configUrl + appNewUrl + `?parent_container_id=${parent}&filename=${fileName}` - - const headers = new Headers() - if (!this.isPublicFilesRoute) { - headers.append('Authorization', 'Bearer ' + this.getToken) - headers.append('X-Requested-With', 'XMLHttpRequest') - } else { - headers.append( - 'Authorization', - 'Basic ' + Buffer.from('public:' + this.publicLinkPassword).toString('base64') - ) + const appNewUrl = 'app/new' // this.capabilities.files.app_providers[0].new_url.replace(/^\/+/, '') + const url = + configUrl + + appNewUrl + + `?parent_container_id=${parent}&filename=${encodeURIComponent(fileName)}` + + (this.isPublicFilesRoute ? `&public-token=${publicToken}` : '') + + const headers = { + 'X-Requested-With': 'XMLHttpRequest', + ...(this.isPublicFilesRoute && { + 'public-token': publicToken + }), + ...(this.publicLinkPassword && { + Authorization: + 'Basic ' + + Buffer.from(['public', this.publicLinkPassword].join(':')).toString('base64') + }), + ...(this.getToken && { + Authorization: 'Bearer ' + this.getToken + }) } - const response = await fetch(encodeURI(url), { + const response = await fetch(url, { method: 'POST', headers })