formData
This commit is contained in:
parent
42fca4aa3f
commit
4a6610e49e
|
|
@ -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,
|
||||
}];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict, BackCxt extends AsyncContext
|
|||
const { contentType, body } = makeContentTypeAndBody(params);
|
||||
const response = await global.fetch(this.serverUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': contentType,
|
||||
headers: contentType ? {
|
||||
'oak-cxt': cxtStr,
|
||||
'oak-aspect': name as string,
|
||||
},
|
||||
} : Object.assign(
|
||||
{
|
||||
'oak-cxt': cxtStr,
|
||||
'oak-aspect': name as string,
|
||||
}, {
|
||||
contentType: contentType as string
|
||||
}
|
||||
),
|
||||
body,
|
||||
});
|
||||
if (response.status > 299) {
|
||||
|
|
@ -61,7 +67,7 @@ export class SimpleConnector<ED extends EntityDict, BackCxt extends AsyncContext
|
|||
result,
|
||||
opRecords,
|
||||
} = await response.json();
|
||||
|
||||
|
||||
if (exception) {
|
||||
throw this.makeException(exception);
|
||||
}
|
||||
|
|
@ -87,7 +93,7 @@ export class SimpleConnector<ED extends EntityDict, BackCxt extends AsyncContext
|
|||
return SimpleConnector.ROUTER;
|
||||
}
|
||||
|
||||
async parseRequest(headers: IncomingHttpHeaders, body: any, store: AsyncRowStore<ED, BackCxt>): Promise<{ name: string; params: any; context: BackCxt; }> {
|
||||
async parseRequest(headers: IncomingHttpHeaders, body: any, store: AsyncRowStore<ED, BackCxt>): 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<ED extends EntityDict, BackCxt extends AsyncContext
|
|||
context,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
serializeResult(result: any, context: BackCxt, headers: IncomingHttpHeaders, body: any): { body: any; headers?: Record<string, any> | undefined; } {
|
||||
if (result instanceof Stream || result instanceof Buffer) {
|
||||
return {
|
||||
|
|
@ -117,7 +123,7 @@ export class SimpleConnector<ED extends EntityDict, BackCxt extends AsyncContext
|
|||
};
|
||||
}
|
||||
|
||||
serializeException(exception: OakException<ED>, headers: IncomingHttpHeaders, body: any): { body: any; headers?: Record<string, any> | undefined; } {
|
||||
serializeException(exception: OakException<ED>, headers: IncomingHttpHeaders, body: any): { body: any; headers?: Record<string, any> | undefined; } {
|
||||
return {
|
||||
body: {
|
||||
exception: exception.toString(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue