Skip to content

Commit 653cc70

Browse files
authored
Merge branch 'main' into i18n-sync
2 parents 672ad9a + d1bcbbf commit 653cc70

File tree

6 files changed

+24
-153
lines changed

6 files changed

+24
-153
lines changed

src/bundles/files/actions.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,8 @@ const actions = () => ({
396396
* @param {FileStat[]} files
397397
*/
398398
doFilesDownloadLink: (files) => perform(ACTIONS.DOWNLOAD_LINK, async (ipfs, { store }) => {
399-
const apiUrl = store.selectApiUrl()
400399
const gatewayUrl = store.selectGatewayUrl()
401-
return await getDownloadLink(files, gatewayUrl, apiUrl, ipfs)
400+
return getDownloadLink(files, gatewayUrl, ipfs)
402401
}),
403402

404403
/**
@@ -407,7 +406,7 @@ const actions = () => ({
407406
*/
408407
doFilesDownloadCarLink: (files) => perform(ACTIONS.DOWNLOAD_LINK, async (ipfs, { store }) => {
409408
const gatewayUrl = store.selectGatewayUrl()
410-
return await getCarLink(files, gatewayUrl, ipfs)
409+
return getCarLink(files, gatewayUrl, ipfs)
411410
}),
412411

413412
/**
@@ -417,7 +416,7 @@ const actions = () => ({
417416
doFilesShareLink: (files) => perform(ACTIONS.SHARE_LINK, async (ipfs, { store }) => {
418417
// ensureMFS deliberately omitted here, see https://github.com/ipfs/ipfs-webui/issues/1744 for context.
419418
const publicGateway = store.selectPublicGateway()
420-
return await getShareableLink(files, publicGateway, ipfs)
419+
return getShareableLink(files, publicGateway, ipfs)
421420
}),
422421

423422
/**

src/files/FilesPage.js

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { withTranslation, Trans } from 'react-i18next'
66
import ReactJoyride from 'react-joyride'
77
// Lib
88
import { filesTour } from '../lib/tours'
9-
import downloadFile from './download-file'
109
// Components
1110
import ContextMenu from './context-menu/ContextMenu'
1211
import withTour from '../components/tour/withTour'
@@ -27,8 +26,6 @@ const FilesPage = ({
2726
files, filesPathInfo, pinningServices, toursEnabled, handleJoyrideCallback, isCliTutorModeEnabled, cliOptions, t
2827
}) => {
2928
const contextMenuRef = useRef()
30-
const [downloadAbort, setDownloadAbort] = useState(null)
31-
const [downloadProgress, setDownloadProgress] = useState(null)
3229
const [modals, setModals] = useState({ show: null, files: null })
3330
const [contextMenu, setContextMenu] = useState({
3431
isOpen: false,
@@ -58,32 +55,13 @@ const FilesPage = ({
5855
*/
5956

6057
const onDownload = async (files) => {
61-
if (downloadProgress !== null) {
62-
return downloadAbort()
63-
}
64-
65-
const { url, filename, method } = await doFilesDownloadLink(files)
66-
67-
if (method === 'GET') {
68-
const link = document.createElement('a')
69-
link.href = url
70-
link.click()
71-
} else {
72-
const updater = (v) => setDownloadProgress(v)
73-
const { abort } = await downloadFile(url, filename, updater, method)
74-
setDownloadAbort(() => abort)
75-
}
58+
const url = await doFilesDownloadLink(files)
59+
window.location.href = url
7660
}
7761

7862
const onDownloadCar = async (files) => {
79-
if (downloadProgress !== null) {
80-
return downloadAbort()
81-
}
82-
8363
const url = await doFilesDownloadCarLink(files)
84-
const link = document.createElement('a')
85-
link.href = url
86-
link.click()
64+
window.location.href = url
8765
}
8866

8967
const onAddFiles = (raw, root = '') => {
@@ -167,7 +145,6 @@ const FilesPage = ({
167145
pendingPins={pendingPins}
168146
failedPins={failedPins}
169147
upperDir={files.upper}
170-
downloadProgress={downloadProgress}
171148
onShare={(files) => showModal(SHARE, files)}
172149
onRename={(files) => showModal(RENAME, files)}
173150
onRemove={(files) => showModal(DELETE, files)}

src/files/download-file.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/files/files-list/FilesList.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const mergeRemotePinsIntoFiles = (files, remotePins = [], pendingPins = [], fail
5151
}
5252

5353
export const FilesList = ({
54-
className, files, pins, pinningServices, remotePins, pendingPins, failedPins, filesSorting, updateSorting, downloadProgress, filesIsFetching, filesPathInfo, showLoadingAnimation,
54+
className, files, pins, pinningServices, remotePins, pendingPins, failedPins, filesSorting, updateSorting, filesIsFetching, filesPathInfo, showLoadingAnimation,
5555
onShare, onSetPinning, onInspect, onDownload, onRemove, onRename, onNavigate, onRemotePinClick, onAddFiles, onMove, doFetchRemotePins, doDismissFailedPin, handleContextMenuClick, t
5656
}) => {
5757
const [selected, setSelected] = useState([])
@@ -355,7 +355,6 @@ export const FilesList = ({
355355
inspect={() => onInspect(selectedFiles[0].cid)}
356356
count={selectedFiles.length}
357357
isMfs={filesPathInfo.isMfs}
358-
downloadProgress={downloadProgress}
359358
size={selectedFiles.reduce((a, b) => a + (b.size || 0), 0)} />
360359
}
361360
</Fragment> }
@@ -374,7 +373,6 @@ FilesList.propTypes = {
374373
asc: PropTypes.bool.isRequired
375374
}),
376375
updateSorting: PropTypes.func.isRequired,
377-
downloadProgress: PropTypes.number,
378376
filesIsFetching: PropTypes.bool,
379377
filesPathInfo: PropTypes.object,
380378
// Actions

src/files/selected-actions/SelectedActions.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class SelectedActions extends React.Component {
5555
download: PropTypes.func.isRequired,
5656
rename: PropTypes.func.isRequired,
5757
inspect: PropTypes.func.isRequired,
58-
downloadProgress: PropTypes.number,
5958
t: PropTypes.func.isRequired,
6059
tReady: PropTypes.bool.isRequired,
6160
isMfs: PropTypes.bool.isRequired,
@@ -70,37 +69,12 @@ class SelectedActions extends React.Component {
7069
force100: false
7170
}
7271

73-
componentDidUpdate (prev) {
74-
if (this.props.downloadProgress === 100 && prev.downloadProgress !== 100) {
75-
this.setState({ force100: true })
76-
setTimeout(() => {
77-
this.setState({ force100: false })
78-
}, 2000)
79-
}
80-
}
81-
8272
componentDidMount () {
8373
this.containerRef.current && this.containerRef.current.focus()
8474
}
8575

86-
get downloadText () {
87-
if (this.state.force100) {
88-
return this.props.t('finished')
89-
}
90-
91-
if (!this.props.downloadProgress) {
92-
return this.props.t('app:actions.download')
93-
}
94-
95-
if (this.props.downloadProgress === 100) {
96-
return this.props.t('finished')
97-
}
98-
99-
return this.props.downloadProgress.toFixed(0) + '%'
100-
}
101-
10276
render () {
103-
const { t, tReady, animateOnStart, count, size, unselect, remove, share, setPinning, download, downloadProgress, rename, inspect, className, style, isMfs, ...props } = this.props
77+
const { t, tReady, animateOnStart, count, size, unselect, remove, share, setPinning, download, rename, inspect, className, style, isMfs, ...props } = this.props
10478

10579
const isSingle = count === 1
10680

@@ -131,7 +105,7 @@ class SelectedActions extends React.Component {
131105
</button>
132106
<button role="menuitem" className='tc mh2' onClick={download}>
133107
<StrokeDownload className='w3 hover-fill-navy-muted' fill='#A4BFCC' aria-hidden="true"/>
134-
<p className='ma0 f6'>{this.downloadText}</p>
108+
<p className='ma0 f6'>{t('app:actions.download')}</p>
135109
</button>
136110
<button role="menuitem" className={classNames('tc mh2', classes.action(isMfs))} onClick={isMfs ? remove : null}>
137111
<StrokeTrash className={classes.svg(isMfs)} fill='#A4BFCC' aria-hidden="true"/>

src/lib/files.js

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,20 @@ export function normalizeFiles (files) {
3535
}
3636

3737
/**
38-
* @typedef {Object} FileDownload
39-
* @property {string} url
40-
* @property {string} filename
41-
* @property {string} method
42-
*
43-
* @param {FileStat} file
38+
* @param {string} type
39+
* @param {string} name
40+
* @param {CID} cid
4441
* @param {string} gatewayUrl
45-
* @param {string} apiUrl
46-
* @returns {Promise<FileDownload>}
42+
* @returns {string}
4743
*/
48-
async function downloadSingle (file, gatewayUrl, apiUrl) {
49-
let url, filename, method
50-
51-
if (file.type === 'directory') {
52-
const name = file.name || `download_${file.cid}` // Name is not always available.
53-
url = `${apiUrl}/api/v0/get?arg=${file.cid}&archive=true&compress=true`
54-
filename = `${name}.tar.gz`
55-
method = 'POST' // API is POST-only
44+
function getDownloadURL (type, name, cid, gatewayUrl) {
45+
if (type === 'directory') {
46+
const filename = `${name || `download_${cid.toString()}`}.tar`
47+
return `${gatewayUrl}/ipfs/${cid.toString()}?download=true&format=tar&filename=${filename}`
5648
} else {
57-
url = `${gatewayUrl}/ipfs/${file.cid}?download=true&filename=${file.name}`
58-
filename = file.name
59-
method = 'GET'
49+
const filename = `${name || cid}`
50+
return `${gatewayUrl}/ipfs/${cid.toString()}?download=true&filename=${filename}`
6051
}
61-
62-
return { url, filename, method }
6352
}
6453

6554
/**
@@ -87,42 +76,20 @@ export async function makeCIDFromFiles (files, ipfs) {
8776
return stat.cid
8877
}
8978

90-
/**
91-
*
92-
* @param {FileStat[]} files
93-
* @param {string} apiUrl
94-
* @param {IPFSService} ipfs
95-
* @returns {Promise<FileDownload>}
96-
*/
97-
async function downloadMultiple (files, apiUrl, ipfs) {
98-
if (!apiUrl) {
99-
const e = new Error('api url undefined')
100-
return Promise.reject(e)
101-
}
102-
103-
const cid = await makeCIDFromFiles(files, ipfs)
104-
105-
return {
106-
url: `${apiUrl}/api/v0/get?arg=${cid}&archive=true&compress=true`,
107-
filename: `download_${cid}.tar.gz`,
108-
method: 'POST' // API is POST-only
109-
}
110-
}
111-
11279
/**
11380
*
11481
* @param {FileStat[]} files
11582
* @param {string} gatewayUrl
116-
* @param {string} apiUrl
11783
* @param {IPFSService} ipfs
118-
* @returns {Promise<FileDownload>}
84+
* @returns {Promise<string>}
11985
*/
120-
export async function getDownloadLink (files, gatewayUrl, apiUrl, ipfs) {
86+
export async function getDownloadLink (files, gatewayUrl, ipfs) {
12187
if (files.length === 1) {
122-
return downloadSingle(files[0], gatewayUrl, apiUrl)
88+
return getDownloadURL(files[0].type, files[0].name, files[0].cid, gatewayUrl)
12389
}
12490

125-
return downloadMultiple(files, apiUrl, ipfs)
91+
const cid = await makeCIDFromFiles(files, ipfs)
92+
return getDownloadURL('directory', '', cid, gatewayUrl)
12693
}
12794

12895
/**

0 commit comments

Comments
 (0)