Ben Hsieh před 7 roky
rodič
revize
a1b9dccf33

+ 2
- 0
src/index.js Zobrazit soubor

241
       console.log(e , 'EXPIRED!!')
241
       console.log(e , 'EXPIRED!!')
242
       if(e.taskId === taskId && promise.onExpire) {
242
       if(e.taskId === taskId && promise.onExpire) {
243
         promise.onExpire(e)
243
         promise.onExpire(e)
244
+      }
245
+    })
244
 
246
 
245
     partEvent = emitter.addListener('RNFetchBlobServerPush', (e) => {
247
     partEvent = emitter.addListener('RNFetchBlobServerPush', (e) => {
246
       if(e.taskId === taskId && promise.onPartData) {
248
       if(e.taskId === taskId && promise.onPartData) {

+ 2
- 2
src/ios.js Zobrazit soubor

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

+ 2
- 0
src/ios/RNFetchBlobNetwork.m Zobrazit soubor

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

+ 3
- 0
test-server/public/json-dummy-1.json Zobrazit soubor

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

+ 17
- 0
test-server/server.js Zobrazit soubor

66
   next();
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
 app.get('/video/:count', (req, res) => {
86
 app.get('/video/:count', (req, res) => {
70
   var count = 0
87
   var count = 0
71
   res.set('Content-Type', 'multipart/x-mixed-replace; boundary="---osclivepreview---"')
88
   res.set('Content-Type', 'multipart/x-mixed-replace; boundary="---osclivepreview---"')

+ 1
- 0
test-server/test.jpeg Zobrazit soubor

1
+undefined

+ 1
- 1
test/test-0.10.0.js Zobrazit soubor

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

+ 3
- 1
test/test-0.6.2.js Zobrazit soubor

62
 
62
 
63
 describe('Upload multipart data with file from CameraRoll', (report, done) => {
63
 describe('Upload multipart data with file from CameraRoll', (report, done) => {
64
     let filename = 'test-from-storage-img-'+Date.now()+'.png'
64
     let filename = 'test-from-storage-img-'+Date.now()+'.png'
65
+    console.log(photo)
65
     RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
66
     RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
66
         'Content-Type' : 'multipart/form-data',
67
         'Content-Type' : 'multipart/form-data',
67
       }, [
68
       }, [
165
   let assetName = fs.asset('test-asset1.json')
166
   let assetName = fs.asset('test-asset1.json')
166
   RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
167
   RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
167
     Authorization : `Bearer ${DROPBOX_TOKEN}`,
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
     'Content-Type' : 'application/octet-stream',
170
     'Content-Type' : 'application/octet-stream',
170
   }, RNFetchBlob.wrap(assetName))
171
   }, RNFetchBlob.wrap(assetName))
171
   .then((resp) => {
172
   .then((resp) => {
173
+    console.log(resp)
172
     resp = resp.json()
174
     resp = resp.json()
173
     report(
175
     report(
174
       <Assert key="file name check"
176
       <Assert key="file name check"

+ 8
- 2
test/test-0.9.4.js Zobrazit soubor

14
 
14
 
15
 window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
15
 window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
16
 window.Blob = RNFetchBlob.polyfill.Blob
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
 const fs = RNFetchBlob.fs
22
 const fs = RNFetchBlob.fs
19
 const { Assert, Comparer, Info, prop } = RNTest
23
 const { Assert, Comparer, Info, prop } = RNTest
56
       return res.json()
60
       return res.json()
57
     })
61
     })
58
     .then((data) => {
62
     .then((data) => {
59
-      // console.log(data)
63
+      console.log(data)
60
       report(<Assert key="fetch request success" expect={20000} actual={data.total}/>)
64
       report(<Assert key="fetch request success" expect={20000} actual={data.total}/>)
61
       done()
65
       done()
62
     })
66
     })
64
 })
68
 })
65
 
69
 
66
 describe('issue #111 get redirect destination', (report, done) => {
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
   .then((res) => {
74
   .then((res) => {
69
     console.log(res.info())
75
     console.log(res.info())
70
     report(
76
     report(

+ 3
- 3
test/test-0.9.5.js Zobrazit soubor

30
 
30
 
31
 describe('issue #122 force response data format', (report, done) => {
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
     'RNFB-Response' : 'base64'
34
     'RNFB-Response' : 'base64'
35
   })
35
   })
36
   .then((res) => {
36
   .then((res) => {
38
     report(
38
     report(
39
       <Assert key="test data verify" expect="fetchblob-dev" actual={JSON.parse(r).name}/>,
39
       <Assert key="test data verify" expect="fetchblob-dev" actual={JSON.parse(r).name}/>,
40
       <Assert key="should successfully decode the data" expect={true} actual={true}/>)
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
   .then((res) => {
43
   .then((res) => {
44
     report(
44
     report(
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
   let count = 0
84
   let count = 0
85
   let codes = [404, 500, 501, 403]
85
   let codes = [404, 500, 501, 403]

+ 40
- 40
test/test-android.js Zobrazit soubor

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
   RNFetchBlob.config({
180
   RNFetchBlob.config({
157
     addAndroidDownloads : {
181
     addAndroidDownloads : {
158
       useDownloadManager : true,
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
     done()
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 Zobrazit soubor

17
 
17
 
18
 // test environment variables
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
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
25
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
26
 prop('styles', {
26
 prop('styles', {
27
   image : {
27
   image : {
73
 // require('./test-0.9.4')
73
 // require('./test-0.9.4')
74
 // require('./test-0.9.5')
74
 // require('./test-0.9.5')
75
 // require('./test-0.9.6')
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
 // require('./test-fetch')
79
 // require('./test-fetch')
78
 // require('./test-fs')
80
 // require('./test-fs')
79
 // require('./test-xmlhttp')
81
 // require('./test-xmlhttp')
80
 // require('./test-blob')
82
 // require('./test-blob')
81
 // require('./test-firebase')
83
 // require('./test-firebase')
82
-// require('./test-android')
84
+require('./test-android')
83
 // require('./test-stress')
85
 // require('./test-stress')
84
 // require('./benchmark')
86
 // require('./benchmark')