From c0e81ff58408b4658cfac8828e65be73d63d7436 Mon Sep 17 00:00:00 2001 From: Raman Shekhawat Date: Wed, 9 Aug 2023 15:21:46 +0530 Subject: [PATCH] hot fixes metada issue --- src/populateGenesis.ts | 4 ++-- src/server-extension/resolvers/refresh_metadata.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/populateGenesis.ts b/src/populateGenesis.ts index db2fdce4b..a1b319010 100644 --- a/src/populateGenesis.ts +++ b/src/populateGenesis.ts @@ -401,7 +401,7 @@ async function syncAttributes(ctx: CommonContext, block: SubstrateBlock) { updatedAt: new Date(block.timestamp), }) - if (key === 'uri') { + if (['uri', 'name', 'description', 'fallback_image', 'media', 'attributes'].includes(key)) { const token = new Token({ id, metadata: new Metadata() }) token.metadata = await getMetadata(token.metadata as Metadata, attribute) await ctx.store.save(token) @@ -420,7 +420,7 @@ async function syncAttributes(ctx: CommonContext, block: SubstrateBlock) { updatedAt: new Date(block.timestamp), }) - if (key === 'uri') { + if (['uri', 'name', 'description', 'fallback_image', 'media', 'attributes'].includes(key)) { const collection = new Collection({ id, metadata: new Metadata() }) collection.metadata = await getMetadata(collection.metadata as Metadata, attribute) await ctx.store.save(collection) diff --git a/src/server-extension/resolvers/refresh_metadata.ts b/src/server-extension/resolvers/refresh_metadata.ts index 6e7cf522e..e29163dcf 100644 --- a/src/server-extension/resolvers/refresh_metadata.ts +++ b/src/server-extension/resolvers/refresh_metadata.ts @@ -66,6 +66,15 @@ export class RefreshMetadataResolver { resource.metadata = new Metadata() } resource.metadata = await getMetadata(resource.metadata, resource.attributes.find((a) => a.key === 'uri') ?? null) + const syncAttributesPromise = resource.attributes + .filter((a) => a.key !== 'uri') + .map(async (a) => { + if (resource && resource.metadata) { + resource.metadata = await getMetadata(resource.metadata, a) + } + }) + + await Promise.all(syncAttributesPromise) try { await manager.save(resource) } catch (error) {