mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
IPFS gateway tweaks
This commit is contained in:
parent
9c38c82496
commit
b6d255bbad
@ -23,12 +23,13 @@ export default function useIpfs() {
|
||||
try {
|
||||
const message = 'IPFS started'
|
||||
console.time(message)
|
||||
|
||||
ipfs = await Ipfs.create()
|
||||
console.timeEnd(message)
|
||||
ipfsMessage = message
|
||||
|
||||
const { version } = await ipfs.version()
|
||||
ipfsVersion = version
|
||||
const { agentVersion } = await ipfs.id()
|
||||
ipfsVersion = agentVersion
|
||||
} catch (error) {
|
||||
const message = `IPFS init error: ${error.message}`
|
||||
ipfsMessage = message
|
||||
@ -43,7 +44,7 @@ export default function useIpfs() {
|
||||
useEffect(() => {
|
||||
startIpfs()
|
||||
|
||||
// just like componentDidUnmount()
|
||||
// just like componentWillUnmount()
|
||||
return function cleanup() {
|
||||
if (ipfs && ipfs.stop) {
|
||||
console.time('IPFS stopped')
|
||||
|
@ -57,10 +57,15 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
||||
const cid = response[0].hash
|
||||
console.log(`File added: ${cid}`)
|
||||
|
||||
// ping url to make it globally available
|
||||
// Ping gateway url to make it globally available.
|
||||
// Using gateway.ipfs.io is faster for initial ping,
|
||||
// but we store ipfs.io url in DDO.
|
||||
// https://ipfs.github.io/public-gateway-checker/
|
||||
const url = `https://ipfs.io/ipfs/${cid}`
|
||||
setMessage('Checking global IPFS URL')
|
||||
await pingUrl(url)
|
||||
const urlGateway = `https://gateway.ipfs.io/ipfs/${cid}`
|
||||
|
||||
setMessage('Checking IPFS gateway URL')
|
||||
await pingUrl(urlGateway)
|
||||
|
||||
// add IPFS url to file.url
|
||||
addFile(url)
|
||||
@ -98,10 +103,7 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
||||
/>
|
||||
)}
|
||||
{ipfsMessage !== '' && (
|
||||
<div
|
||||
className={styles.message}
|
||||
title={`js-ipfs v${ipfsVersion}`}
|
||||
>
|
||||
<div className={styles.message} title={ipfsVersion}>
|
||||
{ipfsMessage}
|
||||
</div>
|
||||
)}
|
||||
|
Loading…
Reference in New Issue
Block a user