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 {
|
try {
|
||||||
const message = 'IPFS started'
|
const message = 'IPFS started'
|
||||||
console.time(message)
|
console.time(message)
|
||||||
|
|
||||||
ipfs = await Ipfs.create()
|
ipfs = await Ipfs.create()
|
||||||
console.timeEnd(message)
|
console.timeEnd(message)
|
||||||
ipfsMessage = message
|
ipfsMessage = message
|
||||||
|
|
||||||
const { version } = await ipfs.version()
|
const { agentVersion } = await ipfs.id()
|
||||||
ipfsVersion = version
|
ipfsVersion = agentVersion
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = `IPFS init error: ${error.message}`
|
const message = `IPFS init error: ${error.message}`
|
||||||
ipfsMessage = message
|
ipfsMessage = message
|
||||||
@ -43,7 +44,7 @@ export default function useIpfs() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
startIpfs()
|
startIpfs()
|
||||||
|
|
||||||
// just like componentDidUnmount()
|
// just like componentWillUnmount()
|
||||||
return function cleanup() {
|
return function cleanup() {
|
||||||
if (ipfs && ipfs.stop) {
|
if (ipfs && ipfs.stop) {
|
||||||
console.time('IPFS stopped')
|
console.time('IPFS stopped')
|
||||||
|
@ -57,10 +57,15 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
|||||||
const cid = response[0].hash
|
const cid = response[0].hash
|
||||||
console.log(`File added: ${cid}`)
|
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}`
|
const url = `https://ipfs.io/ipfs/${cid}`
|
||||||
setMessage('Checking global IPFS URL')
|
const urlGateway = `https://gateway.ipfs.io/ipfs/${cid}`
|
||||||
await pingUrl(url)
|
|
||||||
|
setMessage('Checking IPFS gateway URL')
|
||||||
|
await pingUrl(urlGateway)
|
||||||
|
|
||||||
// add IPFS url to file.url
|
// add IPFS url to file.url
|
||||||
addFile(url)
|
addFile(url)
|
||||||
@ -98,10 +103,7 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{ipfsMessage !== '' && (
|
{ipfsMessage !== '' && (
|
||||||
<div
|
<div className={styles.message} title={ipfsVersion}>
|
||||||
className={styles.message}
|
|
||||||
title={`js-ipfs v${ipfsVersion}`}
|
|
||||||
>
|
|
||||||
{ipfsMessage}
|
{ipfsMessage}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user