From 4a6610e49e32355524e2544db2d4b6b7553984b1 Mon Sep 17 00:00:00 2001 From: wenjiarui Date: Wed, 1 Mar 2023 17:18:21 +0800 Subject: [PATCH] formData --- lib/utils/SimpleConnector.js | 41 ++++++++++++++++++------------------ src/utils/SimpleConnector.ts | 22 ++++++++++++------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/lib/utils/SimpleConnector.js b/lib/utils/SimpleConnector.js index 288c480..d11219f 100644 --- a/lib/utils/SimpleConnector.js +++ b/lib/utils/SimpleConnector.js @@ -10,7 +10,7 @@ function makeContentTypeAndBody(data) { if (process.env.OAK_PLATFORM !== 'wechatMp') { if (data instanceof FormData) { return { - contentType: 'multipart/form-data', + // contentType: 'multipart/form-data', body: data, }; } @@ -38,14 +38,15 @@ var SimpleConnector = /** @class */ (function (_super) { cxtStr = context.toString(); _a = makeContentTypeAndBody(params), contentType = _a.contentType, body = _a.body; return [4 /*yield*/, global.fetch(this.serverUrl, { - method: 'POST', - headers: { - 'Content-Type': contentType, - 'oak-cxt': cxtStr, - 'oak-aspect': name, - }, - body: body, - })]; + method: 'POST', + headers: Object.assign({ + 'oak-cxt': cxtStr, + 'oak-aspect': name, + }, contentType ? { + 'Content-Type': contentType + } : {}), + body: body, + })]; case 1: response = _c.sent(); if (response.status > 299) { @@ -62,19 +63,19 @@ var SimpleConnector = /** @class */ (function (_super) { throw this.makeException(exception); } return [2 /*return*/, { - result: result, - opRecords: opRecords, - message: message, - }]; + result: result, + opRecords: opRecords, + message: message, + }]; case 3: if (!(responseType === null || responseType === void 0 ? void 0 : responseType.toLocaleLowerCase().match(/application\/octet-stream/i))) return [3 /*break*/, 5]; return [4 /*yield*/, response.arrayBuffer()]; case 4: result = _c.sent(); return [2 /*return*/, { - result: result, - message: message, - }]; + result: result, + message: message, + }]; case 5: throw new Error("\u5C1A\u4E0D\u652F\u6301\u7684content-type\u7C7B\u578B".concat(responseType)); } }); @@ -97,10 +98,10 @@ var SimpleConnector = /** @class */ (function (_super) { context = _a.sent(); context.setHeaders(headers); return [2 /*return*/, { - name: aspectName, - params: body, - context: context, - }]; + name: aspectName, + params: body, + context: context, + }]; } }); }); diff --git a/src/utils/SimpleConnector.ts b/src/utils/SimpleConnector.ts index e79cac4..50ce22d 100644 --- a/src/utils/SimpleConnector.ts +++ b/src/utils/SimpleConnector.ts @@ -10,7 +10,7 @@ function makeContentTypeAndBody(data: any) { if (process.env.OAK_PLATFORM !== 'wechatMp') { if (data instanceof FormData) { return { - contentType: 'multipart/form-data', + // contentType: 'multipart/form-data', body: data, }; } @@ -41,11 +41,17 @@ export class SimpleConnector 299) { @@ -61,7 +67,7 @@ export class SimpleConnector): Promise<{ name: string; params: any; context: BackCxt; }> { + async parseRequest(headers: IncomingHttpHeaders, body: any, store: AsyncRowStore): Promise<{ name: string; params: any; context: BackCxt; }> { const { 'oak-cxt': oakCxtStr, 'oak-aspect': aspectName } = headers; assert(typeof oakCxtStr === 'string' || oakCxtStr === undefined); assert(typeof aspectName === 'string'); @@ -99,7 +105,7 @@ export class SimpleConnector | undefined; } { if (result instanceof Stream || result instanceof Buffer) { return { @@ -117,7 +123,7 @@ export class SimpleConnector, headers: IncomingHttpHeaders, body: any): { body: any; headers?: Record | undefined; } { + serializeException(exception: OakException, headers: IncomingHttpHeaders, body: any): { body: any; headers?: Record | undefined; } { return { body: { exception: exception.toString(),