Skip to content

Commit 4d12bc2

Browse files
authored
Merge pull request #21 from regulaforensics/feature/export-base-request
Add baseRequest as process param
2 parents 7a3c4e6 + 3300f45 commit 4d12bc2

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/ext/document-reader.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Configuration} from "../configuration.js";
66
import globalAxios, {AxiosInstance} from "axios";
77
import {BASE_PATH} from "../base.js";
88
import {ProcessRequestImage as ProcessRequestImageBase} from "../models/index.js";
9-
import {Base64String, ProcessRequest} from "./process-request.js";
9+
import {Base64String, instanceOfProcessRequest, ProcessRequest} from "./process-request.js";
1010
import {ProcessRequestImage} from "./process-request-image.js";
1111

1212
// @ts-ignore
@@ -32,23 +32,29 @@ export class DocumentReaderApi {
3232
* @param {*} [options] Override http request option.
3333
* @throws {RequiredError} If some request params are missed
3434
* */
35-
process(processRequest: ProcessRequest, options?: any): Promise<Response> {
35+
process(request: ProcessRequest | ProcessRequestBase, options?: any): Promise<Response> {
36+
let baseRequest;
37+
38+
if (instanceOfProcessRequest(request)) {
39+
if (!request.processParam) {
40+
request.processParam = {
41+
scenario: Scenario.FULL_PROCESS,
42+
resultTypeOutput: [Result.TEXT]
43+
}
44+
}
45+
if (!request.systemInfo) {
46+
request.systemInfo = {}
47+
}
3648

37-
if (!processRequest.processParam) {
38-
processRequest.processParam = {
39-
scenario: Scenario.FULL_PROCESS,
40-
resultTypeOutput: [Result.TEXT]
49+
if (!request.systemInfo.license && this.license) {
50+
request.systemInfo.license = this.license
4151
}
42-
}
43-
if (!processRequest.systemInfo) {
44-
processRequest.systemInfo = {}
45-
}
4652

47-
if (!processRequest.systemInfo.license && this.license) {
48-
processRequest.systemInfo.license = this.license
53+
baseRequest = requestToBaseRequest(request)
54+
} else {
55+
baseRequest = request
4956
}
5057

51-
const baseRequest = requestToBaseRequest(processRequest)
5258
return this.processApi.apiProcess(baseRequest, options)
5359
.then((axiosResult) => new Response(axiosResult.data));
5460
}

src/ext/process-request.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ export interface ProcessRequest {
2727
systemInfo?: ProcessSystemInfo;
2828
}
2929

30-
30+
export const instanceOfProcessRequest = (data: any): data is ProcessRequest => {
31+
return 'images' in data
32+
}

0 commit comments

Comments
 (0)