|
@@ -2,6 +2,7 @@ import RNFetchBlob from '../index.js'
|
2
|
2
|
import Log from '../utils/log.js'
|
3
|
3
|
import fs from '../fs'
|
4
|
4
|
import unicode from '../utils/unicode'
|
|
5
|
+import Blob from './Blob'
|
5
|
6
|
|
6
|
7
|
const log = new Log('FetchPolyfill')
|
7
|
8
|
|
|
@@ -18,13 +19,14 @@ export default class Fetch {
|
18
|
19
|
class RNFetchBlobFetchPolyfill {
|
19
|
20
|
|
20
|
21
|
constructor(config:RNFetchBlobConfig) {
|
21
|
|
- this.build = () => (url, options) => {
|
|
22
|
+ this.build = () => (url, options = {}) => {
|
22
|
23
|
options.headers = options.headers || {}
|
23
|
24
|
options['Content-Type'] = options.headers['Content-Type'] || options.headers['content-type']
|
24
|
25
|
options['content-type'] = options.headers['Content-Type'] || options.headers['content-type']
|
25
|
26
|
return RNFetchBlob.config(config)
|
26
|
27
|
.fetch(options.method, url, options.headers, options.body)
|
27
|
28
|
.then((resp) => {
|
|
29
|
+ log.verbose('response', resp)
|
28
|
30
|
let info = resp.info()
|
29
|
31
|
return Promise.resolve(new RNFetchBlobFetchRepsonse(resp))
|
30
|
32
|
})
|
|
@@ -91,7 +93,21 @@ function readText(resp, info):Promise<string> {
|
91
|
93
|
}
|
92
|
94
|
}
|
93
|
95
|
|
|
96
|
+function readBlob(resp, info):Promise<object> {
|
|
97
|
+ log.verbose('readBlob', resp, info)
|
|
98
|
+ let cType = info.headers['Content-Type']
|
|
99
|
+ switch (info.rnfbEncode) {
|
|
100
|
+ case 'base64':
|
|
101
|
+ return Blob.build(resp.data, { type : `${cType};BASE64` })
|
|
102
|
+ case 'path':
|
|
103
|
+ return Blob.build(RNFetchBlob.wrap(resp.data), { type : `${cType}`})
|
|
104
|
+ default:
|
|
105
|
+ return Blob.build(resp.data, { type : `${cType}`})
|
|
106
|
+ }
|
|
107
|
+}
|
|
108
|
+
|
94
|
109
|
function readJSON(resp, info):Promise<object> {
|
|
110
|
+ log.verbose('readJSON', resp, info)
|
95
|
111
|
switch (info.rnfbEncode) {
|
96
|
112
|
case 'base64':
|
97
|
113
|
return Promise.resolve(resp.json())
|