Explorar el Código

Add fetch.uploadProgress and fetch.progress overload method #140

Ben Hsieh hace 7 años
padre
commit
389eda8d07

+ 2
- 0
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java Ver fichero

394
                         DownloadManager dm = (DownloadManager)RNFetchBlob.RCTContext.getSystemService(RNFetchBlob.RCTContext.DOWNLOAD_SERVICE);
394
                         DownloadManager dm = (DownloadManager)RNFetchBlob.RCTContext.getSystemService(RNFetchBlob.RCTContext.DOWNLOAD_SERVICE);
395
                         dm.addCompletedDownload(title, desc, scannable, mime, destPath, contentLength, notification);
395
                         dm.addCompletedDownload(title, desc, scannable, mime, destPath, contentLength, notification);
396
                     }
396
                     }
397
+
397
                     done(response);
398
                     done(response);
398
                 }
399
                 }
399
             });
400
             });
488
                 } catch (Exception ignored) {
489
                 } catch (Exception ignored) {
489
                     ignored.printStackTrace();
490
                     ignored.printStackTrace();
490
                 }
491
                 }
492
+                this.destPath = this.destPath.replace("?append=true", "");
491
                 callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
493
                 callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
492
                 break;
494
                 break;
493
             default:
495
             default:

+ 2
- 0
src/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java Ver fichero

43
         this.mPath = path;
43
         this.mPath = path;
44
         if (path != null) {
44
         if (path != null) {
45
             boolean appendToExistingFile = path.contains("?append=true");
45
             boolean appendToExistingFile = path.contains("?append=true");
46
+            path = path.replace("?append=true", "");
47
+            mPath = path;
46
             File f = new File(path);
48
             File f = new File(path);
47
             if(f.exists() == false)
49
             if(f.exists() == false)
48
                 f.createNewFile();
50
                 f.createNewFile();

+ 27
- 2
src/index.js Ver fichero

194
   // extend Promise object, add `progress`, `uploadProgress`, and `cancel`
194
   // extend Promise object, add `progress`, `uploadProgress`, and `cancel`
195
   // method for register progress event handler and cancel request.
195
   // method for register progress event handler and cancel request.
196
   // Add second parameter for performance purpose #140
196
   // Add second parameter for performance purpose #140
197
-  promise.progress = (fn, interval:number=250, count:number=-1) => {
197
+  // When there's only one argument pass to this method, use default `interval`
198
+  // and `count`, otherwise use the given on.
199
+  // TODO : code refactor, move `uploadProgress` and `progress` to StatefulPromise
200
+  promise.progress = (...args) => {
201
+    let interval = 250
202
+    let count = -1
203
+    let fn = () => {}
204
+    if(args.length === 2) {
205
+      interval = args[0].interval
206
+      interval = args[0].count
207
+      fn = args[1]
208
+    }
209
+    else {
210
+      fn = args[0]
211
+    }
198
     promise.onProgress = fn
212
     promise.onProgress = fn
199
     RNFetchBlob.enableProgressReport(taskId, interval, count)
213
     RNFetchBlob.enableProgressReport(taskId, interval, count)
200
     return promise
214
     return promise
201
   }
215
   }
202
-  promise.uploadProgress = (fn, interval:number=250, count:number=-1) => {
216
+  promise.uploadProgress = (...args) => {
217
+    let interval = 250
218
+    let count = -1
219
+    let fn = () => {}
220
+    if(args.length === 2) {
221
+      interval = args[0].interval
222
+      interval = args[0].count
223
+      fn = args[1]
224
+    }
225
+    else {
226
+      fn = args[0]
227
+    }
203
     promise.onUploadProgress = fn
228
     promise.onUploadProgress = fn
204
     RNFetchBlob.enableUploadProgressReport(taskId, interval, count)
229
     RNFetchBlob.enableUploadProgressReport(taskId, interval, count)
205
     return promise
230
     return promise