Skip to content

Commit 26a2b14

Browse files
committed
Improve proposal content IPFS lookup
1 parent 14a7b9a commit 26a2b14

File tree

3 files changed

+258
-7
lines changed

3 files changed

+258
-7
lines changed

package-lock.json

+247
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"dompurify": "^3.1.5",
2424
"dotenv": "^16.4.5",
2525
"fuzzy-search": "^3.2.1",
26+
"is-ipfs": "^8.0.4",
2627
"lodash": "^4.17.21",
2728
"long": "^5.2.4",
2829
"mathjs": "^13.0.0",

src/utils/Proposal.mjs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import axios from 'axios'
2+
import { cid as isIPFSCID } from 'is-ipfs'
23

34
export const PROPOSAL_STATUSES = {
45
'': 'All',
@@ -30,18 +31,20 @@ const Proposal = async (data) => {
3031
} catch {
3132
try {
3233
let ipfsUrl
33-
if(metadata.startsWith('ipfs://')){
34+
if(metadata.startsWith('ipfs://') && metadata !== 'ipfs://CID'){
3435
ipfsUrl = metadata.replace("ipfs://", "https://ipfs.io/ipfs/")
3536
}else if(metadata.startsWith('https://')){
3637
ipfsUrl = metadata
37-
}else{
38+
}else if(isIPFSCID(metadata)){
3839
ipfsUrl = `https://ipfs.io/ipfs/${metadata}`
3940
}
40-
let response = await axios.get(ipfsUrl, { timeout: 5000 })
41-
if(response.headers['content-type'] === 'application/json'){
42-
metadata = response.data
43-
title = metadata.title
44-
description = metadata.summary || metadata.description || metadata.details
41+
if(ipfsUrl) {
42+
let response = await axios.get(ipfsUrl, { timeout: 5000 })
43+
if(response.headers['content-type'] === 'application/json'){
44+
metadata = response.data
45+
title = metadata.title
46+
description = metadata.summary || metadata.description || metadata.details
47+
}
4548
}
4649
} catch (e) {
4750
console.log(e)

0 commit comments

Comments
 (0)