From 8c368729679e429aa38c9049cd17e2bd802dd538 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 9 Jun 2022 14:36:48 +0200 Subject: [PATCH] fix: use gateway links to download standalone files --- src/files/FilesPage.js | 13 ++++++++++--- src/lib/files.js | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/files/FilesPage.js b/src/files/FilesPage.js index a728fea53..4a0eae145 100644 --- a/src/files/FilesPage.js +++ b/src/files/FilesPage.js @@ -62,10 +62,17 @@ const FilesPage = ({ return downloadAbort() } - const updater = (v) => setDownloadProgress(v) const { url, filename, method } = await doFilesDownloadLink(files) - const { abort } = await downloadFile(url, filename, updater, method) - setDownloadAbort(() => abort) + + if (method === 'GET') { + const link = document.createElement('a') + link.href = url + link.click() + } else { + const updater = (v) => setDownloadProgress(v) + const { abort } = await downloadFile(url, filename, updater, method) + setDownloadAbort(() => abort) + } } const onAddFiles = (raw, root = '') => { if (root === '') root = files.path diff --git a/src/lib/files.js b/src/lib/files.js index 7f29878c0..72a0a4999 100644 --- a/src/lib/files.js +++ b/src/lib/files.js @@ -54,7 +54,7 @@ async function downloadSingle (file, gatewayUrl, apiUrl) { filename = `${name}.tar.gz` method = 'POST' // API is POST-only } else { - url = `${gatewayUrl}/ipfs/${file.cid}` + url = `${gatewayUrl}/ipfs/${file.cid}?download=true&filename=${file.name}` filename = file.name method = 'GET' }