shogun-relay-sdk 1.2.9 → 1.2.10
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/client.js +4 -0
- package/dist/modules/ipfs.js +28 -4
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -20,6 +20,10 @@ class ApiClient {
|
|
|
20
20
|
if (this.config.token) {
|
|
21
21
|
req.headers["Authorization"] = `Bearer ${this.config.token}`;
|
|
22
22
|
}
|
|
23
|
+
// If data is FormData, remove Content-Type header to let browser set it with boundary
|
|
24
|
+
if (req.data instanceof FormData) {
|
|
25
|
+
delete req.headers["Content-Type"];
|
|
26
|
+
}
|
|
23
27
|
return req;
|
|
24
28
|
});
|
|
25
29
|
}
|
package/dist/modules/ipfs.js
CHANGED
|
@@ -71,8 +71,11 @@ class IpfsModule {
|
|
|
71
71
|
// Format: /api/v0/cat?arg=QmDirectory/index.html
|
|
72
72
|
const fullPath = `${directoryCid}/${filePath}`;
|
|
73
73
|
// Encode only the CID part, keep slashes for navigation
|
|
74
|
-
const encodedPath = fullPath.includes(
|
|
75
|
-
? `${encodeURIComponent(directoryCid)}/${filePath
|
|
74
|
+
const encodedPath = fullPath.includes("/")
|
|
75
|
+
? `${encodeURIComponent(directoryCid)}/${filePath
|
|
76
|
+
.split("/")
|
|
77
|
+
.map((p) => encodeURIComponent(p))
|
|
78
|
+
.join("/")}`
|
|
76
79
|
: encodeURIComponent(fullPath);
|
|
77
80
|
// Use GET instead of POST, or send empty string instead of null to avoid JSON parser error
|
|
78
81
|
// IPFS API v0 cat accepts POST with empty body, but Express JSON parser fails on null
|
|
@@ -131,8 +134,17 @@ class IpfsModule {
|
|
|
131
134
|
if (userAddress) {
|
|
132
135
|
headers["x-user-address"] = userAddress;
|
|
133
136
|
}
|
|
137
|
+
// Explicitly don't set Content-Type - let browser set it with boundary for FormData
|
|
134
138
|
return this.client.post("/api/v1/ipfs/upload", formData, {
|
|
135
139
|
headers: headers,
|
|
140
|
+
// Ensure axios doesn't serialize FormData as JSON
|
|
141
|
+
transformRequest: [(data) => {
|
|
142
|
+
// If it's FormData, return as-is (axios will handle it)
|
|
143
|
+
if (data instanceof form_data_1.default) {
|
|
144
|
+
return data;
|
|
145
|
+
}
|
|
146
|
+
return data;
|
|
147
|
+
}],
|
|
136
148
|
});
|
|
137
149
|
}
|
|
138
150
|
/**
|
|
@@ -158,8 +170,17 @@ class IpfsModule {
|
|
|
158
170
|
if (userAddress) {
|
|
159
171
|
headers["x-user-address"] = userAddress;
|
|
160
172
|
}
|
|
173
|
+
// Explicitly don't set Content-Type - let browser set it with boundary for FormData
|
|
161
174
|
return this.client.post("/api/v1/ipfs/upload-directory", formData, {
|
|
162
175
|
headers: headers,
|
|
176
|
+
// Ensure axios doesn't serialize FormData as JSON
|
|
177
|
+
transformRequest: [(data) => {
|
|
178
|
+
// If it's FormData, return as-is (axios will handle it)
|
|
179
|
+
if (data instanceof form_data_1.default) {
|
|
180
|
+
return data;
|
|
181
|
+
}
|
|
182
|
+
return data;
|
|
183
|
+
}],
|
|
163
184
|
});
|
|
164
185
|
}
|
|
165
186
|
/**
|
|
@@ -180,8 +201,11 @@ class IpfsModule {
|
|
|
180
201
|
*/
|
|
181
202
|
async catFromDirectoryBlob(directoryCid, filePath) {
|
|
182
203
|
const fullPath = `${directoryCid}/${filePath}`;
|
|
183
|
-
const encodedPath = fullPath.includes(
|
|
184
|
-
? `${encodeURIComponent(directoryCid)}/${filePath
|
|
204
|
+
const encodedPath = fullPath.includes("/")
|
|
205
|
+
? `${encodeURIComponent(directoryCid)}/${filePath
|
|
206
|
+
.split("/")
|
|
207
|
+
.map((p) => encodeURIComponent(p))
|
|
208
|
+
.join("/")}`
|
|
185
209
|
: encodeURIComponent(fullPath);
|
|
186
210
|
return this.client.post(`/api/v1/ipfs/api/v0/cat?arg=${encodedPath}`, "", {
|
|
187
211
|
responseType: "blob",
|
package/package.json
CHANGED