reformat file sanitizers to use update ipfs api

This commit is contained in:
Barry Gitarts 2019-08-09 08:06:19 -04:00 committed by Barry G
parent ea7c90efe9
commit 461604bd66
2 changed files with 15 additions and 5 deletions

View File

@ -34,7 +34,7 @@ async function getProjectAssets(projectId, setState, debug=false){
const projectInfo = await LiquidPledging.methods.getPledgeAdmin(projectId).call()
const CID = projectInfo.url.split('/').slice(-1)[0]
if (debug) console.log({CID, projectInfo, ipfs})
getFiles(CID)
getFilesWeb(CID)
.then((files) => {
setState(files)
const manifest = files[2]
@ -45,7 +45,7 @@ async function getProjectAssets(projectId, setState, debug=false){
databaseExists('ipfs')
.catch(() => window.location.reload())
getFilesWeb(CID)
getFiles(CID)
.then((files) => {
setState(files)
const manifest = files[2]
@ -93,11 +93,15 @@ export function useProfileData(profiles) {
return delegatePledges
}
const isManifest = asset => {
const name = asset.path.split('/').slice(-1)[0]
return name.toLowerCase() === 'manifest.json'
}
const getProjectManifest = assets => {
if (!assets) {
return null;
}
const manifest = assets.find(a => a.name.toLowerCase() === 'manifest.json');
const manifest = assets.find(isManifest);
if (!manifest) {
return null;
}

View File

@ -8,8 +8,14 @@ const formatMedia = content => {
return src
}
const getName = asset => asset.path.split('/').slice(-1)[0]
const isManifest = asset => {
const name = getName(asset)
return name.toLowerCase() === 'manifest.json'
}
const getProjectManifest = assets => {
return assets ? JSON.parse(assets.find(a => a.name.toLowerCase() === 'manifest.json').content) : null
return assets ? JSON.parse(assets.find(isManifest).content) : null
}
export function getNumberOfBackers(pledges){
@ -35,7 +41,7 @@ export const getMediaSrc = assets => {
if (media.url) return media.url
if (media.file && media.file !== '/root/') {
return formatMedia(
assets.find(a => a.name === getFile(media.file)).content
assets.find(a => getName(a) === getFile(media.file)).content
)
}
}