From 4235b4f5535794f38c0a20f00c00ef9286f5f64b Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Tue, 9 Apr 2024 21:37:07 -0400 Subject: [PATCH] removing already uploaded cids when replicate --- package.json | 2 +- src/protocols/chain-api.ts | 15 ++++++++++++++- src/types/blockchain.ts | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 744e407..9d239bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@functionland/react-native-fula", - "version": "1.54.18", + "version": "1.54.19", "description": "This package is a bridge to use the Fula libp2p protocols in the react-native which is using wnfs", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/src/protocols/chain-api.ts b/src/protocols/chain-api.ts index a88d0e4..20d70fb 100644 --- a/src/protocols/chain-api.ts +++ b/src/protocols/chain-api.ts @@ -341,6 +341,7 @@ export const manifestNewBatch = async ( ) { newCids.push(cid); } else { + let addCid = true; let formattedManifestInfo: BType.ManifestResponse = JSON.parse( JSON.stringify(manifestInfo.toHuman()) ); @@ -349,7 +350,19 @@ export const manifestNewBatch = async ( (user) => user.uploader === uploader ) ) { - newCids.push(formattedManifestInfo.manifestMetadata.job.uri); + addCid = false; + } + if (addCid && formattedManifestInfo?.manifestMetadata) { + try { + let manifestMetaData: BType.ManifestMetadata = JSON.parse( + formattedManifestInfo?.manifestMetadata + ); + if (manifestMetaData?.job?.uri) { + newCids.push(manifestMetaData.job.uri); + } + } catch (e) { + console.log('error while parsing manifestMetadata'); + } } } } diff --git a/src/types/blockchain.ts b/src/types/blockchain.ts index cd28a34..8d0224f 100644 --- a/src/types/blockchain.ts +++ b/src/types/blockchain.ts @@ -121,6 +121,6 @@ export interface UserData { export interface ManifestResponse { usersData: UserData[]; - manifestMetadata: ManifestMetadata; + manifestMetadata: string; size_?: number | null; // The question mark indicates that this field is optional. }