Explorar el Código

Merge branch '0.6.3' into 0.7.0

Ben Hsieh hace 8 años
padre
commit
03d6e4d4b3
Se han modificado 8 ficheros con 205 adiciones y 136 borrados
  1. 1
    1
      package.json
  2. 10
    14
      src/ios/RNFetchBlobNetwork.m
  3. 1
    1
      src/package.json
  4. 2
    1
      test-server/server.js
  5. 4
    1
      test/test-0.5.1.js
  6. 118
    118
      test/test-0.6.2.js
  7. 68
    0
      test/test-0.6.3.js
  8. 1
    0
      test/test-init.js

+ 1
- 1
package.json Ver fichero

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "fetchblob",
3
-  "version": "0.6.2",
3
+  "version": "0.6.3",
4 4
   "private": true,
5 5
   "scripts": {
6 6
     "start": "node node_modules/react-native/local-cli/cli.js start",

+ 10
- 14
src/ios/RNFetchBlobNetwork.m Ver fichero

@@ -92,7 +92,7 @@ NSOperationQueue *taskQueue;
92 92
     
93 93
     // the session trust any SSL certification
94 94
 
95
-    NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:taskId];
95
+    NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
96 96
     session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:[NSOperationQueue mainQueue]];
97 97
     
98 98
     if(path != nil || [self.options valueForKey:CONFIG_USE_TEMP]!= nil)
@@ -168,25 +168,21 @@ NSOperationQueue *taskQueue;
168 168
             }
169 169
      ];
170 170
     
171
-    if(receivedBytes >= expectedBytes)
172
-    {
173
-        if(respFile == YES)
174
-        {
175
-            [writeStream close];
176
-            callback(@[[NSNull null], destPath]);
177
-        }
178
-        // base64 response
179
-        else {
180
-            callback(@[[NSNull null], [respData base64EncodedStringWithOptions:0]]);
181
-        }
182
-        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
183
-    }
184 171
 }
185 172
 
186 173
 - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
187 174
     NSLog([error localizedDescription]);
188 175
     self.error = error;
189 176
     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
177
+    if(respFile == YES)
178
+    {
179
+        [writeStream close];
180
+        callback(@[error == nil ? [NSNull null] : [error localizedDescription], destPath]);
181
+    }
182
+    // base64 response
183
+    else {
184
+        callback(@[error == nil ? [NSNull null] : [error localizedDescription], [respData base64EncodedStringWithOptions:0]]);
185
+    }
190 186
 }
191 187
 
192 188
 // upload progress handler

+ 1
- 1
src/package.json Ver fichero

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "react-native-fetch-blob",
3
-  "version": "0.6.2",
3
+  "version": "0.6.3-dev.1",
4 4
   "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
5 5
   "main": "index.js",
6 6
   "scripts": {

+ 2
- 1
test-server/server.js Ver fichero

@@ -40,9 +40,10 @@ app.listen(8123, function(err){
40 40
     console.log('test server running at port ',8123)
41 41
 })
42 42
 
43
+var count = 0
43 44
 
44 45
 app.use(function(req,res,next){
45
-  console.log(chalk.green('request url=') + chalk.magenta(req.url))
46
+  console.log(chalk.green('request url=') + chalk.magenta(req.url), ++count)
46 47
   next()
47 48
 })
48 49
 

+ 4
- 1
test/test-0.5.1.js Ver fichero

@@ -212,13 +212,14 @@ RNTest.config({
212 212
     </Info>)
213 213
   })
214 214
   .then((res) => {
215
+    try {
215 216
     deb = Date.now()
216 217
     let promise =  RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
217 218
       Authorization : `Bearer ${DROPBOX_TOKEN}`,
218 219
       'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
219 220
       'Content-Type' : 'application/octet-stream',
220 221
     }, RNFetchBlob.wrap(res.path()))
221
-    if(Platform.OS === 'ios')
222
+    if(Platform.OS === 'ios') {
222 223
       promise.progress((now, total) => {
223 224
         if(Date.now() - deb < 1000)
224 225
           return
@@ -233,7 +234,9 @@ RNTest.config({
233 234
           </Text>
234 235
         </Info>)
235 236
       })
237
+    }
236 238
     return promise
239
+  } catch(err) { console.log(err) }
237 240
   })
238 241
   .then((res) => {
239 242
     report(<Assert

+ 118
- 118
test/test-0.6.2.js Ver fichero

@@ -55,124 +55,124 @@ describe('upload asset from camera roll', (report, done) => {
55 55
       done()
56 56
     })
57 57
 })
58
-//
59
-// describe('Upload multipart data with file from CameraRoll', (report, done) => {
60
-//     let filename = 'test-from-storage-img-'+Date.now()+'.png'
61
-//     RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
62
-//         'Content-Type' : 'multipart/form-data',
63
-//       }, [
64
-//         { name : 'test-img', filename : filename, data: RNFetchBlob.wrap(photo)},
65
-//         { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
66
-//         { name : 'field1', data : 'hello !!'},
67
-//         { name : 'field2', data : 'hello2 !!'}
68
-//       ])
69
-//     .then((resp) => {
70
-//       resp = resp.json()
71
-//       report(
72
-//         <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
73
-//         <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
74
-//       )
75
-//       return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
76
-//     })
77
-//     .then((resp) => {
78
-//       report(<Info key="uploaded image">
79
-//         <Image
80
-//           style={styles.image}
81
-//           source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
82
-//       </Info>)
83
-//       done()
84
-//     })
85
-// })
86
-//
87
-//
88
-// describe('access assets from camera roll', (report, done) => {
89
-//   let photo = null
90
-//   CameraRoll.getPhotos({first : 10})
91
-//     .then((resp) => {
92
-//       photo = resp.edges[0].node.image.uri
93
-//       report(<Info key="items">
94
-//         <Text>{photo}</Text>
95
-//       </Info>)
96
-//       return fs.readFile(photo, 'base64')
97
-//     })
98
-//     .then((data) => {
99
-//       report(<Info key="asset image">
100
-//         <Image
101
-//           style={styles.image}
102
-//           source={{uri: `data:image/png;base64, ${data}`}}/>
103
-//       </Info>)
104
-//       done()
105
-//     })
106
-// })
107
-//
108
-// describe('read asset in app bundle',(report, done) => {
109
-//   let target = fs.asset('test-asset2.png')
110
-//   fs.readFile(target, 'base64')
111
-//   .then((data) => {
112
-//     report(<Info key="asset image">
113
-//       <Image
114
-//         style={styles.image}
115
-//         source={{uri: `data:image/png;base64, ${data}`}}/>
116
-//     </Info>)
117
-//     return fs.readFile(fs.asset('test-asset1.json'), 'utf8')
118
-//   })
119
-//   .then((resp) => {
120
-//     report(
121
-//       <Assert key="asset content verify"
122
-//         expect="asset#1"
123
-//         actual={JSON.parse(resp).secret}/>)
124
-//       done()
125
-//   })
126
-// })
127
-//
128
-// describe('stat assets in app', (report, done) => {
129
-//   fs.stat(fs.asset('test-asset2.png'))
130
-//     .then((data) => {
131
-//       report(<Info key="list of assets">
132
-//         <Text>{JSON.stringify(data)}</Text>
133
-//       </Info>)
134
-//       done()
135
-//     })
136
-// })
137
-//
138
-// describe('copy asset', (report, done) => {
139
-//   let dest = `${dirs.DocumentDir}/test-asset-1-${Date.now()}.json`
140
-//   fs.cp(fs.asset('test-asset1.json'), dest)
141
-//     .then(() => fs.readFile(dest, 'utf8'))
142
-//     .then((data) => {
143
-//       report(<Assert key="asset copied correctly"
144
-//         expect={'asset#1'}
145
-//         actual={JSON.parse(data).secret}/>)
146
-//       return fs.stat(fs.asset('test-asset1.json'))
147
-//     })
148
-//     .then((stat) => {
149
-//       report(<Assert key="file size check"
150
-//         expect={27}
151
-//         actual={Math.floor(stat.size)}/>,
152
-//       <Info key="dest file info">
153
-//         <Text>{JSON.stringify(stat)}</Text>
154
-//       </Info>)
155
-//       done()
156
-//     })
157
-// })
158
-//
159
-//
160
-// describe('upload file from assets',(report, done) => {
161
-//   let assetName = fs.asset('test-asset1.json')
162
-//   RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
163
-//     Authorization : `Bearer ${DROPBOX_TOKEN}`,
164
-//     'Dropbox-API-Arg': `{\"path\": \"/rn-upload/file-from-asset-${Platform.OS}.json\",\"mode\": \"add\",\"autorename\": false,\"mute\": false}`,
165
-//     'Content-Type' : 'application/octet-stream',
166
-//   }, RNFetchBlob.wrap(assetName))
167
-//   .then((resp) => {
168
-//     resp = resp.json()
169
-//     report(
170
-//       <Assert key="file name check"
171
-//         expect={`file-from-asset-${Platform.OS}.json`}
172
-//         actual={resp.name}/>)
173
-//     done()
174
-//   })
175
-// })
58
+
59
+describe('Upload multipart data with file from CameraRoll', (report, done) => {
60
+    let filename = 'test-from-storage-img-'+Date.now()+'.png'
61
+    RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
62
+        'Content-Type' : 'multipart/form-data',
63
+      }, [
64
+        { name : 'test-img', filename : filename, data: RNFetchBlob.wrap(photo)},
65
+        { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
66
+        { name : 'field1', data : 'hello !!'},
67
+        { name : 'field2', data : 'hello2 !!'}
68
+      ])
69
+    .then((resp) => {
70
+      resp = resp.json()
71
+      report(
72
+        <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
73
+        <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
74
+      )
75
+      return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
76
+    })
77
+    .then((resp) => {
78
+      report(<Info key="uploaded image">
79
+        <Image
80
+          style={styles.image}
81
+          source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
82
+      </Info>)
83
+      done()
84
+    })
85
+})
86
+
87
+
88
+describe('access assets from camera roll', (report, done) => {
89
+  let photo = null
90
+  CameraRoll.getPhotos({first : 10})
91
+    .then((resp) => {
92
+      photo = resp.edges[0].node.image.uri
93
+      report(<Info key="items">
94
+        <Text>{photo}</Text>
95
+      </Info>)
96
+      return fs.readFile(photo, 'base64')
97
+    })
98
+    .then((data) => {
99
+      report(<Info key="asset image">
100
+        <Image
101
+          style={styles.image}
102
+          source={{uri: `data:image/png;base64, ${data}`}}/>
103
+      </Info>)
104
+      done()
105
+    })
106
+})
107
+
108
+describe('read asset in app bundle',(report, done) => {
109
+  let target = fs.asset('test-asset2.png')
110
+  fs.readFile(target, 'base64')
111
+  .then((data) => {
112
+    report(<Info key="asset image">
113
+      <Image
114
+        style={styles.image}
115
+        source={{uri: `data:image/png;base64, ${data}`}}/>
116
+    </Info>)
117
+    return fs.readFile(fs.asset('test-asset1.json'), 'utf8')
118
+  })
119
+  .then((resp) => {
120
+    report(
121
+      <Assert key="asset content verify"
122
+        expect="asset#1"
123
+        actual={JSON.parse(resp).secret}/>)
124
+      done()
125
+  })
126
+})
127
+
128
+describe('stat assets in app', (report, done) => {
129
+  fs.stat(fs.asset('test-asset2.png'))
130
+    .then((data) => {
131
+      report(<Info key="list of assets">
132
+        <Text>{JSON.stringify(data)}</Text>
133
+      </Info>)
134
+      done()
135
+    })
136
+})
137
+
138
+describe('copy asset', (report, done) => {
139
+  let dest = `${dirs.DocumentDir}/test-asset-1-${Date.now()}.json`
140
+  fs.cp(fs.asset('test-asset1.json'), dest)
141
+    .then(() => fs.readFile(dest, 'utf8'))
142
+    .then((data) => {
143
+      report(<Assert key="asset copied correctly"
144
+        expect={'asset#1'}
145
+        actual={JSON.parse(data).secret}/>)
146
+      return fs.stat(fs.asset('test-asset1.json'))
147
+    })
148
+    .then((stat) => {
149
+      report(<Assert key="file size check"
150
+        expect={27}
151
+        actual={Math.floor(stat.size)}/>,
152
+      <Info key="dest file info">
153
+        <Text>{JSON.stringify(stat)}</Text>
154
+      </Info>)
155
+      done()
156
+    })
157
+})
158
+
159
+
160
+describe('upload file from assets',(report, done) => {
161
+  let assetName = fs.asset('test-asset1.json')
162
+  RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
163
+    Authorization : `Bearer ${DROPBOX_TOKEN}`,
164
+    'Dropbox-API-Arg': `{\"path\": \"/rn-upload/file-from-asset-${Platform.OS}.json\",\"mode\": \"add\",\"autorename\": false,\"mute\": false}`,
165
+    'Content-Type' : 'application/octet-stream',
166
+  }, RNFetchBlob.wrap(assetName))
167
+  .then((resp) => {
168
+    resp = resp.json()
169
+    report(
170
+      <Assert key="file name check"
171
+        expect={`file-from-asset-${Platform.OS}.json`}
172
+        actual={resp.name}/>)
173
+    done()
174
+  })
175
+})
176 176
 
177 177
 describe('Check custom MIME type correctness',(report, done) => {
178 178
   RNFetchBlob

+ 68
- 0
test/test-0.6.3.js Ver fichero

@@ -0,0 +1,68 @@
1
+import RNTest from './react-native-testkit/'
2
+import React from 'react'
3
+import RNFetchBlob from 'react-native-fetch-blob'
4
+import Timer from 'react-timer-mixin'
5
+
6
+import {
7
+  StyleSheet,
8
+  Text,
9
+  View,
10
+  ScrollView,
11
+  CameraRoll,
12
+  Platform,
13
+  Dimensions,
14
+  Image,
15
+} from 'react-native';
16
+
17
+const fs = RNFetchBlob.fs
18
+const { Assert, Comparer, Info, prop } = RNTest
19
+const describe = RNTest.config({
20
+  group : '0.6.3',
21
+  run : true,
22
+  expand : true,
23
+  timeout : 300000000,
24
+})
25
+const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop()
26
+const  dirs = RNFetchBlob.fs.dirs
27
+
28
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
29
+
30
+describe('massive HTTP request', (report, done) => {
31
+  try {
32
+  let promises = []
33
+  let progress = []
34
+  let begin = Date.now()
35
+  for(let i=0; i<1500;i++) {
36
+    let p = RNFetchBlob
37
+    .config({fileCache : true})
38
+    .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
39
+    // .progress(function(current, total){
40
+    //   progress[this] = current/total
41
+    // }.bind(i))
42
+    promises.push(p)
43
+  }
44
+  // let it = Timer.setInterval(() => {
45
+  //   function pgs() {
46
+  //     let res = []
47
+  //     for(var i in progress) {
48
+  //       res.push(<Text key={`download#${i}`}>{`download #${i} ${Math.floor(progress[i]*100)}%`}</Text>)
49
+  //     }
50
+  //     return res
51
+  //   }
52
+  //   report(<Info key={`progress monitor`} uid="progress">
53
+  //     {pgs()}
54
+  //   </Info>)
55
+  // }, 1000)
56
+  Promise.all(promises).then((resps) => {
57
+    for(let i in resps) {
58
+      fs.unlink(resps[i].path())
59
+    }
60
+    report(<Info key={`time = ${(Date.now() - begin) / 1000} sec`}></Info>)
61
+    // Timer.clearInterval(it)
62
+    done()
63
+  })
64
+} catch(err) {
65
+  console.log(err)
66
+}
67
+
68
+})

+ 1
- 0
test/test-init.js Ver fichero

@@ -57,5 +57,6 @@ require('./test-0.5.1')
57 57
 require('./test-0.5.2')
58 58
 require('./test-0.6.0')
59 59
 require('./test-0.6.2')
60
+require('./test-0.6.3')
60 61
 require('./test-fs')
61 62
 require('./test-android')