diff --git a/config/system-user-dev.json b/config/system-user-dev.json index 87318d5..69826dc 100644 --- a/config/system-user-dev.json +++ b/config/system-user-dev.json @@ -1,6 +1,6 @@ { - "password": "YksrA6beZTqSioEpHxZd", + "password": "spksihHDsyk3JUUkH3xt", "email": "system@system.com", - "id": "67a8a4578de3cb65f3bbdbc0", - "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3YThhNDU3OGRlM2NiNjVmM2JiZGJjMCIsImlhdCI6MTczOTEwNTM2N30.YA9hkc0dUyNvKCLjWnW-L1J1UvCBvGKCVC8qkrKe4Xw" + "id": "67a8a8e25a3e45751f654a13", + "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3YThhOGUyNWEzZTQ1NzUxZjY1NGExMyIsImlhdCI6MTczOTEwNjUzMH0.ViWmWvfJF2UnM46pRXvl0sXThfP2dNlzrmzSxpWChew" } \ No newline at end of file diff --git a/src/use-cases/ipfs-use-cases.js b/src/use-cases/ipfs-use-cases.js index cf5c3b4..fe669a5 100644 --- a/src/use-cases/ipfs-use-cases.js +++ b/src/use-cases/ipfs-use-cases.js @@ -177,27 +177,41 @@ class IpfsUseCases { if (!fileMetadata.dataPinned) { throw new Error(`CID ${cid} has not been pinned by ipfs-file-pin-service instance ${ipfsFileProvider}`) } - console.log('fileMetadata: ', fileMetadata) + // console.log('fileMetadata: ', fileMetadata) // Throw an error if this is not a JSON file const filename = fileMetadata.filename if (!filename.endsWith('.json')) { throw new Error(`CID ${cid} does not resolve to a JSON file.`) } - console.log('ping01') // Retrieve the CID content and store it in a Buffer. const helia = this.adapters.ipfs.ipfs const fileChunks = [] - console.log('ping02') - for await (const chunk of helia.fs.cat(cid)) { - fileChunks.push(chunk) + + // list cid content. This is used to determine if the CID is a file or a directory. + const contentArray = [] + for await (const file of helia.fs.ls(cid)) { + contentArray.push(file) } - console.log('ping03') + // console.log('contentArray: ', contentArray) + + try { + // Handle CIDs that are files. + for await (const chunk of helia.fs.cat(cid)) { + fileChunks.push(chunk) + } + } catch (err) { + // Handle CIDs that are directorys containing a JSON file. (TokenTiger.com tokens) + for await (const chunk of helia.fs.cat(`${cid}/${contentArray[0].name}`)) { + fileChunks.push(chunk) + } + } + const fileBuf = Buffer.concat(fileChunks) - console.log('ping04') + // Convert the Buffer into a string. const jsonStr = fileBuf.toString() - console.log('ping05') + // Parse the string into a JSON object. let json = null try {