From 27addc6c74aaf753983c395bfa8d88608da11dac Mon Sep 17 00:00:00 2001 From: dholms Date: Mon, 20 Nov 2023 19:12:57 -0600 Subject: [PATCH] base case for findBlobRefs --- packages/pds/src/api/com/atproto/temp/importRepo.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/pds/src/api/com/atproto/temp/importRepo.ts b/packages/pds/src/api/com/atproto/temp/importRepo.ts index 483bed271d8..ff11dd5f6d1 100644 --- a/packages/pds/src/api/com/atproto/temp/importRepo.ts +++ b/packages/pds/src/api/com/atproto/temp/importRepo.ts @@ -218,10 +218,13 @@ const importBlob = async ( }) } -const findBlobRefs = (val: LexValue): BlobRef[] => { +export const findBlobRefs = (val: LexValue, layer = 0): BlobRef[] => { + if (layer > 10) { + return [] + } // walk arrays if (Array.isArray(val)) { - return val.flatMap((item) => findBlobRefs(item)) + return val.flatMap((item) => findBlobRefs(item, layer + 1)) } // objects if (val && typeof val === 'object') { @@ -233,7 +236,7 @@ const findBlobRefs = (val: LexValue): BlobRef[] => { if (CID.asCID(val) || val instanceof Uint8Array) { return [] } - return Object.values(val).flatMap((item) => findBlobRefs(item)) + return Object.values(val).flatMap((item) => findBlobRefs(item, layer + 1)) } // pass through return []