// FIXME: replace with a dedicated gateway
export const BASE_URL = 'https://cloudflare-ipfs.com/ipfs/'
export const api = Axios.create({
baseURL: BASE_URL,
headers: {
'Content-Type': 'application/json',
},
withCredentials: false,
timeout: 5000,
httpsAgent: new https.Agent({ keepAlive: true }),
})
export const fetchMetadata = async (
ctx: DataHandlerHandlerContext<Store, typeof fieldSelection>,
cid: string
): Promise<any | null> => {
try {
const { status, data } = await api.get(`${BASE_URL}/${cid}`)
ctx.log.info(`[IPFS] ${status} CID: ${cid}`)
if (status < 400) {
return data
}
} catch (e) {
ctx.log.warn(
`[IPFS] ERROR CID: ${cid} TRY ${(e as Error).message}`
)
}
return null
}
processor.run(new TypeormDatabase(), async (ctx) => {
for (let c of ctx.blocks) {
for (let log of c.logs) {
// track and decode NFT events to get CID
// use fetchMetadata() to fetch metadata
}
}
})