fallback to fetch files from web if ipfs node fails

redirect on page create to fund-project path
This commit is contained in:
Barry Gitarts 2019-08-08 16:32:15 -04:00 committed by Barry G
parent 3645ba787e
commit ea7c90efe9
3 changed files with 13 additions and 3 deletions

View File

@ -210,7 +210,7 @@ const SubmissionSection = ({ classes, history }) => {
console.log({res})
openSnackBar('success', addProjectSucessMsg(res))
setTimeout(() => {
history.push(`/project/${getProjectId(res)}`)
history.push(`/fund-project/${getProjectId(res)}`)
resetForm()
}, 5000)
})

View File

@ -4,7 +4,7 @@ import LiquidPledging from '../../embarkArtifacts/contracts/LiquidPledging'
import { useState, useEffect, useMemo, useContext } from 'react'
import { unnest } from 'ramda'
import { timeSinceBlock } from '../../utils/dates'
import { getFiles, ipfs } from '../../utils/ipfs'
import { getFiles, getFilesWeb, ipfs } from '../../utils/ipfs'
import { databaseExists } from '../../utils/db'
import { arrayToObject } from '../../utils/array'
import { FundingContext } from '../../context'
@ -45,7 +45,7 @@ async function getProjectAssets(projectId, setState, debug=false){
databaseExists('ipfs')
.catch(() => window.location.reload())
getFiles(CID)
getFilesWeb(CID)
.then((files) => {
setState(files)
const manifest = files[2]

View File

@ -129,6 +129,16 @@ export const getFiles = CID => {
})
}
export const getFilesWeb = CID => {
const clean = CID.split('/').slice(-1)[0]
return new Promise(function(resolve, reject) {
ipfsHttp.get(clean, (err, files) => {
if (err) reject(err)
else resolve(files)
})
})
}
export const isWeb = str => str.includes('http')
export const formatMedia = str => {
return isWeb(str) ? str : `/root/${str}`