react-native-blob-util 0.22.0 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +56 -56
- package/LICENSE +21 -21
- package/Migration.md +41 -41
- package/NuGet.config +11 -11
- package/README.md +1109 -1104
- package/android/gradle.properties +1 -1
- package/android/src/main/AndroidManifest.xml +37 -37
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConfig.java +57 -57
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConst.java +20 -20
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFileTransformer.java +9 -9
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilImpl.java +431 -431
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilProgressConfig.java +39 -39
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +1014 -1014
- package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilDefaultResp.java +98 -98
- package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilFileResp.java +166 -166
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/FileDescription.java +19 -19
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/FileProvider.java +4 -4
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/MimeType.java +70 -70
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/PathResolver.java +223 -223
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/Tls12SocketFactory.java +68 -68
- package/android/src/main/res/values/strings.xml +3 -3
- package/android/src/main/res/xml/provider_paths.xml +12 -12
- package/android.js +58 -58
- package/class/ReactNativeBlobUtilCanceledFetchError.js +9 -9
- package/class/ReactNativeBlobUtilFile.js +5 -5
- package/class/ReactNativeBlobUtilReadStream.js +84 -84
- package/class/ReactNativeBlobUtilSession.js +68 -68
- package/class/ReactNativeBlobUtilWriteStream.js +50 -50
- package/class/StatefulPromise.js +7 -7
- package/codegenSpecs/NativeBlobUtils.js +86 -86
- package/components/Fetch.onPress.js +10 -10
- package/components/Fetch.when.js +15 -15
- package/fetch.js +350 -350
- package/fs.js +480 -480
- package/index.js +64 -64
- package/index.js.flow +192 -192
- package/index.web.js +1 -1
- package/ios/PrivacyInfo.xcprivacy +28 -28
- package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.h +55 -55
- package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.mm +992 -992
- package/ios/ReactNativeBlobUtil.xcodeproj/project.pbxproj +405 -405
- package/ios/ReactNativeBlobUtilConst.h +58 -58
- package/ios/ReactNativeBlobUtilConst.mm +47 -47
- package/ios/ReactNativeBlobUtilFS.h +108 -108
- package/ios/ReactNativeBlobUtilFS.mm +1064 -1064
- package/ios/ReactNativeBlobUtilFileTransformer.h +23 -23
- package/ios/ReactNativeBlobUtilFileTransformer.mm +20 -20
- package/ios/ReactNativeBlobUtilNetwork.h +49 -49
- package/ios/ReactNativeBlobUtilNetwork.mm +159 -159
- package/ios/ReactNativeBlobUtilProgress.h +32 -32
- package/ios/ReactNativeBlobUtilProgress.mm +57 -57
- package/ios/ReactNativeBlobUtilReqBuilder.h +37 -37
- package/ios/ReactNativeBlobUtilReqBuilder.mm +292 -292
- package/ios/ReactNativeBlobUtilRequest.h +48 -48
- package/ios/ReactNativeBlobUtilRequest.mm +584 -584
- package/ios.js +61 -61
- package/json-stream.js +42 -42
- package/lib/oboe-browser.js +2703 -2703
- package/mediacollection.js +36 -36
- package/package.json +68 -68
- package/polyfill/Blob.js +362 -362
- package/polyfill/Event.js +11 -11
- package/polyfill/EventTarget.js +78 -78
- package/polyfill/Fetch.js +219 -219
- package/polyfill/File.js +27 -27
- package/polyfill/FileReader.js +91 -91
- package/polyfill/ProgressEvent.js +32 -32
- package/polyfill/XMLHttpRequest.js +466 -466
- package/polyfill/XMLHttpRequestEventTarget.js +126 -126
- package/polyfill/index.js +11 -11
- package/react-native-blob-util.podspec +48 -48
- package/types.js +69 -69
- package/utils/log.js +40 -40
- package/utils/unicode.js +7 -7
- package/utils/uri.js +33 -33
- package/utils/uuid.js +4 -4
- package/windows/ExperimentalFeatures.props +33 -33
- package/windows/README.md +2 -2
- package/windows/ReactNativeBlobUtil/PropertySheet.props +15 -15
- package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.cpp +1836 -1836
- package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.def +3 -3
- package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.h +372 -372
- package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.vcxproj +139 -139
- package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.vcxproj.filters +43 -43
- package/windows/ReactNativeBlobUtil/ReactPackageProvider.cpp +20 -20
- package/windows/ReactNativeBlobUtil/ReactPackageProvider.h +24 -24
- package/windows/ReactNativeBlobUtil/ReactPackageProvider.idl +9 -9
- package/windows/ReactNativeBlobUtil/codegen/.clang-format +1 -1
- package/windows/ReactNativeBlobUtil/codegen/NativeBlobUtilsDataTypes.g.h +42 -42
- package/windows/ReactNativeBlobUtil/codegen/NativeBlobUtilsSpec.g.h +353 -353
- package/windows/ReactNativeBlobUtil/packages.config +3 -3
- package/windows/ReactNativeBlobUtil/packages.lock.json +59 -59
- package/windows/ReactNativeBlobUtil/pch.cpp +1 -1
- package/windows/ReactNativeBlobUtil/pch.h +30 -30
- package/windows/ReactNativeBlobUtil/resource.h +5 -5
- package/windows/ReactNativeBlobUtil/targetver.h +8 -8
- package/windows/ReactNativeBlobUtil.sln +43 -43
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
// ReactNativeBlobUtilFileTransformer.h
|
|
2
|
-
// ReactNativeBlobUtil
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
#ifndef ReactNativeBlobUtilDataConverter_h
|
|
6
|
-
#define ReactNativeBlobUtilDataConverter_h
|
|
7
|
-
|
|
8
|
-
#import <UIKit/UIKit.h>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@protocol FileTransformer <NSObject>
|
|
12
|
-
- (NSData*) onWriteFile:(NSData*)data;
|
|
13
|
-
- (NSData*) onReadFile:(NSData*)data;
|
|
14
|
-
@end
|
|
15
|
-
|
|
16
|
-
@interface ReactNativeBlobUtilFileTransformer : NSObject
|
|
17
|
-
|
|
18
|
-
+ (void) setFileTransformer:(NSObject<FileTransformer>*) fileTransformer;
|
|
19
|
-
+ (NSObject<FileTransformer>*) getFileTransformer;
|
|
20
|
-
|
|
21
|
-
@end
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
// ReactNativeBlobUtilFileTransformer.h
|
|
2
|
+
// ReactNativeBlobUtil
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#ifndef ReactNativeBlobUtilDataConverter_h
|
|
6
|
+
#define ReactNativeBlobUtilDataConverter_h
|
|
7
|
+
|
|
8
|
+
#import <UIKit/UIKit.h>
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@protocol FileTransformer <NSObject>
|
|
12
|
+
- (NSData*) onWriteFile:(NSData*)data;
|
|
13
|
+
- (NSData*) onReadFile:(NSData*)data;
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
@interface ReactNativeBlobUtilFileTransformer : NSObject
|
|
17
|
+
|
|
18
|
+
+ (void) setFileTransformer:(NSObject<FileTransformer>*) fileTransformer;
|
|
19
|
+
+ (NSObject<FileTransformer>*) getFileTransformer;
|
|
20
|
+
|
|
21
|
+
@end
|
|
22
|
+
|
|
23
|
+
|
|
24
24
|
#endif /* ReactNativeBlobUtilFileTransformer_h */
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
// ReactNativeBlobUtilFileTransformer.m
|
|
2
|
-
// ReactNativeBlobUtil
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
#import "ReactNativeBlobUtilFileTransformer.h"
|
|
6
|
-
|
|
7
|
-
static NSObject<FileTransformer> *sharedFileTransformer;
|
|
8
|
-
|
|
9
|
-
@implementation ReactNativeBlobUtilFileTransformer
|
|
10
|
-
|
|
11
|
-
+ (void) setFileTransformer:(NSObject<FileTransformer> *)fileTransformer {
|
|
12
|
-
sharedFileTransformer = fileTransformer;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
+ (NSObject<FileTransformer>*) getFileTransformer {
|
|
16
|
-
return sharedFileTransformer;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@end
|
|
20
|
-
|
|
1
|
+
// ReactNativeBlobUtilFileTransformer.m
|
|
2
|
+
// ReactNativeBlobUtil
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#import "ReactNativeBlobUtilFileTransformer.h"
|
|
6
|
+
|
|
7
|
+
static NSObject<FileTransformer> *sharedFileTransformer;
|
|
8
|
+
|
|
9
|
+
@implementation ReactNativeBlobUtilFileTransformer
|
|
10
|
+
|
|
11
|
+
+ (void) setFileTransformer:(NSObject<FileTransformer> *)fileTransformer {
|
|
12
|
+
sharedFileTransformer = fileTransformer;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
+ (NSObject<FileTransformer>*) getFileTransformer {
|
|
16
|
+
return sharedFileTransformer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@end
|
|
20
|
+
|
|
21
21
|
// PHOENIX:PATCH-PACKAGE END
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ReactNativeBlobUtilNetwork.h
|
|
3
|
-
// ReactNativeBlobUtil
|
|
4
|
-
//
|
|
5
|
-
// Created by wkh237 on 2016/6/6.
|
|
6
|
-
// Copyright © 2016 wkh237. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#ifndef ReactNativeBlobUtilNetwork_h
|
|
10
|
-
#define ReactNativeBlobUtilNetwork_h
|
|
11
|
-
|
|
12
|
-
#import <Foundation/Foundation.h>
|
|
13
|
-
#import "ReactNativeBlobUtilProgress.h"
|
|
14
|
-
#import "ReactNativeBlobUtilFS.h"
|
|
15
|
-
#import "ReactNativeBlobUtilRequest.h"
|
|
16
|
-
|
|
17
|
-
#if __has_include(<React/RCTAssert.h>)
|
|
18
|
-
#import <React/RCTBridgeModule.h>
|
|
19
|
-
#else
|
|
20
|
-
#import "RCTBridgeModule.h"
|
|
21
|
-
#endif
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@interface ReactNativeBlobUtilNetwork : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
|
|
25
|
-
|
|
26
|
-
@property(nonnull, nonatomic) NSOperationQueue *taskQueue;
|
|
27
|
-
@property(nonnull, nonatomic) NSMapTable<NSString*, ReactNativeBlobUtilRequest*> * requestsTable;
|
|
28
|
-
@property(nonnull, nonatomic) NSMutableDictionary<NSString*, ReactNativeBlobUtilProgress*> *rebindProgressDict;
|
|
29
|
-
@property(nonnull, nonatomic) NSMutableDictionary<NSString*, ReactNativeBlobUtilProgress*> *rebindUploadProgressDict;
|
|
30
|
-
|
|
31
|
-
+ (ReactNativeBlobUtilNetwork* _Nullable)sharedInstance;
|
|
32
|
-
+ (NSMutableDictionary * _Nullable ) normalizeHeaders:(NSDictionary * _Nullable)headers;
|
|
33
|
-
|
|
34
|
-
- (nullable id) init;
|
|
35
|
-
- (void) sendRequest:(NSDictionary * _Nullable )options
|
|
36
|
-
contentLength:(long)contentLength
|
|
37
|
-
baseModule:(ReactNativeBlobUtil * _Nullable)baseModule
|
|
38
|
-
taskId:(NSString * _Nullable)taskId
|
|
39
|
-
withRequest:(NSURLRequest * _Nullable)req
|
|
40
|
-
callback:(_Nullable RCTResponseSenderBlock) callback;
|
|
41
|
-
- (void) cancelRequest:(NSString * _Nonnull)taskId;
|
|
42
|
-
- (void) enableProgressReport:(NSString * _Nonnull) taskId config:(ReactNativeBlobUtilProgress * _Nullable)config;
|
|
43
|
-
- (void) enableUploadProgress:(NSString * _Nonnull) taskId config:(ReactNativeBlobUtilProgress * _Nullable)config;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@end
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#endif /* ReactNativeBlobUtilNetwork_h */
|
|
1
|
+
//
|
|
2
|
+
// ReactNativeBlobUtilNetwork.h
|
|
3
|
+
// ReactNativeBlobUtil
|
|
4
|
+
//
|
|
5
|
+
// Created by wkh237 on 2016/6/6.
|
|
6
|
+
// Copyright © 2016 wkh237. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef ReactNativeBlobUtilNetwork_h
|
|
10
|
+
#define ReactNativeBlobUtilNetwork_h
|
|
11
|
+
|
|
12
|
+
#import <Foundation/Foundation.h>
|
|
13
|
+
#import "ReactNativeBlobUtilProgress.h"
|
|
14
|
+
#import "ReactNativeBlobUtilFS.h"
|
|
15
|
+
#import "ReactNativeBlobUtilRequest.h"
|
|
16
|
+
|
|
17
|
+
#if __has_include(<React/RCTAssert.h>)
|
|
18
|
+
#import <React/RCTBridgeModule.h>
|
|
19
|
+
#else
|
|
20
|
+
#import "RCTBridgeModule.h"
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@interface ReactNativeBlobUtilNetwork : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
|
|
25
|
+
|
|
26
|
+
@property(nonnull, nonatomic) NSOperationQueue *taskQueue;
|
|
27
|
+
@property(nonnull, nonatomic) NSMapTable<NSString*, ReactNativeBlobUtilRequest*> * requestsTable;
|
|
28
|
+
@property(nonnull, nonatomic) NSMutableDictionary<NSString*, ReactNativeBlobUtilProgress*> *rebindProgressDict;
|
|
29
|
+
@property(nonnull, nonatomic) NSMutableDictionary<NSString*, ReactNativeBlobUtilProgress*> *rebindUploadProgressDict;
|
|
30
|
+
|
|
31
|
+
+ (ReactNativeBlobUtilNetwork* _Nullable)sharedInstance;
|
|
32
|
+
+ (NSMutableDictionary * _Nullable ) normalizeHeaders:(NSDictionary * _Nullable)headers;
|
|
33
|
+
|
|
34
|
+
- (nullable id) init;
|
|
35
|
+
- (void) sendRequest:(NSDictionary * _Nullable )options
|
|
36
|
+
contentLength:(long)contentLength
|
|
37
|
+
baseModule:(ReactNativeBlobUtil * _Nullable)baseModule
|
|
38
|
+
taskId:(NSString * _Nullable)taskId
|
|
39
|
+
withRequest:(NSURLRequest * _Nullable)req
|
|
40
|
+
callback:(_Nullable RCTResponseSenderBlock) callback;
|
|
41
|
+
- (void) cancelRequest:(NSString * _Nonnull)taskId;
|
|
42
|
+
- (void) enableProgressReport:(NSString * _Nonnull) taskId config:(ReactNativeBlobUtilProgress * _Nullable)config;
|
|
43
|
+
- (void) enableUploadProgress:(NSString * _Nonnull) taskId config:(ReactNativeBlobUtilProgress * _Nullable)config;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@end
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
#endif /* ReactNativeBlobUtilNetwork_h */
|
|
@@ -1,159 +1,159 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ReactNativeBlobUtilNetwork.m
|
|
3
|
-
// ReactNativeBlobUtil
|
|
4
|
-
//
|
|
5
|
-
// Created by wkh237 on 2016/6/6.
|
|
6
|
-
// Copyright © 2016 wkh237. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
#import <Foundation/Foundation.h>
|
|
11
|
-
#import "ReactNativeBlobUtilNetwork.h"
|
|
12
|
-
|
|
13
|
-
#import "ReactNativeBlobUtilConst.h"
|
|
14
|
-
#import "ReactNativeBlobUtilProgress.h"
|
|
15
|
-
|
|
16
|
-
#if __has_include(<React/RCTAssert.h>)
|
|
17
|
-
#import <React/RCTRootView.h>
|
|
18
|
-
#import <React/RCTLog.h>
|
|
19
|
-
#import <React/RCTBridge.h>
|
|
20
|
-
#else
|
|
21
|
-
#import "RCTRootView.h"
|
|
22
|
-
#import "RCTLog.h"
|
|
23
|
-
#import "RCTBridge.h"
|
|
24
|
-
#endif
|
|
25
|
-
|
|
26
|
-
////////////////////////////////////////
|
|
27
|
-
//
|
|
28
|
-
// HTTP request handler
|
|
29
|
-
//
|
|
30
|
-
////////////////////////////////////////
|
|
31
|
-
|
|
32
|
-
NSMapTable * expirationTable;
|
|
33
|
-
|
|
34
|
-
__attribute__((constructor))
|
|
35
|
-
static void initialize_tables() {
|
|
36
|
-
if (expirationTable == nil) {
|
|
37
|
-
expirationTable = [[NSMapTable alloc] init];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
@implementation ReactNativeBlobUtilNetwork
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- (id)init {
|
|
46
|
-
self = [super init];
|
|
47
|
-
if (self) {
|
|
48
|
-
self.requestsTable = [NSMapTable mapTableWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableWeakMemory];
|
|
49
|
-
|
|
50
|
-
self.taskQueue = [[NSOperationQueue alloc] init];
|
|
51
|
-
self.taskQueue.qualityOfService = NSQualityOfServiceUtility;
|
|
52
|
-
self.taskQueue.maxConcurrentOperationCount = 10;
|
|
53
|
-
self.rebindProgressDict = [NSMutableDictionary dictionary];
|
|
54
|
-
self.rebindUploadProgressDict = [NSMutableDictionary dictionary];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return self;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
+ (ReactNativeBlobUtilNetwork* _Nullable)sharedInstance {
|
|
61
|
-
static id _sharedInstance = nil;
|
|
62
|
-
static dispatch_once_t onceToken;
|
|
63
|
-
|
|
64
|
-
dispatch_once(&onceToken, ^{
|
|
65
|
-
_sharedInstance = [[self alloc] init];
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return _sharedInstance;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
- (void) sendRequest:(__weak NSDictionary * _Nullable )options
|
|
72
|
-
contentLength:(long) contentLength
|
|
73
|
-
baseModule:(ReactNativeBlobUtil * _Nullable)baseModule
|
|
74
|
-
taskId:(NSString * _Nullable)taskId
|
|
75
|
-
withRequest:(__weak NSURLRequest * _Nullable)req
|
|
76
|
-
callback:(_Nullable RCTResponseSenderBlock) callback
|
|
77
|
-
{
|
|
78
|
-
ReactNativeBlobUtilRequest *request = [[ReactNativeBlobUtilRequest alloc] init];
|
|
79
|
-
[request sendRequest:options
|
|
80
|
-
contentLength:contentLength
|
|
81
|
-
baseModule:baseModule
|
|
82
|
-
taskId:taskId
|
|
83
|
-
withRequest:req
|
|
84
|
-
taskOperationQueue:self.taskQueue
|
|
85
|
-
callback:callback];
|
|
86
|
-
|
|
87
|
-
@synchronized([ReactNativeBlobUtilNetwork class]) {
|
|
88
|
-
[self.requestsTable setObject:request forKey:taskId];
|
|
89
|
-
[self checkProgressConfigForTask:taskId];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
- (void) checkProgressConfigForTask:(NSString *)taskId {
|
|
94
|
-
//reconfig progress
|
|
95
|
-
ReactNativeBlobUtilProgress *downloadConfig = self.rebindProgressDict[taskId];
|
|
96
|
-
if (downloadConfig != nil) {
|
|
97
|
-
[self enableProgressReport:taskId config:downloadConfig];
|
|
98
|
-
[self.rebindProgressDict removeObjectForKey:taskId];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
//reconfig uploadProgress
|
|
102
|
-
ReactNativeBlobUtilProgress *uploadConfig = self.rebindUploadProgressDict[taskId];
|
|
103
|
-
if (uploadConfig != nil) {
|
|
104
|
-
[self enableUploadProgress:taskId config:uploadConfig];
|
|
105
|
-
[self.rebindUploadProgressDict removeObjectForKey:taskId];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
- (void) enableProgressReport:(NSString *) taskId config:(ReactNativeBlobUtilProgress *)config
|
|
110
|
-
{
|
|
111
|
-
if (config) {
|
|
112
|
-
@synchronized ([ReactNativeBlobUtilNetwork class]) {
|
|
113
|
-
if (![self.requestsTable objectForKey:taskId]) {
|
|
114
|
-
[self.rebindProgressDict setValue:config forKey:taskId];
|
|
115
|
-
} else {
|
|
116
|
-
[self.requestsTable objectForKey:taskId].progressConfig = config;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
- (void) enableUploadProgress:(NSString *) taskId config:(ReactNativeBlobUtilProgress *)config
|
|
123
|
-
{
|
|
124
|
-
if (config) {
|
|
125
|
-
@synchronized ([ReactNativeBlobUtilNetwork class]) {
|
|
126
|
-
if (![self.requestsTable objectForKey:taskId]) {
|
|
127
|
-
[self.rebindUploadProgressDict setValue:config forKey:taskId];
|
|
128
|
-
} else {
|
|
129
|
-
[self.requestsTable objectForKey:taskId].uploadProgressConfig = config;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
- (void) cancelRequest:(NSString *)taskId
|
|
136
|
-
{
|
|
137
|
-
NSURLSessionDataTask * task;
|
|
138
|
-
|
|
139
|
-
@synchronized ([ReactNativeBlobUtilNetwork class]) {
|
|
140
|
-
task = [self.requestsTable objectForKey:taskId].task;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (task && task.state == NSURLSessionTaskStateRunning) {
|
|
144
|
-
[task cancel];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// removing case from headers
|
|
149
|
-
+ (NSMutableDictionary *) normalizeHeaders:(NSDictionary *)headers
|
|
150
|
-
{
|
|
151
|
-
NSMutableDictionary * mheaders = [[NSMutableDictionary alloc]init];
|
|
152
|
-
for (NSString * key in headers) {
|
|
153
|
-
[mheaders setValue:[headers valueForKey:key] forKey:[key lowercaseString]];
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return mheaders;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
@end
|
|
1
|
+
//
|
|
2
|
+
// ReactNativeBlobUtilNetwork.m
|
|
3
|
+
// ReactNativeBlobUtil
|
|
4
|
+
//
|
|
5
|
+
// Created by wkh237 on 2016/6/6.
|
|
6
|
+
// Copyright © 2016 wkh237. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
#import <Foundation/Foundation.h>
|
|
11
|
+
#import "ReactNativeBlobUtilNetwork.h"
|
|
12
|
+
|
|
13
|
+
#import "ReactNativeBlobUtilConst.h"
|
|
14
|
+
#import "ReactNativeBlobUtilProgress.h"
|
|
15
|
+
|
|
16
|
+
#if __has_include(<React/RCTAssert.h>)
|
|
17
|
+
#import <React/RCTRootView.h>
|
|
18
|
+
#import <React/RCTLog.h>
|
|
19
|
+
#import <React/RCTBridge.h>
|
|
20
|
+
#else
|
|
21
|
+
#import "RCTRootView.h"
|
|
22
|
+
#import "RCTLog.h"
|
|
23
|
+
#import "RCTBridge.h"
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
////////////////////////////////////////
|
|
27
|
+
//
|
|
28
|
+
// HTTP request handler
|
|
29
|
+
//
|
|
30
|
+
////////////////////////////////////////
|
|
31
|
+
|
|
32
|
+
NSMapTable * expirationTable;
|
|
33
|
+
|
|
34
|
+
__attribute__((constructor))
|
|
35
|
+
static void initialize_tables() {
|
|
36
|
+
if (expirationTable == nil) {
|
|
37
|
+
expirationTable = [[NSMapTable alloc] init];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@implementation ReactNativeBlobUtilNetwork
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
- (id)init {
|
|
46
|
+
self = [super init];
|
|
47
|
+
if (self) {
|
|
48
|
+
self.requestsTable = [NSMapTable mapTableWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableWeakMemory];
|
|
49
|
+
|
|
50
|
+
self.taskQueue = [[NSOperationQueue alloc] init];
|
|
51
|
+
self.taskQueue.qualityOfService = NSQualityOfServiceUtility;
|
|
52
|
+
self.taskQueue.maxConcurrentOperationCount = 10;
|
|
53
|
+
self.rebindProgressDict = [NSMutableDictionary dictionary];
|
|
54
|
+
self.rebindUploadProgressDict = [NSMutableDictionary dictionary];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return self;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
+ (ReactNativeBlobUtilNetwork* _Nullable)sharedInstance {
|
|
61
|
+
static id _sharedInstance = nil;
|
|
62
|
+
static dispatch_once_t onceToken;
|
|
63
|
+
|
|
64
|
+
dispatch_once(&onceToken, ^{
|
|
65
|
+
_sharedInstance = [[self alloc] init];
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return _sharedInstance;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
- (void) sendRequest:(__weak NSDictionary * _Nullable )options
|
|
72
|
+
contentLength:(long) contentLength
|
|
73
|
+
baseModule:(ReactNativeBlobUtil * _Nullable)baseModule
|
|
74
|
+
taskId:(NSString * _Nullable)taskId
|
|
75
|
+
withRequest:(__weak NSURLRequest * _Nullable)req
|
|
76
|
+
callback:(_Nullable RCTResponseSenderBlock) callback
|
|
77
|
+
{
|
|
78
|
+
ReactNativeBlobUtilRequest *request = [[ReactNativeBlobUtilRequest alloc] init];
|
|
79
|
+
[request sendRequest:options
|
|
80
|
+
contentLength:contentLength
|
|
81
|
+
baseModule:baseModule
|
|
82
|
+
taskId:taskId
|
|
83
|
+
withRequest:req
|
|
84
|
+
taskOperationQueue:self.taskQueue
|
|
85
|
+
callback:callback];
|
|
86
|
+
|
|
87
|
+
@synchronized([ReactNativeBlobUtilNetwork class]) {
|
|
88
|
+
[self.requestsTable setObject:request forKey:taskId];
|
|
89
|
+
[self checkProgressConfigForTask:taskId];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
- (void) checkProgressConfigForTask:(NSString *)taskId {
|
|
94
|
+
//reconfig progress
|
|
95
|
+
ReactNativeBlobUtilProgress *downloadConfig = self.rebindProgressDict[taskId];
|
|
96
|
+
if (downloadConfig != nil) {
|
|
97
|
+
[self enableProgressReport:taskId config:downloadConfig];
|
|
98
|
+
[self.rebindProgressDict removeObjectForKey:taskId];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//reconfig uploadProgress
|
|
102
|
+
ReactNativeBlobUtilProgress *uploadConfig = self.rebindUploadProgressDict[taskId];
|
|
103
|
+
if (uploadConfig != nil) {
|
|
104
|
+
[self enableUploadProgress:taskId config:uploadConfig];
|
|
105
|
+
[self.rebindUploadProgressDict removeObjectForKey:taskId];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
- (void) enableProgressReport:(NSString *) taskId config:(ReactNativeBlobUtilProgress *)config
|
|
110
|
+
{
|
|
111
|
+
if (config) {
|
|
112
|
+
@synchronized ([ReactNativeBlobUtilNetwork class]) {
|
|
113
|
+
if (![self.requestsTable objectForKey:taskId]) {
|
|
114
|
+
[self.rebindProgressDict setValue:config forKey:taskId];
|
|
115
|
+
} else {
|
|
116
|
+
[self.requestsTable objectForKey:taskId].progressConfig = config;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
- (void) enableUploadProgress:(NSString *) taskId config:(ReactNativeBlobUtilProgress *)config
|
|
123
|
+
{
|
|
124
|
+
if (config) {
|
|
125
|
+
@synchronized ([ReactNativeBlobUtilNetwork class]) {
|
|
126
|
+
if (![self.requestsTable objectForKey:taskId]) {
|
|
127
|
+
[self.rebindUploadProgressDict setValue:config forKey:taskId];
|
|
128
|
+
} else {
|
|
129
|
+
[self.requestsTable objectForKey:taskId].uploadProgressConfig = config;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
- (void) cancelRequest:(NSString *)taskId
|
|
136
|
+
{
|
|
137
|
+
NSURLSessionDataTask * task;
|
|
138
|
+
|
|
139
|
+
@synchronized ([ReactNativeBlobUtilNetwork class]) {
|
|
140
|
+
task = [self.requestsTable objectForKey:taskId].task;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (task && task.state == NSURLSessionTaskStateRunning) {
|
|
144
|
+
[task cancel];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// removing case from headers
|
|
149
|
+
+ (NSMutableDictionary *) normalizeHeaders:(NSDictionary *)headers
|
|
150
|
+
{
|
|
151
|
+
NSMutableDictionary * mheaders = [[NSMutableDictionary alloc]init];
|
|
152
|
+
for (NSString * key in headers) {
|
|
153
|
+
[mheaders setValue:[headers valueForKey:key] forKey:[key lowercaseString]];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return mheaders;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@end
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ReactNativeBlobUtilProgress.h
|
|
3
|
-
// ReactNativeBlobUtil
|
|
4
|
-
//
|
|
5
|
-
// Created by Ben Hsieh on 2016/9/25.
|
|
6
|
-
// Copyright © 2016年 wkh237.github.io. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#ifndef ReactNativeBlobUtilProgress_h
|
|
10
|
-
#define ReactNativeBlobUtilProgress_h
|
|
11
|
-
|
|
12
|
-
#import <Foundation/Foundation.h>
|
|
13
|
-
|
|
14
|
-
typedef NS_ENUM(NSUInteger, ProgressType) {
|
|
15
|
-
Download,
|
|
16
|
-
Upload,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
@interface ReactNativeBlobUtilProgress : NSObject
|
|
20
|
-
|
|
21
|
-
@property (nonatomic) NSNumber * count;
|
|
22
|
-
@property (nonatomic) NSNumber * interval;
|
|
23
|
-
@property (nonatomic) NSInteger type;
|
|
24
|
-
@property (nonatomic) BOOL enable;
|
|
25
|
-
|
|
26
|
-
-(id)initWithType:(ProgressType)type interval:(NSNumber*)interval count:(NSNumber *)count;
|
|
27
|
-
-(BOOL)shouldReport:(NSNumber *) nextProgress;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@end
|
|
31
|
-
|
|
32
|
-
#endif /* ReactNativeBlobUtilProgress_h */
|
|
1
|
+
//
|
|
2
|
+
// ReactNativeBlobUtilProgress.h
|
|
3
|
+
// ReactNativeBlobUtil
|
|
4
|
+
//
|
|
5
|
+
// Created by Ben Hsieh on 2016/9/25.
|
|
6
|
+
// Copyright © 2016年 wkh237.github.io. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef ReactNativeBlobUtilProgress_h
|
|
10
|
+
#define ReactNativeBlobUtilProgress_h
|
|
11
|
+
|
|
12
|
+
#import <Foundation/Foundation.h>
|
|
13
|
+
|
|
14
|
+
typedef NS_ENUM(NSUInteger, ProgressType) {
|
|
15
|
+
Download,
|
|
16
|
+
Upload,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
@interface ReactNativeBlobUtilProgress : NSObject
|
|
20
|
+
|
|
21
|
+
@property (nonatomic) NSNumber * count;
|
|
22
|
+
@property (nonatomic) NSNumber * interval;
|
|
23
|
+
@property (nonatomic) NSInteger type;
|
|
24
|
+
@property (nonatomic) BOOL enable;
|
|
25
|
+
|
|
26
|
+
-(id)initWithType:(ProgressType)type interval:(NSNumber*)interval count:(NSNumber *)count;
|
|
27
|
+
-(BOOL)shouldReport:(NSNumber *) nextProgress;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@end
|
|
31
|
+
|
|
32
|
+
#endif /* ReactNativeBlobUtilProgress_h */
|