@cpzxrobot/sdk 1.3.127 → 1.3.128
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/web_platform.js +8 -1
- package/package.json +1 -1
- package/web_platform.ts +17 -1
package/dist/web_platform.js
CHANGED
|
@@ -84,7 +84,14 @@ class WebPlatform {
|
|
|
84
84
|
headers.set('Miniapp-Code', (_a = this.appCode) !== null && _a !== void 0 ? _a : "");
|
|
85
85
|
headers.set('Accept', 'text/event-stream');
|
|
86
86
|
headers.set('Cache-Control', 'no-cache');
|
|
87
|
-
|
|
87
|
+
// 处理 body 是 object 的情况
|
|
88
|
+
let processedInit = init;
|
|
89
|
+
if ((init === null || init === void 0 ? void 0 : init.body) && typeof init.body === 'object' && !(init.body instanceof FormData) && !(init.body instanceof Blob) && !(init.body instanceof ArrayBuffer)) {
|
|
90
|
+
processedInit = Object.assign(Object.assign({}, init), { body: JSON.stringify(init.body), headers: Object.assign(Object.assign({}, init.headers), { 'Content-Type': 'application/json' }) });
|
|
91
|
+
// 更新 headers 对象
|
|
92
|
+
headers.set('Content-Type', 'application/json');
|
|
93
|
+
}
|
|
94
|
+
const response = yield fetch(this.baseURL + input.toString(), Object.assign(Object.assign({}, processedInit), { headers }));
|
|
88
95
|
var reader = response.body.getReader();
|
|
89
96
|
const decoder = new TextDecoder("utf-8");
|
|
90
97
|
let done = false;
|
package/package.json
CHANGED
package/web_platform.ts
CHANGED
|
@@ -79,8 +79,24 @@ export class WebPlatform implements PlatformInterface {
|
|
|
79
79
|
headers.set('Miniapp-Code', this.appCode ?? "");
|
|
80
80
|
headers.set('Accept', 'text/event-stream');
|
|
81
81
|
headers.set('Cache-Control', 'no-cache');
|
|
82
|
+
|
|
83
|
+
// 处理 body 是 object 的情况
|
|
84
|
+
let processedInit = init;
|
|
85
|
+
if (init?.body && typeof init.body === 'object' && !(init.body instanceof FormData) && !(init.body instanceof Blob) && !(init.body instanceof ArrayBuffer)) {
|
|
86
|
+
processedInit = {
|
|
87
|
+
...init,
|
|
88
|
+
body: JSON.stringify(init.body),
|
|
89
|
+
headers: {
|
|
90
|
+
...init.headers,
|
|
91
|
+
'Content-Type': 'application/json'
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// 更新 headers 对象
|
|
95
|
+
headers.set('Content-Type', 'application/json');
|
|
96
|
+
}
|
|
97
|
+
|
|
82
98
|
const response = await fetch(this.baseURL + input.toString(), {
|
|
83
|
-
...
|
|
99
|
+
...processedInit,
|
|
84
100
|
headers
|
|
85
101
|
});
|
|
86
102
|
|