Skip to content

Commit cead7f3

Browse files
Merge pull request #64 from ConvertAPI/feature/multiple-file-params
Handle multiple file params
2 parents e334ecd + 8c66651 commit cead7f3

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ jobs:
66
strategy:
77
matrix:
88
node-version:
9+
- 20
910
- 18
1011
- 14
1112
- 10
12-
- 6
1313
name: Node ${{ matrix.node-version }} sample
1414
steps:
1515
- uses: actions/checkout@v3

src/task.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ const Task = class {
3131

3232
async normalizeParams(params) {
3333
const result = Object.assign({}, params, this.defaultParams);
34+
const fileParams = Object.keys(params).filter(key => key.endsWith('File') && key !== 'StoreFile');
3435

35-
if (params.File) {
36-
const file = await params.File;
37-
result.File = await buildFileParam(this.api, file);
38-
}
36+
await Promise.all(fileParams.map(async (key) => {
37+
const file = await params[key];
38+
result[key] = await buildFileParam(this.api, file);
39+
}));
3940

4041
if (params.Files) {
4142
const files = await normalizeFilesParam(params.Files);

test/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ describe('ConvertAPI', () => {
119119
expect(result.file.url).to.be.a('string');
120120
});
121121

122+
it('should compare files', async () => {
123+
const params = {
124+
File: './examples/files/test.docx',
125+
CompareFile: './examples/files/test.docx',
126+
};
127+
128+
const result = await api.convert('compare', params);
129+
130+
expect(result.file.url).to.be.a('string');
131+
});
132+
122133
it('should handle api errors', () => {
123134
const params = { Url: 'https://www.w3.org/TR/PNG/iso_8859-1.txt' };
124135

0 commit comments

Comments
 (0)