Skip to content

Commit

Permalink
fix: onDownloadProgress should be passed into options
Browse files Browse the repository at this point in the history
  • Loading branch information
tsufiev authored and Raubzeug committed Apr 5, 2022
1 parent f15ae16 commit 5008ab3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Currently 4 request settings are supported:
- `collectRequest (bool)`: optional flag, telling if the request should be logger (default `true`)
- `requestConfig (object)`: optional config with the custom request parameters
- `headers (object)`: optional object with custom request headers.
- `timeout (number)`: optional request timeout
- `onDownloadProgress (function)`: optional callback for processing file download progress

### Headers
The `setDefaultHeader({name (string), value (string), methods (array)})` method allows to add a default
Expand Down
14 changes: 2 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,10 @@ export default class AxiosWrapper {
}

async request<T = any>(methodParams: ApiMethodParams): Promise<T> {
const {
method,
url,
data = null,
params,
options = {},
retries = 0,
onDownloadProgress,
} = methodParams;
const {method, url, data = null, params, options = {}, retries = 0} = methodParams;

const axiosSettings: AxiosRequestConfig = options.requestConfig || {};
const {concurrentId, collectRequest = true, timeout, headers} = options;
const {concurrentId, collectRequest = true, timeout, headers, onDownloadProgress} = options;
if (concurrentId) {
this.cancelRequest(concurrentId);
axiosSettings.cancelToken = this.createRequestToken(concurrentId);
Expand Down Expand Up @@ -218,14 +210,12 @@ export default class AxiosWrapper {
url: string,
params: ApiMethodParams['params'],
options: ApiMethodParams['options'] = {},
onDownloadProgress,
) {
return this.request<T>({
method: 'GET',
url,
params,
options,
onDownloadProgress,
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ export interface ApiMethodParams {
timeout?: number;
headers?: Record<string, unknown>;
requestConfig?: Record<string, unknown>;
onDownloadProgress?: AxiosRequestConfig['onDownloadProgress'];
};
onDownloadProgress?: (progress: ProgressEvent) => void;
}

0 comments on commit 5008ab3

Please sign in to comment.