From 5008ab3727367c3e852398e5314cdbdf19e4ec68 Mon Sep 17 00:00:00 2001 From: Timur Sufiev Date: Tue, 5 Apr 2022 16:12:45 +0300 Subject: [PATCH] fix: onDownloadProgress should be passed into options --- README.md | 2 ++ src/index.ts | 14 ++------------ src/models/index.ts | 2 +- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6473a8b..9d86f54 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/index.ts b/src/index.ts index 44861d0..f4e06d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -131,18 +131,10 @@ export default class AxiosWrapper { } async request(methodParams: ApiMethodParams): Promise { - 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); @@ -218,14 +210,12 @@ export default class AxiosWrapper { url: string, params: ApiMethodParams['params'], options: ApiMethodParams['options'] = {}, - onDownloadProgress, ) { return this.request({ method: 'GET', url, params, options, - onDownloadProgress, }); } diff --git a/src/models/index.ts b/src/models/index.ts index 9f9895a..7d9b862 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -46,6 +46,6 @@ export interface ApiMethodParams { timeout?: number; headers?: Record; requestConfig?: Record; + onDownloadProgress?: AxiosRequestConfig['onDownloadProgress']; }; - onDownloadProgress?: (progress: ProgressEvent) => void; }