Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timeout on fxart metadata #265

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/mappings/utils/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { contentFrom, type Content } from '@kodadot1/hyperdata'
import { ensure } from '@kodadot1/metasquid'
import { EntityWithId, TokenMetadata } from '@kodadot1/metasquid/types'
import { $obtain } from '@kodadot1/minipfs'
import { EntityWithId } from '@kodadot1/metasquid/types'
import { $obtain, type URI, obtain } from '@kodadot1/minipfs'
import { MetadataEntity } from '../../model'
import logger from './logger'
// import { attributeFrom } from './types'
Expand All @@ -10,12 +10,22 @@ export const BASE_URL = 'https://image.w.kodadot.xyz/'
/**
* Fetch the metadata from the IPFS
* @param metadata - the metadata to fetch
**/
**/
export const fetchMetadata = async <T extends Content>(metadata: string): Promise<T> => {
try {
if (!metadata) {
return ensure<T>({})
}

// e.g: https://fxart-beta.kodadot.workers.dev/metadata/v1/json?chain=ahp&collection=115&nft=2404413027&metadata=ipfs:%2F%2Fbafybeidwapzo6tll4qc2n4u7gmbjdett6fi37xis7dwzpacazxhjm6z7t4%2F0.json
if (metadata.includes('kodadot.workers.dev/metadata/')) {
const value = await obtain(metadata as URI, {
retry: 6,
retryDelay: 10_000,
})
return contentFrom(value as any) as T
}

const value = await $obtain<T>(metadata, ['rmrk', 'infura_kodadot1'], true)
return contentFrom(value as any) as T
} catch (e) {
Expand All @@ -28,7 +38,7 @@ export const fetchMetadata = async <T extends Content>(metadata: string): Promis
/**
* Fetch the list of metadata from the IPFS
* @param metadata - the metadata to fetch
**/
**/
export const fetchAllMetadata = async <T extends Content>(
metadata: string[]
): Promise<(Partial<MetadataEntity> & EntityWithId)[]> => {
Expand All @@ -43,11 +53,8 @@ export const fetchAllMetadata = async <T extends Content>(
* Format the metadata to be compatible with the cache model
* @param id - the id of the metadata (CID)
* @param metadata - the metadata to fetch
**/
export const makeCompatibleMetadata = (
id: string,
metadata: Content
): Partial<MetadataEntity> & EntityWithId => ({
**/
export const makeCompatibleMetadata = (id: string, metadata: Content): Partial<MetadataEntity> & EntityWithId => ({
id,
description: metadata.description || '',
image: metadata.image || metadata.thumbnail,
Expand Down