From c6e8a88a2e66f10edd7c5e301c565fe996e89929 Mon Sep 17 00:00:00 2001 From: Maxim Belov Date: Sat, 4 Mar 2023 01:02:41 +0200 Subject: [PATCH 1/3] feat(http): add onProgress callback to uploadFile and downloadFile --- .../plugins/http/index.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/@awesome-cordova-plugins/plugins/http/index.ts b/src/@awesome-cordova-plugins/plugins/http/index.ts index dc9bc48004..5d73823f12 100644 --- a/src/@awesome-cordova-plugins/plugins/http/index.ts +++ b/src/@awesome-cordova-plugins/plugins/http/index.ts @@ -1,6 +1,11 @@ import { Injectable } from '@angular/core'; import { Cordova, CordovaProperty, AwesomeCordovaNativePlugin, Plugin } from '@awesome-cordova-plugins/core'; +export interface OnProgress { + isProgress: boolean; + transferred: number; + total: number; +} export interface HTTPResponse { /** * The HTTP status number of the response or a negative internal error code. @@ -523,10 +528,18 @@ export class HTTP extends AwesomeCordovaNativePlugin { * @param headers {Object} The headers to set for this request * @param filePath {string} The local path(s) of the file(s) to upload * @param name {string} The name(s) of the parameter to pass the file(s) along as + * @param onProgress {function} A callback that is called when is progress * @returns {Promise} returns a FileEntry promise that will resolve on success, and reject on failure */ @Cordova() - uploadFile(url: string, body: any, headers: any, filePath: string | string[], name: string | string[]): Promise { + uploadFile( + url: string, + body: any, + headers: any, + filePath: string | string[], + name: string | string[], + onProgress: (response: OnProgress) => void + ): Promise { return; } @@ -537,6 +550,7 @@ export class HTTP extends AwesomeCordovaNativePlugin { * @param headers {Object} The headers to set for this request * @param filePath {string} The local path(s) of the file(s) to upload * @param name {string} The name(s) of the parameter to pass the file(s) along as + * @param onProgress {function} A callback that is called when is progress * @param success {function} A callback that is called when the request succeed * @param failure {function} A callback that is called when the request failed * @returns {string} returns a string that represents the requestId @@ -551,6 +565,7 @@ export class HTTP extends AwesomeCordovaNativePlugin { headers: any, filePath: string | string[], name: string | string[], + onProgress: (response: OnProgress) => void, success: (result: any) => void, failure: (error: any) => void ): string { @@ -563,10 +578,17 @@ export class HTTP extends AwesomeCordovaNativePlugin { * @param body {Object} The body of the request * @param headers {Object} The headers to set for this request * @param filePath {string} The path to download the file to, including the file name. + * @param onProgress {function} A callback that is called when is progress * @returns {Promise} returns a FileEntry promise that will resolve on success, and reject on failure */ @Cordova() - downloadFile(url: string, body: any, headers: any, filePath: string): Promise { + downloadFile( + url: string, + body: any, + headers: any, + filePath: string, + onProgress: (response: OnProgress) => void + ): Promise { return; } @@ -576,6 +598,7 @@ export class HTTP extends AwesomeCordovaNativePlugin { * @param body {Object} The body of the request * @param headers {Object} The headers to set for this request * @param filePath {string} The path to download the file to, including the file name. + * @param onProgress {function} A callback that is called when is progress * @param success {function} A callback that is called when the request succeed * @param failure {function} A callback that is called when the request failed * @returns {string} returns a string that represents the requestId @@ -589,6 +612,7 @@ export class HTTP extends AwesomeCordovaNativePlugin { body: any, headers: any, filePath: string, + onProgress: (response: OnProgress) => void, success: (result: any) => void, failure: (error: any) => void ): string { From 3143b7d058b2082a1edda9234c6ed1698614082c Mon Sep 17 00:00:00 2001 From: Maxim Belov Date: Sat, 6 May 2023 12:20:19 +0300 Subject: [PATCH 2/3] feat(http): add uploadFileWithOptions and downloadFileWithOptions methods --- .../plugins/http/index.ts | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/@awesome-cordova-plugins/plugins/http/index.ts b/src/@awesome-cordova-plugins/plugins/http/index.ts index 5d73823f12..1bb432cad6 100644 --- a/src/@awesome-cordova-plugins/plugins/http/index.ts +++ b/src/@awesome-cordova-plugins/plugins/http/index.ts @@ -528,17 +528,29 @@ export class HTTP extends AwesomeCordovaNativePlugin { * @param headers {Object} The headers to set for this request * @param filePath {string} The local path(s) of the file(s) to upload * @param name {string} The name(s) of the parameter to pass the file(s) along as - * @param onProgress {function} A callback that is called when is progress * @returns {Promise} returns a FileEntry promise that will resolve on success, and reject on failure */ @Cordova() - uploadFile( + uploadFile(url: string, body: any, headers: any, filePath: string | string[], name: string | string[]): Promise { + return; + } + + /** + * + * @param url {string} The url to send the request to + * @param options + * @returns {Promise} returns a FileEntry promise that will resolve on success, and reject on failure + */ + @Cordova() + uploadFileWithOptions( url: string, - body: any, - headers: any, - filePath: string | string[], - name: string | string[], - onProgress: (response: OnProgress) => void + options: { + params: any; + headers: any; + filePath: string | string[]; + name: string | string[]; + onProgress: (response: OnProgress) => void; + } ): Promise { return; } @@ -550,7 +562,6 @@ export class HTTP extends AwesomeCordovaNativePlugin { * @param headers {Object} The headers to set for this request * @param filePath {string} The local path(s) of the file(s) to upload * @param name {string} The name(s) of the parameter to pass the file(s) along as - * @param onProgress {function} A callback that is called when is progress * @param success {function} A callback that is called when the request succeed * @param failure {function} A callback that is called when the request failed * @returns {string} returns a string that represents the requestId @@ -565,7 +576,6 @@ export class HTTP extends AwesomeCordovaNativePlugin { headers: any, filePath: string | string[], name: string | string[], - onProgress: (response: OnProgress) => void, success: (result: any) => void, failure: (error: any) => void ): string { @@ -578,16 +588,28 @@ export class HTTP extends AwesomeCordovaNativePlugin { * @param body {Object} The body of the request * @param headers {Object} The headers to set for this request * @param filePath {string} The path to download the file to, including the file name. - * @param onProgress {function} A callback that is called when is progress * @returns {Promise} returns a FileEntry promise that will resolve on success, and reject on failure */ @Cordova() - downloadFile( + downloadFile(url: string, body: any, headers: any, filePath: string): Promise { + return; + } + + /** + * + * @param url {string} The url to send the request to + * @param options + * @returns {Promise} returns a FileEntry promise that will resolve on success, and reject on failure + */ + @Cordova() + downloadFileWithOptions( url: string, - body: any, - headers: any, - filePath: string, - onProgress: (response: OnProgress) => void + options: { + params: any; + headers: any; + filePath: string; + onProgress: (response: OnProgress) => void; + } ): Promise { return; } @@ -598,7 +620,6 @@ export class HTTP extends AwesomeCordovaNativePlugin { * @param body {Object} The body of the request * @param headers {Object} The headers to set for this request * @param filePath {string} The path to download the file to, including the file name. - * @param onProgress {function} A callback that is called when is progress * @param success {function} A callback that is called when the request succeed * @param failure {function} A callback that is called when the request failed * @returns {string} returns a string that represents the requestId @@ -612,7 +633,6 @@ export class HTTP extends AwesomeCordovaNativePlugin { body: any, headers: any, filePath: string, - onProgress: (response: OnProgress) => void, success: (result: any) => void, failure: (error: any) => void ): string { From 4250d7980b0c22be302cc79cf0782077794ffcf1 Mon Sep 17 00:00:00 2001 From: Maxim Belov Date: Sat, 3 Jun 2023 00:02:57 +0300 Subject: [PATCH 3/3] add onProgress to sendRequest --- .../plugins/http/index.ts | 41 +------------------ 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/src/@awesome-cordova-plugins/plugins/http/index.ts b/src/@awesome-cordova-plugins/plugins/http/index.ts index 1bb432cad6..44930d4f10 100644 --- a/src/@awesome-cordova-plugins/plugins/http/index.ts +++ b/src/@awesome-cordova-plugins/plugins/http/index.ts @@ -535,26 +535,6 @@ export class HTTP extends AwesomeCordovaNativePlugin { return; } - /** - * - * @param url {string} The url to send the request to - * @param options - * @returns {Promise} returns a FileEntry promise that will resolve on success, and reject on failure - */ - @Cordova() - uploadFileWithOptions( - url: string, - options: { - params: any; - headers: any; - filePath: string | string[]; - name: string | string[]; - onProgress: (response: OnProgress) => void; - } - ): Promise { - return; - } - /** * * @param url {string} The url to send the request to @@ -595,25 +575,6 @@ export class HTTP extends AwesomeCordovaNativePlugin { return; } - /** - * - * @param url {string} The url to send the request to - * @param options - * @returns {Promise} returns a FileEntry promise that will resolve on success, and reject on failure - */ - @Cordova() - downloadFileWithOptions( - url: string, - options: { - params: any; - headers: any; - filePath: string; - onProgress: (response: OnProgress) => void; - } - ): Promise { - return; - } - /** * * @param url {string} The url to send the request to @@ -652,6 +613,7 @@ export class HTTP extends AwesomeCordovaNativePlugin { * @param options.filePath {string} file path(s) to be used during upload and download see uploadFile and downloadFile for detailed information * @param options.name {string} name(s) to be used during upload see uploadFile for detailed information * @param options.responseType {string} response type, defaults to text + * @param options.onProgress {function} A callback that is called when is progress * @returns {Promise} returns a promise that will resolve on success, and reject on failure */ @Cordova() @@ -667,6 +629,7 @@ export class HTTP extends AwesomeCordovaNativePlugin { filePath?: string | string[]; name?: string | string[]; responseType?: 'text' | 'arraybuffer' | 'blob' | 'json'; + onProgress?: (response: OnProgress) => void; } ): Promise { return;