Browse Source

merge 0.9.7

Ben Hsieh 8 years ago
parent
commit
a1b9dccf33

+ 2
- 0
src/index.js View File

@@ -241,6 +241,8 @@ function fetch(...args:any):Promise {
241 241
       console.log(e , 'EXPIRED!!')
242 242
       if(e.taskId === taskId && promise.onExpire) {
243 243
         promise.onExpire(e)
244
+      }
245
+    })
244 246
 
245 247
     partEvent = emitter.addListener('RNFetchBlobServerPush', (e) => {
246 248
       if(e.taskId === taskId && promise.onPartData) {

+ 2
- 2
src/ios.js View File

@@ -20,7 +20,7 @@ const RNFetchBlob:RNFetchBlobNative = NativeModules.RNFetchBlob
20 20
  */
21 21
 function openDocument(path:string, scheme:string) {
22 22
   if(Platform.OS === 'ios')
23
-    return RNFetchBlob.openDocument(path, scheme)
23
+    return RNFetchBlob.openDocument('file://' + path, scheme)
24 24
   else
25 25
     return Promise.reject('RNFetchBlob.openDocument only supports IOS.')
26 26
 }
@@ -33,7 +33,7 @@ function openDocument(path:string, scheme:string) {
33 33
  */
34 34
 function previewDocument(path:string, scheme:string) {
35 35
   if(Platform.OS === 'ios')
36
-    return RNFetchBlob.previewDocument(path, scheme)
36
+    return RNFetchBlob.previewDocument('file://' + path, scheme)
37 37
   else
38 38
     return Promise.reject('RNFetchBlob.previewDocument only supports IOS.')
39 39
 }

+ 2
- 0
src/ios/RNFetchBlobNetwork.m View File

@@ -42,6 +42,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
42 42
 {
43 43
     BOOL * respFile;
44 44
     BOOL isNewPart;
45
+    BOOL * isIncrement;
45 46
     NSMutableData * partBuffer;
46 47
     NSString * destPath;
47 48
     NSOutputStream * writeStream;
@@ -562,6 +563,7 @@ NSOperationQueue *taskQueue;
562 563
     }
563 564
 }
564 565
 
566
+
565 567
 - (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
566 568
 {
567 569
     NSLog(@"sess done in background");

+ 3
- 0
test-server/public/json-dummy-1.json View File

@@ -0,0 +1,3 @@
1
+{
2
+  "name" : "fetchblob-dev"
3
+}

+ 17
- 0
test-server/server.js View File

@@ -66,6 +66,23 @@ app.use(function(req, res, next) {
66 66
   next();
67 67
 })
68 68
 
69
+
70
+app.get('/10s-download', (req,res) => {
71
+  var count = 0
72
+  var data = ''
73
+  for(var i =0;i<1024000;i++)
74
+    data += '1'
75
+  res.set('Contet-Length', 1024000*10)
76
+  var it = setInterval(() => {
77
+    res.write(data)
78
+    count++
79
+    if(count == 10) {
80
+      clearInterval(it)
81
+      res.end()
82
+    }
83
+  }, 1000)
84
+})
85
+
69 86
 app.get('/video/:count', (req, res) => {
70 87
   var count = 0
71 88
   res.set('Content-Type', 'multipart/x-mixed-replace; boundary="---osclivepreview---"')

+ 1
- 0
test-server/test.jpeg View File

@@ -0,0 +1 @@
1
+undefined

+ 1
- 1
test/test-0.10.0.js View File

@@ -78,7 +78,7 @@ describe('issue #102', (report, done) => {
78 78
     .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
79 79
     .then((res) => {
80 80
       tmp = res
81
-      RNFetchBlob.ios.previewDocument('file://' + res.path(), 'itms-books:')
81
+      RNFetchBlob.ios.previewDocument(res.path())
82 82
       return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {},
83 83
       [{ name : String(1), data : RNFetchBlob.wrap(res.path()), filename: '#102-test-image.png' }])
84 84
     })

+ 3
- 1
test/test-0.6.2.js View File

@@ -62,6 +62,7 @@ describe('upload asset from camera roll', (report, done) => {
62 62
 
63 63
 describe('Upload multipart data with file from CameraRoll', (report, done) => {
64 64
     let filename = 'test-from-storage-img-'+Date.now()+'.png'
65
+    console.log(photo)
65 66
     RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
66 67
         'Content-Type' : 'multipart/form-data',
67 68
       }, [
@@ -165,10 +166,11 @@ describe('upload file from assets',(report, done) => {
165 166
   let assetName = fs.asset('test-asset1.json')
166 167
   RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
167 168
     Authorization : `Bearer ${DROPBOX_TOKEN}`,
168
-    'Dropbox-API-Arg': `{\"path\": \"/rn-upload/file-from-asset-${Platform.OS}.json\",\"mode\": \"add\",\"autorename\": false,\"mute\": false}`,
169
+    'Dropbox-API-Arg': `{\"path\": \"/rn-upload/file-from-asset-${Platform.OS}.json\",\"mode\": \"overwrite\",\"autorename\": false,\"mute\": false}`,
169 170
     'Content-Type' : 'application/octet-stream',
170 171
   }, RNFetchBlob.wrap(assetName))
171 172
   .then((resp) => {
173
+    console.log(resp)
172 174
     resp = resp.json()
173 175
     report(
174 176
       <Assert key="file name check"

+ 8
- 2
test/test-0.9.4.js View File

@@ -14,6 +14,10 @@ import {
14 14
 
15 15
 window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
16 16
 window.Blob = RNFetchBlob.polyfill.Blob
17
+window.fetch = new RNFetchBlob.polyfill.Fetch({
18
+  auto : true,
19
+  binaryContentTypes : ['image/', 'video/', 'audio/']
20
+}).build()
17 21
 
18 22
 const fs = RNFetchBlob.fs
19 23
 const { Assert, Comparer, Info, prop } = RNTest
@@ -56,7 +60,7 @@ describe('issue #106', (report, done) => {
56 60
       return res.json()
57 61
     })
58 62
     .then((data) => {
59
-      // console.log(data)
63
+      console.log(data)
60 64
       report(<Assert key="fetch request success" expect={20000} actual={data.total}/>)
61 65
       done()
62 66
     })
@@ -64,7 +68,9 @@ describe('issue #106', (report, done) => {
64 68
 })
65 69
 
66 70
 describe('issue #111 get redirect destination', (report, done) => {
67
-  RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
71
+  RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`, {
72
+    'Cache-Control' : 'no-store'
73
+  })
68 74
   .then((res) => {
69 75
     console.log(res.info())
70 76
     report(

+ 3
- 3
test/test-0.9.5.js View File

@@ -30,7 +30,7 @@ let prefix = ((Platform.OS === 'android') ? 'file://' : '')
30 30
 
31 31
 describe('issue #122 force response data format', (report, done) => {
32 32
 
33
-  RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/json-dummy.json`, {
33
+  RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/json-dummy-1.json`, {
34 34
     'RNFB-Response' : 'base64'
35 35
   })
36 36
   .then((res) => {
@@ -38,7 +38,7 @@ describe('issue #122 force response data format', (report, done) => {
38 38
     report(
39 39
       <Assert key="test data verify" expect="fetchblob-dev" actual={JSON.parse(r).name}/>,
40 40
       <Assert key="should successfully decode the data" expect={true} actual={true}/>)
41
-    return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/json-dummy.json`)
41
+    return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/json-dummy-1.json`)
42 42
   })
43 43
   .then((res) => {
44 44
     report(
@@ -79,7 +79,7 @@ describe('#129 memory leaking when enable uploadProgress', (report, done) => {
79 79
 
80 80
 })
81 81
 
82
-false && describe('#131 status code != 200 should not throw an error', (report, done) => {
82
+describe('#131 status code != 200 should not throw an error', (report, done) => {
83 83
 
84 84
   let count = 0
85 85
   let codes = [404, 500, 501, 403]

+ 40
- 40
test/test-android.js View File

@@ -148,52 +148,52 @@ const dirs = RNFetchBlob.fs.dirs
148 148
 //   })
149 149
 // })
150 150
 //
151
-// #75
152
-describe('APK downloaded from Download Manager should correct', (report, done) => {
153
-
154
-  let url  = null
151
+// // #75
152
+// describe('APK downloaded from Download Manager should correct', (report, done) => {
153
+//
154
+//   let url  = null
155
+//
156
+//   RNFetchBlob.config({
157
+//     addAndroidDownloads : {
158
+//       useDownloadManager : true,
159
+//       title : 'test-APK',
160
+//       description : 'apk install file',
161
+//       mime : 'application/vnd.android.package-archive',
162
+//       mediaScannable : true,
163
+//       notification : true,
164
+//     }
165
+//   })
166
+//   .fetch('GET', `${TEST_SERVER_URL}/public/apk-dummy.apk`)
167
+//   .then((res) => {
168
+//     let sendIntent = RNFetchBlob.android.actionViewIntent
169
+//     return sendIntent(res.path(), 'application/vnd.android.package-archive')
170
+//   })
171
+//   .then(() => {
172
+//     done()
173
+//   })
174
+//
175
+// })
155 176
 
177
+// issue #74
178
+describe('download file to specific location using DownloadManager', (report, done) => {
179
+  let dest = dirs.DCIMDir + '/android-download-test-' +Date.now() + '.png'
156 180
   RNFetchBlob.config({
157 181
     addAndroidDownloads : {
158 182
       useDownloadManager : true,
159
-      title : 'test-APK',
160
-      description : 'apk install file',
161
-      mime : 'application/vnd.android.package-archive',
162
-      mediaScannable : true,
163
-      notification : true,
183
+      path : dest,
184
+      mime : 'image/png',
185
+      title : 'android-download-path-test.png',
186
+      description : 'download to specific path #74'
164 187
     }
165 188
   })
166
-  .fetch('GET', `${TEST_SERVER_URL}/public/apk-dummy.apk`)
167
-  .then((res) => {
168
-    let sendIntent = RNFetchBlob.android.actionViewIntent
169
-    return sendIntent(res.path(), 'application/vnd.android.package-archive')
170
-  })
171
-  .then(() => {
189
+  .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
190
+  .then((res) => fs.stat(res.path()))
191
+  .then((stat) => {
192
+    report(
193
+      <Assert key="file exists at the path"
194
+        expect={true} actual={true}/>,
195
+      <Assert key="file size correct"
196
+        expect="23975" actual={stat.size}/>)
172 197
     done()
173 198
   })
174
-
175 199
 })
176
-
177
-// issue #74
178
-// describe('download file to specific location using DownloadManager', (report, done) => {
179
-//   let dest = dirs.DCIMDir + '/android-download-test-' +Date.now() + '.png'
180
-//   RNFetchBlob.config({
181
-//     addAndroidDownloads : {
182
-//       useDownloadManager : true,
183
-//       path : dest,
184
-//       mime : 'image/png',
185
-//       title : 'android-download-path-test.png',
186
-//       description : 'download to specific path #74'
187
-//     }
188
-//   })
189
-//   .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
190
-//   .then((res) => fs.stat(res.path()))
191
-//   .then((stat) => {
192
-//     report(
193
-//       <Assert key="file exists at the path"
194
-//         expect={true} actual={true}/>,
195
-//       <Assert key="file size correct"
196
-//         expect="23975" actual={stat.size}/>)
197
-//     done()
198
-//   })
199
-// })

+ 9
- 7
test/test-init.js View File

@@ -17,11 +17,11 @@ const { Assert, Comparer, Info, prop } = RNTest
17 17
 
18 18
 // test environment variables
19 19
 
20
-prop('FILENAME', `${Platform.OS}-0.8.0-${Date.now()}.png`)
21
-prop('TEST_SERVER_URL', 'http://localhost:8123')
22
-prop('TEST_SERVER_URL_SSL', 'https://localhost:8124')
23
-// prop('TEST_SERVER_URL', 'http://192.168.17.194:8123')
24
-// prop('TEST_SERVER_URL_SSL', 'https://192.168.17.194:8124')
20
+prop('FILENAME', `${Platform.OS}-0.10.0-${Date.now()}.png`)
21
+// prop('TEST_SERVER_URL', 'http://localhost:8123')
22
+// prop('TEST_SERVER_URL_SSL', 'https://localhost:8124')
23
+prop('TEST_SERVER_URL', 'http://192.168.17.203:8123')
24
+prop('TEST_SERVER_URL_SSL', 'https://192.168.17.203:8124')
25 25
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
26 26
 prop('styles', {
27 27
   image : {
@@ -73,12 +73,14 @@ describe('GET image from server', (report, done) => {
73 73
 // require('./test-0.9.4')
74 74
 // require('./test-0.9.5')
75 75
 // require('./test-0.9.6')
76
-require('./test-stream')
76
+// require('./test-0.10.0')
77
+// require('./test-background.js')
78
+// require('./test-stream')
77 79
 // require('./test-fetch')
78 80
 // require('./test-fs')
79 81
 // require('./test-xmlhttp')
80 82
 // require('./test-blob')
81 83
 // require('./test-firebase')
82
-// require('./test-android')
84
+require('./test-android')
83 85
 // require('./test-stress')
84 86
 // require('./benchmark')