Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
doGetArchiveURL: (hash) => async ({ dispatch, store, getIpfs }) => {
const ipfs = getIpfs()
const apiAddress = store.selectIpfsApiAddress()
dispatch({ type: 'FILES_ARCHIVE_FILES' })
// Try to use the HTTP API of the local daemon
const url = apiAddress !== null
? toUri(apiAddress).replace('tcp://', 'http://').concat('/api')
: ENDPOINTS.api
// If no hash was passed it is to download everything
if (!hash) {
const files = Object.values(store.selectFiles())
hash = await makeHashFromFiles(files, ipfs)
}
return {
url: `${url}/v0/get?arg=${hash}&archive=true&compress=true`,
filename: `shared-via-ipfs_${hash.slice(-7)}.tar.gz`
}
},
function getURLFromAddress (name, config) {
if (!config) return null
try {
const address = Array.isArray(config.Addresses[name])
? config.Addresses[name][0]
: config.Addresses[name]
return toUri(address).replace('tcp://', 'http://')
} catch (error) {
console.log(`Failed to get url from Addresses.${name}`, error)
return null
}
}
function parseAddr (addr) {
return toUri(addr.toString().includes('/http') ? addr : addr.encapsulate('/http'))
}