Browse Source

wip commit

Ben Hsieh 8 years ago
parent
commit
f612f35fe9

+ 1
- 7
src/index.js View File

@@ -18,6 +18,7 @@ import type {
18 18
   RNFetchBlobStream
19 19
 } from './types'
20 20
 import fs from './fs'
21
+import getUUID from './utils/uuid'
21 22
 import base64 from 'base-64'
22 23
 const {
23 24
   RNFetchBlobSession,
@@ -286,13 +287,6 @@ class FetchBlobResponse {
286 287
 
287 288
 }
288 289
 
289
-function getUUID() {
290
-  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
291
-    let r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
292
-    return v.toString(16);
293
-  });
294
-}
295
-
296 290
 export default {
297 291
   fetch,
298 292
   base64,

+ 2
- 2
src/ios/RNFetchBlob.xcodeproj/project.pbxproj View File

@@ -190,7 +190,7 @@
190 190
 				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
191 191
 				GCC_WARN_UNUSED_FUNCTION = YES;
192 192
 				GCC_WARN_UNUSED_VARIABLE = YES;
193
-				IPHONEOS_DEPLOYMENT_TARGET = 9.3;
193
+				IPHONEOS_DEPLOYMENT_TARGET = 7.0;
194 194
 				MTL_ENABLE_DEBUG_INFO = YES;
195 195
 				ONLY_ACTIVE_ARCH = YES;
196 196
 				SDKROOT = iphoneos;
@@ -228,7 +228,7 @@
228 228
 				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
229 229
 				GCC_WARN_UNUSED_FUNCTION = YES;
230 230
 				GCC_WARN_UNUSED_VARIABLE = YES;
231
-				IPHONEOS_DEPLOYMENT_TARGET = 9.3;
231
+				IPHONEOS_DEPLOYMENT_TARGET = 7.0;
232 232
 				MTL_ENABLE_DEBUG_INFO = NO;
233 233
 				SDKROOT = iphoneos;
234 234
 				VALIDATE_PRODUCT = YES;

+ 6
- 3
src/polyfill/Blob.js View File

@@ -5,6 +5,7 @@
5 5
  * Web API Blob object polyfill.
6 6
  */
7 7
 import fs from '../fs.js'
8
+import getUUID from '../utils/uuid'
8 9
 
9 10
 export default class Blob {
10 11
 
@@ -24,8 +25,8 @@ export default class Blob {
24 25
     }
25 26
     else if(typeof data === 'string') {
26 27
       // content from file
27
-      if(data.startsWith('RNFetchBlob-file://') {
28
-        enode = 'uri'
28
+      if(data.startsWith('RNFetchBlob-file://')) {
29
+        encode = 'uri'
29 30
       }
30 31
       // BASE64 encoded
31 32
       else {
@@ -54,11 +55,13 @@ export default class Blob {
54 55
    * @return {Blob}
55 56
    */
56 57
   slice(start:?number, end:?number, encoding:?string):Blob {
58
+    console.log('slice called')
57 59
     return fs.slice(this.cacheName, getBlobName(), contentType, start, end)
58 60
   }
59 61
 
60 62
   /**
61 63
    * Release the resource of the Blob object.
64
+   * @nonstandard
62 65
    * @return {Promise}
63 66
    */
64 67
   close() {
@@ -73,5 +76,5 @@ export default class Blob {
73 76
  * @return {string} Temporary filename
74 77
  */
75 78
 function getBlobName() {
76
-
79
+  return 'blob-' + getUUID()
77 80
 }

+ 1
- 1
src/polyfill/File.js View File

@@ -10,7 +10,7 @@ import Blob from './Blob.js'
10 10
 export default class File extends Blob {
11 11
 
12 12
   constructor() {
13
-    
13
+    super()
14 14
   }
15 15
 
16 16
 }

+ 15
- 0
src/polyfill/XMLHttpRequest.js View File

@@ -0,0 +1,15 @@
1
+export default class XMLHttpRequest {
2
+
3
+  constructor(...args) {
4
+    console.log('XMLHttpRequest constructor called', args)
5
+  }
6
+
7
+  send(...data) {
8
+    console.log('XMLHttpRequest send called', data)
9
+  }
10
+
11
+  abort(...args) {
12
+    console.log('XMLHttpRequest abort called', data)
13
+  }
14
+
15
+}

+ 2
- 1
src/polyfill/index.js View File

@@ -1,6 +1,7 @@
1 1
 import Blob from './Blob.js'
2 2
 import File from './File.js'
3
+import XMLHttpRequest from './XMLHttpRequest.js'
3 4
 
4 5
 export default {
5
-  Blob, File
6
+  Blob, File, XMLHttpRequest
6 7
 }

+ 6
- 0
src/utils/uuid.js View File

@@ -0,0 +1,6 @@
1
+export default function getUUID() {
2
+  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
3
+    let r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
4
+    return v.toString(16);
5
+  });
6
+}

+ 4
- 3
test.sh View File

@@ -37,12 +37,13 @@ node -e "var fs=require('fs'); var pkg = JSON.parse(fs.readFileSync('./RNFetchBl
37 37
 
38 38
 # install module
39 39
 cd "${TEST_APP_PATH}"
40
-npm install --save "${CWD}/src"
41
-npm install --save firebase
40
+# npm install --save "${CWD}/src"
41
+npm install --save react-native-fetch-blob@0.7.0-dev.1
42 42
 rnpm link
43 43
 
44 44
 # copy android assets
45
-cp ./test/assets/ ./RNFetchBlobTest/android/app/src/main/
45
+cd ${CWD}
46
+cp -R ./test/assets/ ./RNFetchBlobTest/android/app/src/main/assets/
46 47
 
47 48
 # start RN
48 49
 cd "${TEST_APP_PATH}"

+ 8
- 4
test/test-firebase.js View File

@@ -16,6 +16,10 @@ import {
16 16
 } from 'react-native';
17 17
 
18 18
 const fs = RNFetchBlob.fs
19
+const Blob = RNFetchBlob.polyfill.Blob
20
+window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
21
+window.Blob = Blob
22
+
19 23
 const { Assert, Comparer, Info, prop } = RNTest
20 24
 const describe = RNTest.config({
21 25
   group : 'firebase',
@@ -45,10 +49,10 @@ describe('firebase login', (report, done) => {
45 49
       console.log('firebase sigin failed', err)
46 50
     })
47 51
   firebase.auth().onAuthStateChanged((user) => {
48
-    report(<Assert key="login success"
52
+    report(<Assert key="login status" uid="100"
49 53
       expect={user !== undefined}
50 54
       actual={user}/>,
51
-    <Info key="user content">
55
+    <Info key="user content" uid="user data">
52 56
       <Text>{JSON.stringify(user)}</Text>
53 57
     </Info>)
54 58
     done()
@@ -59,9 +63,9 @@ describe('firebase login', (report, done) => {
59 63
 describe('upload file to firebase', (report, done) => {
60 64
 
61 65
   try {
62
-    
66
+
63 67
     let storage = firebase.storage().ref()
64
-    let task = storage.file(`testdata/firebase-test-${Platform.OS}.png`).put(webFile, metadata)
68
+    let task = storage.child(`testdata/firebase-test-${Platform.OS}.png`).put(new Blob('hello !'), { contentType : 'text/plain' })
65 69
 
66 70
     task.on('state_change', null, (err) => {
67 71
 

+ 2
- 2
test/test-init.js View File

@@ -18,8 +18,8 @@ const { Assert, Comparer, Info, prop } = RNTest
18 18
 // test environment variables
19 19
 
20 20
 prop('FILENAME', `${Platform.OS}-0.7.0-${Date.now()}.png`)
21
-prop('TEST_SERVER_URL', 'http://192.168.16.70:8123')
22
-prop('TEST_SERVER_URL_SSL', 'https://192.168.16.70:8124')
21
+prop('TEST_SERVER_URL', 'http://192.168.0.11:8123')
22
+prop('TEST_SERVER_URL_SSL', 'https://192.168.0.11:8124')
23 23
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
24 24
 prop('styles', {
25 25
   image : {