From cb5a1f80653792f4f625b50eb26b975fed7cfe30 Mon Sep 17 00:00:00 2001 From: Preschian Febryantara Date: Sat, 6 Apr 2024 16:07:08 +0700 Subject: [PATCH] fix: timeout on fxart metadata --- src/mappings/utils/metadata.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/mappings/utils/metadata.ts b/src/mappings/utils/metadata.ts index 2daf5b4d..05d19027 100644 --- a/src/mappings/utils/metadata.ts +++ b/src/mappings/utils/metadata.ts @@ -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' @@ -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 (metadata: string): Promise => { try { if (!metadata) { return ensure({}) } + + // 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(metadata, ['rmrk', 'infura_kodadot1'], true) return contentFrom(value as any) as T } catch (e) { @@ -28,7 +38,7 @@ export const fetchMetadata = async (metadata: string): Promis /** * Fetch the list of metadata from the IPFS * @param metadata - the metadata to fetch -**/ + **/ export const fetchAllMetadata = async ( metadata: string[] ): Promise<(Partial & EntityWithId)[]> => { @@ -43,11 +53,8 @@ export const fetchAllMetadata = async ( * 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 & EntityWithId => ({ + **/ +export const makeCompatibleMetadata = (id: string, metadata: Content): Partial & EntityWithId => ({ id, description: metadata.description || '', image: metadata.image || metadata.thumbnail,