Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronized tables, separated requests and network logic and other... #8

Merged
merged 23 commits into from
Apr 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ RNFetchBlob
console.log('The file saved to ', res.path())
// Beware that when using a file path as Image source on Android,
// you must prepend "file://"" before the file path
imageView = <Image source={{ uri : Platform.OS === 'android' ? 'file://' + res.path() : '' + res.path() }}/>
imageView = <Image source={{ uri : Platform.OS === 'android' ? 'file://' + res.path() : '' + res.path() }}/>
})
```

Expand Down
18 changes: 17 additions & 1 deletion android.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,25 @@ function addCompleteDownload(config) {
return Promise.reject('RNFetchBlob.android.addCompleteDownload only supports Android.')
}

function getSDCardDir() {
if(Platform.OS === 'android')
return RNFetchBlob.getSDCardDir()
else
return Promise.reject('RNFetchBlob.android.getSDCardDir only supports Android.')
}

function getSDCardApplicationDir() {
if(Platform.OS === 'android')
return RNFetchBlob.getSDCardApplicationDir()
else
return Promise.reject('RNFetchBlob.android.getSDCardApplicationDir only supports Android.')
}


export default {
actionViewIntent,
getContentIntent,
addCompleteDownload
addCompleteDownload,
getSDCardDir,
getSDCardApplicationDir,
}
15 changes: 10 additions & 5 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public void run() {
RNFetchBlobFS.createFileASCII(path, dataArray, promise);
}
});

}

@ReactMethod
Expand Down Expand Up @@ -164,7 +163,6 @@ public void run() {
RNFetchBlobFS.cp(path, dest, callback);
}
});

}

@ReactMethod
Expand Down Expand Up @@ -225,7 +223,6 @@ public void run() {
RNFetchBlobFS.writeFile(path, encoding, data, append, promise);
}
});

}

@ReactMethod
Expand Down Expand Up @@ -260,7 +257,6 @@ public void run() {
new RNFetchBlobFS(ctx).scanFile(p, m, callback);
}
});

}

@ReactMethod
Expand Down Expand Up @@ -331,7 +327,7 @@ public void enableUploadProgressReport(String taskId, int interval, int count) {
@ReactMethod
public void fetchBlob(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, final Callback callback) {
new RNFetchBlobReq(options, taskId, method, url, headers, body, null, mClient, callback).run();
}
}

@ReactMethod
public void fetchBlobForm(ReadableMap options, String taskId, String method, String url, ReadableMap headers, ReadableArray body, final Callback callback) {
Expand Down Expand Up @@ -377,4 +373,13 @@ public void addCompleteDownload (ReadableMap config, Promise promise) {

}

@ReactMethod
public void getSDCardDir(Promise promise) {
RNFetchBlobFS.getSDCardDir(promise);
}

@ReactMethod
public void getSDCardApplicationDir(Promise promise) {
RNFetchBlobFS.getSDCardApplicationDir(this.getReactApplicationContext(), promise);
}
}
28 changes: 27 additions & 1 deletion android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,38 @@ static Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {
state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED)) {
res.put("SDCardDir", Environment.getExternalStorageDirectory().getAbsolutePath());
res.put("SDCardApplicationDir", ctx.getExternalFilesDir(null).getParentFile().getAbsolutePath());
try {
res.put("SDCardApplicationDir", ctx.getExternalFilesDir(null).getParentFile().getAbsolutePath());
} catch(Exception e) {
res.put("SDCardApplicationDir", "");
}
}
res.put("MainBundleDir", ctx.getApplicationInfo().dataDir);
return res;
}

static public void getSDCardDir(Promise promise) {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
promise.resolve(Environment.getExternalStorageDirectory().getAbsolutePath());
} else {
promise.reject("RNFetchBlob.getSDCardDir", "External storage not mounted");
}

}

static public void getSDCardApplicationDir(ReactApplicationContext ctx, Promise promise) {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
try {
final String path = ctx.getExternalFilesDir(null).getParentFile().getAbsolutePath();
promise.resolve(path);
} catch (Exception e) {
promise.reject("RNFetchBlob.getSDCardApplicationDir", e.getLocalizedMessage());
}
} else {
promise.reject("RNFetchBlob.getSDCardApplicationDir", "External storage not mounted");
}
}

/**
* Static method that returns a temp file path
* @param taskId An unique string for identify
Expand Down
31 changes: 20 additions & 11 deletions fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ import RNFetchBlobFile from './class/RNFetchBlobFile'
const RNFetchBlob: RNFetchBlobNative = NativeModules.RNFetchBlob

const dirs = {
DocumentDir: RNFetchBlob.DocumentDir,
CacheDir: RNFetchBlob.CacheDir,
PictureDir: RNFetchBlob.PictureDir,
MusicDir: RNFetchBlob.MusicDir,
MovieDir: RNFetchBlob.MovieDir,
DownloadDir: RNFetchBlob.DownloadDir,
DCIMDir: RNFetchBlob.DCIMDir,
SDCardDir: RNFetchBlob.SDCardDir,
SDCardApplicationDir: RNFetchBlob.SDCardApplicationDir,
MainBundleDir: RNFetchBlob.MainBundleDir,
LibraryDir: RNFetchBlob.LibraryDir
DocumentDir : RNFetchBlob.DocumentDir,
CacheDir : RNFetchBlob.CacheDir,
PictureDir : RNFetchBlob.PictureDir,
MusicDir : RNFetchBlob.MusicDir,
MovieDir : RNFetchBlob.MovieDir,
DownloadDir : RNFetchBlob.DownloadDir,
DCIMDir : RNFetchBlob.DCIMDir,
get SDCardDir() {
console.warn('SDCardDir as a constant is deprecated and will be removed in feature release. ' +
'Use RNFetchBlob.android.getSDCardDir():Promise instead.');
return RNFetchBlob.SDCardDir;
},
get SDCardApplicationDir() {
console.warn('SDCardApplicationDir as a constant is deprecated and will be removed in feature release. ' +
'Use RNFetchBlob.android.getSDCardApplicationDir():Promise instead. ' +
'This variable can be empty on error in native code.');
return RNFetchBlob.SDCardApplicationDir;
},
MainBundleDir : RNFetchBlob.MainBundleDir,
LibraryDir : RNFetchBlob.LibraryDir
}

function addCode(code: string, error: Error): Error {
Expand Down
8 changes: 7 additions & 1 deletion ios/RNFetchBlob.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
8C4801A6200CF71700FED7ED /* RNFetchBlobRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C4801A5200CF71700FED7ED /* RNFetchBlobRequest.m */; };
A158F4271D052E49006FFD38 /* RNFetchBlobFS.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F4261D052E49006FFD38 /* RNFetchBlobFS.m */; };
A158F42D1D0535BB006FFD38 /* RNFetchBlobConst.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F42C1D0535BB006FFD38 /* RNFetchBlobConst.m */; };
A158F4301D0539DB006FFD38 /* RNFetchBlobNetwork.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */; };
Expand All @@ -29,6 +30,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
8C4801A4200CF71700FED7ED /* RNFetchBlobRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobRequest.h; sourceTree = "<group>"; };
8C4801A5200CF71700FED7ED /* RNFetchBlobRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNFetchBlobRequest.m; sourceTree = "<group>"; };
A158F4261D052E49006FFD38 /* RNFetchBlobFS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNFetchBlobFS.m; sourceTree = "<group>"; };
A158F4281D052E57006FFD38 /* RNFetchBlobFS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobFS.h; sourceTree = "<group>"; };
A158F4291D0534A9006FFD38 /* RNFetchBlobConst.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobConst.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -71,8 +74,10 @@
A1F950181D7E9134002A95A6 /* IOS7Polyfill.h */,
A1AAE2981D300E4D0051D11C /* RNFetchBlobReqBuilder.m */,
A1AAE2971D300E3E0051D11C /* RNFetchBlobReqBuilder.h */,
A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */,
A158F42E1D0539CE006FFD38 /* RNFetchBlobNetwork.h */,
A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */,
8C4801A4200CF71700FED7ED /* RNFetchBlobRequest.h */,
8C4801A5200CF71700FED7ED /* RNFetchBlobRequest.m */,
A158F42C1D0535BB006FFD38 /* RNFetchBlobConst.m */,
A158F4291D0534A9006FFD38 /* RNFetchBlobConst.h */,
A158F4281D052E57006FFD38 /* RNFetchBlobFS.h */,
Expand Down Expand Up @@ -149,6 +154,7 @@
buildActionMask = 2147483647;
files = (
A166D1AA1CE0647A00273590 /* RNFetchBlob.h in Sources */,
8C4801A6200CF71700FED7ED /* RNFetchBlobRequest.m in Sources */,
A158F42D1D0535BB006FFD38 /* RNFetchBlobConst.m in Sources */,
A158F4271D052E49006FFD38 /* RNFetchBlobFS.m in Sources */,
A158F4301D0539DB006FFD38 /* RNFetchBlobNetwork.m in Sources */,
Expand Down
1 change: 0 additions & 1 deletion ios/RNFetchBlob/RNFetchBlob.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
@property (retain) UIDocumentInteractionController * documentController;

+ (RCTBridge *)getRCTBridge;
+ (void) checkExpiredSessions;

@end

Expand Down
24 changes: 16 additions & 8 deletions ios/RNFetchBlob/RNFetchBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (dispatch_queue_t) methodQueue {

+ (RCTBridge *)getRCTBridge
{
RCTRootView * rootView = [[UIApplication sharedApplication] keyWindow].rootViewController.view;
RCTRootView * rootView = (RCTRootView*) [[UIApplication sharedApplication] keyWindow].rootViewController.view;
return rootView.bridge;
}

Expand Down Expand Up @@ -96,8 +96,12 @@ - (NSDictionary *)constantsToExport
// send HTTP request
else
{
RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
[utils sendRequest:options contentLength:bodyLength bridge:self.bridge taskId:taskId withRequest:req callback:callback];
[[RNFetchBlobNetwork sharedInstance] sendRequest:options
contentLength:bodyLength
bridge:self.bridge
taskId:taskId
withRequest:req
callback:callback];
}
}];

Expand Down Expand Up @@ -128,8 +132,12 @@ - (NSDictionary *)constantsToExport
// send HTTP request
else
{
__block RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
[utils sendRequest:options contentLength:bodyLength bridge:self.bridge taskId:taskId withRequest:req callback:callback];
[[RNFetchBlobNetwork sharedInstance] sendRequest:options
contentLength:bodyLength
bridge:self.bridge
taskId:taskId
withRequest:req
callback:callback];
}
}];
}
Expand Down Expand Up @@ -518,7 +526,7 @@ - (NSDictionary *)constantsToExport

#pragma mark - net.cancelRequest
RCT_EXPORT_METHOD(cancelRequest:(NSString *)taskId callback:(RCTResponseSenderBlock)callback) {
[RNFetchBlobNetwork cancelRequest:taskId];
[[RNFetchBlobNetwork sharedInstance] cancelRequest:taskId];
callback(@[[NSNull null], taskId]);

}
Expand All @@ -528,14 +536,14 @@ - (NSDictionary *)constantsToExport
{

RNFetchBlobProgress * cfg = [[RNFetchBlobProgress alloc] initWithType:Download interval:interval count:count];
[RNFetchBlobNetwork enableProgressReport:taskId config:cfg];
[[RNFetchBlobNetwork sharedInstance] enableProgressReport:taskId config:cfg];
}

#pragma mark - net.enableUploadProgressReport
RCT_EXPORT_METHOD(enableUploadProgressReport:(NSString *)taskId interval:(nonnull NSNumber*)interval count:(nonnull NSNumber*)count)
{
RNFetchBlobProgress * cfg = [[RNFetchBlobProgress alloc] initWithType:Upload interval:interval count:count];
[RNFetchBlobNetwork enableUploadProgress:taskId config:cfg];
[[RNFetchBlobNetwork sharedInstance] enableUploadProgress:taskId config:cfg];
}

#pragma mark - fs.slice
Expand Down
56 changes: 28 additions & 28 deletions ios/RNFetchBlobConst.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@
//
#import "RNFetchBlobConst.h"

extern NSString *const FILE_PREFIX = @"RNFetchBlob-file://";
extern NSString *const ASSET_PREFIX = @"bundle-assets://";
extern NSString *const AL_PREFIX = @"assets-library://";
NSString *const FILE_PREFIX = @"RNFetchBlob-file://";
NSString *const ASSET_PREFIX = @"bundle-assets://";
NSString *const AL_PREFIX = @"assets-library://";

// fetch configs
extern NSString *const CONFIG_USE_TEMP = @"fileCache";
extern NSString *const CONFIG_FILE_PATH = @"path";
extern NSString *const CONFIG_FILE_EXT = @"appendExt";
extern NSString *const CONFIG_TRUSTY = @"trusty";
extern NSString *const CONFIG_INDICATOR = @"indicator";
extern NSString *const CONFIG_KEY = @"key";
extern NSString *const CONFIG_EXTRA_BLOB_CTYPE = @"binaryContentTypes";
NSString *const CONFIG_USE_TEMP = @"fileCache";
NSString *const CONFIG_FILE_PATH = @"path";
NSString *const CONFIG_FILE_EXT = @"appendExt";
NSString *const CONFIG_TRUSTY = @"trusty";
NSString *const CONFIG_INDICATOR = @"indicator";
NSString *const CONFIG_KEY = @"key";
NSString *const CONFIG_EXTRA_BLOB_CTYPE = @"binaryContentTypes";

extern NSString *const EVENT_STATE_CHANGE = @"RNFetchBlobState";
extern NSString *const EVENT_SERVER_PUSH = @"RNFetchBlobServerPush";
extern NSString *const EVENT_PROGRESS = @"RNFetchBlobProgress";
extern NSString *const EVENT_PROGRESS_UPLOAD = @"RNFetchBlobProgress-upload";
extern NSString *const EVENT_EXPIRE = @"RNFetchBlobExpire";
NSString *const EVENT_STATE_CHANGE = @"RNFetchBlobState";
NSString *const EVENT_SERVER_PUSH = @"RNFetchBlobServerPush";
NSString *const EVENT_PROGRESS = @"RNFetchBlobProgress";
NSString *const EVENT_PROGRESS_UPLOAD = @"RNFetchBlobProgress-upload";
NSString *const EVENT_EXPIRE = @"RNFetchBlobExpire";

extern NSString *const MSG_EVENT = @"RNFetchBlobMessage";
extern NSString *const MSG_EVENT_LOG = @"log";
extern NSString *const MSG_EVENT_WARN = @"warn";
extern NSString *const MSG_EVENT_ERROR = @"error";
extern NSString *const FS_EVENT_DATA = @"data";
extern NSString *const FS_EVENT_END = @"end";
extern NSString *const FS_EVENT_WARN = @"warn";
extern NSString *const FS_EVENT_ERROR = @"error";
NSString *const MSG_EVENT = @"RNFetchBlobMessage";
NSString *const MSG_EVENT_LOG = @"log";
NSString *const MSG_EVENT_WARN = @"warn";
NSString *const MSG_EVENT_ERROR = @"error";
NSString *const FS_EVENT_DATA = @"data";
NSString *const FS_EVENT_END = @"end";
NSString *const FS_EVENT_WARN = @"warn";
NSString *const FS_EVENT_ERROR = @"error";

extern NSString *const KEY_REPORT_PROGRESS = @"reportProgress";
extern NSString *const KEY_REPORT_UPLOAD_PROGRESS = @"reportUploadProgress";
NSString *const KEY_REPORT_PROGRESS = @"reportProgress";
NSString *const KEY_REPORT_UPLOAD_PROGRESS = @"reportUploadProgress";

// response type
extern NSString *const RESP_TYPE_BASE64 = @"base64";
extern NSString *const RESP_TYPE_UTF8 = @"utf8";
extern NSString *const RESP_TYPE_PATH = @"path";
NSString *const RESP_TYPE_BASE64 = @"base64";
NSString *const RESP_TYPE_UTF8 = @"utf8";
NSString *const RESP_TYPE_PATH = @"path";
4 changes: 2 additions & 2 deletions ios/RNFetchBlobFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
NSString * streamId;
}

@property (nonatomic) NSOutputStream * outStream;
@property (nonatomic) NSInputStream * inStream;
@property (nonatomic) NSOutputStream * _Nullable outStream;
@property (nonatomic) NSInputStream * _Nullable inStream;
@property (strong, nonatomic) RCTResponseSenderBlock callback;
@property (nonatomic) RCTBridge * bridge;
@property (nonatomic) NSString * encoding;
Expand Down
Loading