Skip to content

Commit f45c01e

Browse files
Fix batch bugs
1 parent 38fcec9 commit f45c01e

File tree

8 files changed

+486
-715
lines changed

8 files changed

+486
-715
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Feel free to explore the [Developer's Guide](https://docs.aspose.cloud/display/w
1919
## Enhancements in Version 21.5
2020

2121
- Update dependencies in sdk
22-
22+
- Added resultOf feature support for batch requests
2323

2424
## Enhancements in Version 21.4
2525

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import * as model from "./model/model";
3737
import { BatchPartRequest } from "./model/batchPartRequest";
3838

3939
export * from "./model/model";
40+
export * from "./model/batchPartRequest";
4041

4142
/**
4243
* Library for communicating with the Aspose.Words for Cloud API
@@ -5288,7 +5289,7 @@ export class WordsApi {
52885289
method: "PUT",
52895290
uri: this.configuration.getApiBaseUrl() + "/words/batch",
52905291
headers: {
5291-
"Content-Type": "multipart/form-data",
5292+
"Content-Type": "multipart/mixed",
52925293
},
52935294
};
52945295

@@ -5373,8 +5374,7 @@ export class WordsApi {
53735374
}
53745375
}
53755376

5376-
let contentType = requestForm.getHeaders()["content-type"].replace("multipart/form-data", "multipart/mixed");
5377-
bodyString += "Content-Type: " + contentType + "\r\n";
5377+
bodyString += "Content-Type: " + requestForm.getHeaders()["content-type"] + "\r\n";
53785378

53795379
bodyString += "RequestId: " + requestObj.id + "\r\n";
53805380
if (requestObj.parentId) {
@@ -5394,11 +5394,12 @@ export class WordsApi {
53945394
}
53955395

53965396
requestOptions.multipart = requestParts;
5397+
requestOptions.encoding = null;
53975398

53985399
const response = await invokeApiMethod(requestOptions, this.configuration);
53995400

54005401
// parse the response
5401-
const responseParts = parseMultipartBody(Buffer.from(response.body), getBoundary(response.headers));
5402+
const responseParts = parseMultipartBody(response.body, getBoundary(response.headers), true);
54025403

54035404
const data = new Array();
54045405
for (let i = 0; i < requests.length; i++) {

src/internal/requestHelper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async function invokeApiMethodInternal(requestOptions: request.OptionsWithUri, c
172172
/**
173173
* Parse multipart response body for given boundary
174174
*/
175-
export function parseMultipartBody(multipartBodyBuffer, boundary) {
175+
export function parseMultipartBody(multipartBodyBuffer, boundary, withStatus) {
176176
const allParts = [];
177177

178178
let partHeaders = [];
@@ -206,7 +206,7 @@ export function parseMultipartBody(multipartBodyBuffer, boundary) {
206206
} else
207207
if((PART_HEADERS === state) && newLineDetected){
208208
if(lastline === '') {
209-
state = STATUS;
209+
state = withStatus ? STATUS : CONTENT;
210210
}
211211
lastline = '';
212212
} else
@@ -227,7 +227,7 @@ export function parseMultipartBody(multipartBodyBuffer, boundary) {
227227
if(lastline.length > (boundary.length+4)) lastline='';
228228
if(((("--" + boundary) === lastline))){
229229
const part = {
230-
code: parseInt(info, 10),
230+
code: withStatus ? parseInt(info, 10) : 0,
231231
headers: partHeaders.reduce((headers, header) => {
232232
if (header.indexOf(':') !== -1) {
233233
const [ key, value ] = header.split(/:\s+/)

src/model/batchPartRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class BatchPartRequest {
7373
/**
7474
* create response from string
7575
*/
76-
createResponse(response: string, _boundary?: string): any {
76+
createResponse(response: Buffer, _boundary?: string): any {
7777
if (_boundary == null) {
7878
return this.innerRequest.createResponse(response);
7979
}

0 commit comments

Comments
 (0)