shogun-relay-sdk 1.2.5 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/ipfs.js +12 -2
- package/package.json +1 -1
package/dist/modules/ipfs.js
CHANGED
|
@@ -66,11 +66,21 @@ class IpfsModule {
|
|
|
66
66
|
* @returns Promise with file content as Buffer
|
|
67
67
|
*/
|
|
68
68
|
async catFromDirectory(directoryCid, filePath) {
|
|
69
|
+
// IPFS API supports paths like CID/path/to/file
|
|
70
|
+
// We need to encode the CID but keep slashes for path navigation
|
|
71
|
+
// Format: /api/v0/cat?arg=QmDirectory/index.html
|
|
69
72
|
const fullPath = `${directoryCid}/${filePath}`;
|
|
70
|
-
|
|
73
|
+
// Encode only the CID part, keep slashes for navigation
|
|
74
|
+
const encodedPath = fullPath.includes('/')
|
|
75
|
+
? `${encodeURIComponent(directoryCid)}/${filePath.split('/').map(p => encodeURIComponent(p)).join('/')}`
|
|
76
|
+
: encodeURIComponent(fullPath);
|
|
77
|
+
// Use GET instead of POST, or send empty string instead of null to avoid JSON parser error
|
|
78
|
+
// IPFS API v0 cat accepts POST with empty body, but Express JSON parser fails on null
|
|
79
|
+
return this.client.post(`/api/v1/ipfs/api/v0/cat?arg=${encodedPath}`, "", // Empty string instead of null to avoid JSON parser error
|
|
80
|
+
{
|
|
71
81
|
responseType: "arraybuffer",
|
|
72
82
|
headers: {
|
|
73
|
-
"Content-
|
|
83
|
+
"Content-Type": "application/octet-stream", // Set content type to avoid JSON parsing
|
|
74
84
|
},
|
|
75
85
|
});
|
|
76
86
|
}
|
package/package.json
CHANGED