@robylon/react-native-sdk 2.0.31-staging.3 → 2.0.31-staging.5
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/ios/RobylonDownloadModule.h +5 -0
- package/ios/RobylonDownloadModule.m +124 -0
- package/lib/commonjs/utils/fileDownload.js +1 -1
- package/lib/commonjs/utils/fileDownload.js.map +1 -1
- package/lib/commonjs/versions/version.staging.js +1 -1
- package/lib/module/utils/fileDownload.js +1 -1
- package/lib/module/utils/fileDownload.js.map +1 -1
- package/lib/module/versions/version.staging.js +1 -1
- package/lib/typescript/utils/fileDownload.d.ts.map +1 -1
- package/lib/typescript/versions/version.staging.d.ts +1 -1
- package/package.json +1 -1
- package/robylon-react-native-sdk.podspec +18 -0
- package/src/utils/fileDownload.ts +56 -13
- package/src/versions/version.staging.ts +1 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#import "RobylonDownloadModule.h"
|
|
2
|
+
|
|
3
|
+
#import <React/RCTUtils.h>
|
|
4
|
+
#import <UIKit/UIKit.h>
|
|
5
|
+
|
|
6
|
+
@implementation RobylonDownloadModule
|
|
7
|
+
|
|
8
|
+
RCT_EXPORT_MODULE();
|
|
9
|
+
|
|
10
|
+
- (dispatch_queue_t)methodQueue
|
|
11
|
+
{
|
|
12
|
+
return dispatch_get_main_queue();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
RCT_REMAP_METHOD(downloadFile,
|
|
16
|
+
downloadFileWithUrl:(NSString *)url
|
|
17
|
+
filename:(NSString *)filename
|
|
18
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
19
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
20
|
+
{
|
|
21
|
+
if (url == nil || url.length == 0) {
|
|
22
|
+
reject(@"INVALID_URL", @"Download URL is missing", nil);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
NSURL *downloadURL = [NSURL URLWithString:url];
|
|
27
|
+
if (downloadURL == nil) {
|
|
28
|
+
reject(@"INVALID_URL", @"Download URL is invalid", nil);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
NSURLSessionDownloadTask *task = [[NSURLSession sharedSession]
|
|
33
|
+
downloadTaskWithURL:downloadURL
|
|
34
|
+
completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
35
|
+
if (error != nil) {
|
|
36
|
+
reject(@"DOWNLOAD_FAILED", @"Failed to download file", error);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (location == nil) {
|
|
41
|
+
reject(@"DOWNLOAD_FAILED", @"Downloaded file location is empty", nil);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
NSString *resolvedName = [self resolvedFileName:filename response:response url:downloadURL];
|
|
46
|
+
NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:resolvedName];
|
|
47
|
+
NSURL *targetURL = [NSURL fileURLWithPath:targetPath];
|
|
48
|
+
|
|
49
|
+
[[NSFileManager defaultManager] removeItemAtURL:targetURL error:nil];
|
|
50
|
+
|
|
51
|
+
NSError *moveError = nil;
|
|
52
|
+
[[NSFileManager defaultManager] moveItemAtURL:location toURL:targetURL error:&moveError];
|
|
53
|
+
if (moveError != nil) {
|
|
54
|
+
reject(@"FILE_MOVE_FAILED", @"Failed to move downloaded file", moveError);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
59
|
+
UIViewController *rootViewController = RCTPresentedViewController();
|
|
60
|
+
if (rootViewController == nil) {
|
|
61
|
+
reject(@"VIEW_CONTROLLER_MISSING", @"Unable to open iOS share sheet", nil);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
UIActivityViewController *activityController =
|
|
66
|
+
[[UIActivityViewController alloc] initWithActivityItems:@[ targetURL ] applicationActivities:nil];
|
|
67
|
+
|
|
68
|
+
UIPopoverPresentationController *popover = activityController.popoverPresentationController;
|
|
69
|
+
if (popover != nil) {
|
|
70
|
+
popover.sourceView = rootViewController.view;
|
|
71
|
+
popover.sourceRect = CGRectMake(rootViewController.view.bounds.size.width / 2.0,
|
|
72
|
+
rootViewController.view.bounds.size.height / 2.0,
|
|
73
|
+
1,
|
|
74
|
+
1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
[rootViewController presentViewController:activityController animated:YES completion:^{
|
|
78
|
+
resolve(resolvedName);
|
|
79
|
+
}];
|
|
80
|
+
});
|
|
81
|
+
}];
|
|
82
|
+
|
|
83
|
+
[task resume];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
- (NSString *)resolvedFileName:(NSString *)filename response:(NSURLResponse *)response url:(NSURL *)url
|
|
87
|
+
{
|
|
88
|
+
NSString *cleanName = [self sanitizedName:filename];
|
|
89
|
+
if (cleanName.length > 0) {
|
|
90
|
+
NSString *urlExtension = [url.path pathExtension];
|
|
91
|
+
NSString *nameExtension = [cleanName pathExtension];
|
|
92
|
+
if (nameExtension.length == 0 && urlExtension.length > 0) {
|
|
93
|
+
return [cleanName stringByAppendingFormat:@".%@", urlExtension];
|
|
94
|
+
}
|
|
95
|
+
return cleanName;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
NSString *suggested = [self sanitizedName:response.suggestedFilename];
|
|
99
|
+
if (suggested.length > 0) {
|
|
100
|
+
return suggested;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
NSString *lastPath = [self sanitizedName:url.lastPathComponent];
|
|
104
|
+
if (lastPath.length > 0) {
|
|
105
|
+
return lastPath;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return [NSString stringWithFormat:@"download-%f", [[NSDate date] timeIntervalSince1970]];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
- (NSString *)sanitizedName:(NSString *)name
|
|
112
|
+
{
|
|
113
|
+
if (name == nil || name.length == 0) {
|
|
114
|
+
return @"";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
NSCharacterSet *invalidCharacters =
|
|
118
|
+
[NSCharacterSet characterSetWithCharactersInString:@"/\\?%*|\"<>:"];
|
|
119
|
+
NSArray<NSString *> *parts = [name componentsSeparatedByCharactersInSet:invalidCharacters];
|
|
120
|
+
NSString *joined = [parts componentsJoinedByString:@"_"];
|
|
121
|
+
return [joined stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@end
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.handleDownloadRequest=exports.downloadFile=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _reactNative=require("react-native");var _logger=require("./logger");var normalizeUrl=function normalizeUrl(url){return url==null?void 0:url.trim();};var
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.handleDownloadRequest=exports.downloadFile=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _reactNative=require("react-native");var _logger=require("./logger");var normalizeUrl=function normalizeUrl(url){return url==null?void 0:url.trim();};var getUrlPathTail=function getUrlPathTail(url){var _url$split,_cleanedUrl$split,_cleanedUrl$split$pop;var cleanedUrl=(url==null?void 0:(_url$split=url.split("?"))==null?void 0:_url$split[0])||"";return(cleanedUrl==null?void 0:(_cleanedUrl$split=cleanedUrl.split("/"))==null?void 0:(_cleanedUrl$split$pop=_cleanedUrl$split.pop())==null?void 0:_cleanedUrl$split$pop.trim())||"";};var getExtensionFromName=function getExtensionFromName(name){if(!(name!=null&&name.includes(".")))return"";return name.substring(name.lastIndexOf("."));};var resolveDownloadFileName=function resolveDownloadFileName(filename,url){var trimmedName=filename==null?void 0:filename.trim();if(trimmedName){var sanitizedName=trimmedName.replace(/[<>:"/\\|?*\x00-\x1F]/g,"_");var urlExtension=getExtensionFromName(getUrlPathTail(url));if(getExtensionFromName(sanitizedName)||!urlExtension)return sanitizedName;return`${sanitizedName}${urlExtension}`;}var tailName=getUrlPathTail(url);if(tailName)return tailName.replace(/[<>:"/\\|?*\x00-\x1F]/g,"_");return`download-robylon-${Date.now()}`;};var isValidHttpUrl=function isValidHttpUrl(url){return /^https?:\/\//i.test(url);};var getNativeDownloadModule=function getNativeDownloadModule(){return(_reactNative.NativeModules==null?void 0:_reactNative.NativeModules.RobylonDownloadModule)||null;};var openUrlWithFallback=function(){var _ref=(0,_asyncToGenerator2.default)(function*(url){try{yield _reactNative.Linking.openURL(url);return;}catch(primaryError){_logger.logger.warn("Primary URL open failed, trying browser fallback",{url:url,primaryError:primaryError instanceof Error?primaryError==null?void 0:primaryError.message:String(primaryError)});}yield _reactNative.Linking.openURL(`https://docs.google.com/viewer?url=${encodeURIComponent(url)}`);});return function openUrlWithFallback(_x){return _ref.apply(this,arguments);};}();var downloadOnAndroid=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(url,filename){var module=getNativeDownloadModule();if(!(module!=null&&module.downloadFile)){throw new Error("Robylon native download module is not linked on Android");}yield module.downloadFile(url,filename);});return function downloadOnAndroid(_x2,_x3){return _ref2.apply(this,arguments);};}();var downloadOniOS=function(){var _ref3=(0,_asyncToGenerator2.default)(function*(url,filename){var module=getNativeDownloadModule();if(!(module!=null&&module.downloadFile)){throw new Error("Robylon native download module is not linked on iOS");}yield module.downloadFile(url,filename);});return function downloadOniOS(_x4,_x5){return _ref3.apply(this,arguments);};}();var downloadWithNativeStorage=function(){var _ref4=(0,_asyncToGenerator2.default)(function*(url,filename){var safeName=resolveDownloadFileName(filename,url);if(_reactNative.Platform.OS==="android"){yield downloadOnAndroid(url,safeName);return;}if(_reactNative.Platform.OS==="ios"){yield downloadOniOS(url,safeName);return;}yield openUrlWithFallback(url);});return function downloadWithNativeStorage(_x6,_x7){return _ref4.apply(this,arguments);};}();var shouldUseInPlaceDownload=function shouldUseInPlaceDownload(downloadRequest){return(downloadRequest==null?void 0:downloadRequest.inPlace)===true;};var downloadFile=exports.downloadFile=function(){var _ref5=(0,_asyncToGenerator2.default)(function*(url,filename,inPlace){try{var normalizedUrl=normalizeUrl(url);_logger.logger.debug("Initiating file download",{url:normalizedUrl,filename:filename});if(!normalizedUrl||typeof normalizedUrl!=="string"){throw new Error("Invalid URL provided for download");}if(!isValidHttpUrl(normalizedUrl)){throw new Error("Download URL must be an http/https URL");}if(inPlace){try{yield downloadWithNativeStorage(normalizedUrl,filename);_logger.logger.debug("File downloaded with native storage flow");}catch(nativeDownloadError){_logger.logger.warn("Native download failed, falling back to URL open",{url:normalizedUrl,nativeDownloadError:nativeDownloadError instanceof Error?nativeDownloadError==null?void 0:nativeDownloadError.message:String(nativeDownloadError)});yield openUrlWithFallback(normalizedUrl);_logger.logger.debug("File download opened with fallback browser flow");}return;}yield openUrlWithFallback(normalizedUrl);_logger.logger.debug("File download opened with legacy URL flow");}catch(error){_logger.logger.error("File download failed",{url:url,filename:filename,error:error instanceof Error?error==null?void 0:error.message:String(error)});throw error;}});return function downloadFile(_x8,_x9,_x10){return _ref5.apply(this,arguments);};}();var handleDownloadRequest=exports.handleDownloadRequest=function(){var _ref6=(0,_asyncToGenerator2.default)(function*(downloadRequest){var url=downloadRequest.url,filename=downloadRequest.filename;if(!url){_logger.logger.error("Download request missing URL");return;}try{yield downloadFile(url,filename,shouldUseInPlaceDownload(downloadRequest));}catch(error){_logger.logger.error("Failed to handle download request",{downloadRequest:downloadRequest,error:error});}});return function handleDownloadRequest(_x11){return _ref6.apply(this,arguments);};}();
|
|
2
2
|
//# sourceMappingURL=fileDownload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_logger","normalizeUrl","url","trim","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_logger","normalizeUrl","url","trim","getUrlPathTail","_url$split","_cleanedUrl$split","_cleanedUrl$split$pop","cleanedUrl","split","pop","getExtensionFromName","name","includes","substring","lastIndexOf","resolveDownloadFileName","filename","trimmedName","sanitizedName","replace","urlExtension","tailName","Date","now","isValidHttpUrl","test","getNativeDownloadModule","NativeModules","RobylonDownloadModule","openUrlWithFallback","_ref","_asyncToGenerator2","default","Linking","openURL","primaryError","logger","warn","Error","message","String","encodeURIComponent","_x","apply","arguments","downloadOnAndroid","_ref2","module","downloadFile","_x2","_x3","downloadOniOS","_ref3","_x4","_x5","downloadWithNativeStorage","_ref4","safeName","Platform","OS","_x6","_x7","shouldUseInPlaceDownload","downloadRequest","inPlace","exports","_ref5","normalizedUrl","debug","nativeDownloadError","error","_x8","_x9","_x10","handleDownloadRequest","_ref6","_x11"],"sourceRoot":"../../../src","sources":["utils/fileDownload.ts"],"mappings":"wSAKA,IAAAA,YAAA,CAAAC,OAAA,iBACA,IAAAC,OAAA,CAAAD,OAAA,aAQA,GAAM,CAAAE,YAAY,CAAG,QAAf,CAAAA,YAAYA,CAAIC,GAAW,CAAa,CAC5C,MAAO,CAAAA,GAAG,cAAHA,GAAG,CAAEC,IAAI,CAAC,CAAC,CACpB,CAAC,CAED,GAAM,CAAAC,cAAc,CAAG,QAAjB,CAAAA,cAAcA,CAAIF,GAAY,CAAa,KAAAG,UAAA,CAAAC,iBAAA,CAAAC,qBAAA,CAC/C,GAAM,CAAAC,UAAU,CAAG,CAAAN,GAAG,eAAAG,UAAA,CAAHH,GAAG,CAAEO,KAAK,CAAC,GAAG,CAAC,eAAfJ,UAAA,CAAkB,CAAC,CAAC,GAAI,EAAE,CAC7C,MAAO,CAAAG,UAAU,eAAAF,iBAAA,CAAVE,UAAU,CAAEC,KAAK,CAAC,GAAG,CAAC,gBAAAF,qBAAA,CAAtBD,iBAAA,CAAwBI,GAAG,CAAC,CAAC,eAA7BH,qBAAA,CAA+BJ,IAAI,CAAC,CAAC,GAA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C,KAAK,CAAGgC,KAAK,cAALA,KAAK,CAAE/B,OAAO,CAAGC,MAAM,CAAC8B,KAAK,CAC/D,CAAC,CAAC,CACF,KAAM,CAAAA,KAAK,CACb,CACF,CAAC,iBA9CY,CAAAtB,YAAYA,CAAAuB,GAAA,CAAAC,GAAA,CAAAC,IAAA,SAAAP,KAAA,CAAAvB,KAAA,MAAAC,SAAA,OA8CxB,CAMM,GAAM,CAAA8B,qBAAqB,CAAAT,OAAA,CAAAS,qBAAA,gBAAAC,KAAA,IAAA5C,kBAAA,CAAAC,OAAA,EAAG,UACnC+B,eAAgC,CACd,CAClB,GAAQ,CAAA9D,GAAG,CAAe8D,eAAe,CAAjC9D,GAAG,CAAEe,QAAQ,CAAK+C,eAAe,CAA5B/C,QAAQ,CAErB,GAAI,CAACf,GAAG,CAAE,CACRmC,cAAM,CAACkC,KAAK,CAAC,8BAA8B,CAAC,CAC5C,OACF,CAEA,GAAI,CACF,KAAM,CAAAtB,YAAY,CAChB/C,GAAG,CACHe,QAAQ,CACR8C,wBAAwB,CAACC,eAAe,CAC1C,CAAC,CACH,CAAE,MAAOO,KAAK,CAAE,CACdlC,cAAM,CAACkC,KAAK,CAAC,mCAAmC,CAAE,CAChDP,eAAe,CAAfA,eAAe,CACfO,KAAK,CAALA,KACF,CAAC,CAAC,CAEJ,CACF,CAAC,iBAvBY,CAAAI,qBAAqBA,CAAAE,IAAA,SAAAD,KAAA,CAAAhC,KAAA,MAAAC,SAAA,OAuBjC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:true});exports.SDK_VERSION=void 0;var SDK_VERSION=exports.SDK_VERSION='2.0.31-staging.
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:true});exports.SDK_VERSION=void 0;var SDK_VERSION=exports.SDK_VERSION='2.0.31-staging.5';
|
|
2
2
|
//# sourceMappingURL=version.staging.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.handleDownloadRequest=exports.downloadFile=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _reactNative=require("react-native");var _logger=require("./logger");var normalizeUrl=function normalizeUrl(url){return url==null?void 0:url.trim();};var
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.handleDownloadRequest=exports.downloadFile=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _reactNative=require("react-native");var _logger=require("./logger");var normalizeUrl=function normalizeUrl(url){return url==null?void 0:url.trim();};var getUrlPathTail=function getUrlPathTail(url){var _url$split,_cleanedUrl$split,_cleanedUrl$split$pop;var cleanedUrl=(url==null?void 0:(_url$split=url.split("?"))==null?void 0:_url$split[0])||"";return(cleanedUrl==null?void 0:(_cleanedUrl$split=cleanedUrl.split("/"))==null?void 0:(_cleanedUrl$split$pop=_cleanedUrl$split.pop())==null?void 0:_cleanedUrl$split$pop.trim())||"";};var getExtensionFromName=function getExtensionFromName(name){if(!(name!=null&&name.includes(".")))return"";return name.substring(name.lastIndexOf("."));};var resolveDownloadFileName=function resolveDownloadFileName(filename,url){var trimmedName=filename==null?void 0:filename.trim();if(trimmedName){var sanitizedName=trimmedName.replace(/[<>:"/\\|?*\x00-\x1F]/g,"_");var urlExtension=getExtensionFromName(getUrlPathTail(url));if(getExtensionFromName(sanitizedName)||!urlExtension)return sanitizedName;return`${sanitizedName}${urlExtension}`;}var tailName=getUrlPathTail(url);if(tailName)return tailName.replace(/[<>:"/\\|?*\x00-\x1F]/g,"_");return`download-robylon-${Date.now()}`;};var isValidHttpUrl=function isValidHttpUrl(url){return /^https?:\/\//i.test(url);};var getNativeDownloadModule=function getNativeDownloadModule(){return(_reactNative.NativeModules==null?void 0:_reactNative.NativeModules.RobylonDownloadModule)||null;};var openUrlWithFallback=function(){var _ref=(0,_asyncToGenerator2.default)(function*(url){try{yield _reactNative.Linking.openURL(url);return;}catch(primaryError){_logger.logger.warn("Primary URL open failed, trying browser fallback",{url:url,primaryError:primaryError instanceof Error?primaryError==null?void 0:primaryError.message:String(primaryError)});}yield _reactNative.Linking.openURL(`https://docs.google.com/viewer?url=${encodeURIComponent(url)}`);});return function openUrlWithFallback(_x){return _ref.apply(this,arguments);};}();var downloadOnAndroid=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(url,filename){var module=getNativeDownloadModule();if(!(module!=null&&module.downloadFile)){throw new Error("Robylon native download module is not linked on Android");}yield module.downloadFile(url,filename);});return function downloadOnAndroid(_x2,_x3){return _ref2.apply(this,arguments);};}();var downloadOniOS=function(){var _ref3=(0,_asyncToGenerator2.default)(function*(url,filename){var module=getNativeDownloadModule();if(!(module!=null&&module.downloadFile)){throw new Error("Robylon native download module is not linked on iOS");}yield module.downloadFile(url,filename);});return function downloadOniOS(_x4,_x5){return _ref3.apply(this,arguments);};}();var downloadWithNativeStorage=function(){var _ref4=(0,_asyncToGenerator2.default)(function*(url,filename){var safeName=resolveDownloadFileName(filename,url);if(_reactNative.Platform.OS==="android"){yield downloadOnAndroid(url,safeName);return;}if(_reactNative.Platform.OS==="ios"){yield downloadOniOS(url,safeName);return;}yield openUrlWithFallback(url);});return function downloadWithNativeStorage(_x6,_x7){return _ref4.apply(this,arguments);};}();var shouldUseInPlaceDownload=function shouldUseInPlaceDownload(downloadRequest){return(downloadRequest==null?void 0:downloadRequest.inPlace)===true;};var downloadFile=exports.downloadFile=function(){var _ref5=(0,_asyncToGenerator2.default)(function*(url,filename,inPlace){try{var normalizedUrl=normalizeUrl(url);_logger.logger.debug("Initiating file download",{url:normalizedUrl,filename:filename});if(!normalizedUrl||typeof normalizedUrl!=="string"){throw new Error("Invalid URL provided for download");}if(!isValidHttpUrl(normalizedUrl)){throw new Error("Download URL must be an http/https URL");}if(inPlace){try{yield downloadWithNativeStorage(normalizedUrl,filename);_logger.logger.debug("File downloaded with native storage flow");}catch(nativeDownloadError){_logger.logger.warn("Native download failed, falling back to URL open",{url:normalizedUrl,nativeDownloadError:nativeDownloadError instanceof Error?nativeDownloadError==null?void 0:nativeDownloadError.message:String(nativeDownloadError)});yield openUrlWithFallback(normalizedUrl);_logger.logger.debug("File download opened with fallback browser flow");}return;}yield openUrlWithFallback(normalizedUrl);_logger.logger.debug("File download opened with legacy URL flow");}catch(error){_logger.logger.error("File download failed",{url:url,filename:filename,error:error instanceof Error?error==null?void 0:error.message:String(error)});throw error;}});return function downloadFile(_x8,_x9,_x10){return _ref5.apply(this,arguments);};}();var handleDownloadRequest=exports.handleDownloadRequest=function(){var _ref6=(0,_asyncToGenerator2.default)(function*(downloadRequest){var url=downloadRequest.url,filename=downloadRequest.filename;if(!url){_logger.logger.error("Download request missing URL");return;}try{yield downloadFile(url,filename,shouldUseInPlaceDownload(downloadRequest));}catch(error){_logger.logger.error("Failed to handle download request",{downloadRequest:downloadRequest,error:error});}});return function handleDownloadRequest(_x11){return _ref6.apply(this,arguments);};}();
|
|
2
2
|
//# sourceMappingURL=fileDownload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_logger","normalizeUrl","url","trim","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_logger","normalizeUrl","url","trim","getUrlPathTail","_url$split","_cleanedUrl$split","_cleanedUrl$split$pop","cleanedUrl","split","pop","getExtensionFromName","name","includes","substring","lastIndexOf","resolveDownloadFileName","filename","trimmedName","sanitizedName","replace","urlExtension","tailName","Date","now","isValidHttpUrl","test","getNativeDownloadModule","NativeModules","RobylonDownloadModule","openUrlWithFallback","_ref","_asyncToGenerator2","default","Linking","openURL","primaryError","logger","warn","Error","message","String","encodeURIComponent","_x","apply","arguments","downloadOnAndroid","_ref2","module","downloadFile","_x2","_x3","downloadOniOS","_ref3","_x4","_x5","downloadWithNativeStorage","_ref4","safeName","Platform","OS","_x6","_x7","shouldUseInPlaceDownload","downloadRequest","inPlace","exports","_ref5","normalizedUrl","debug","nativeDownloadError","error","_x8","_x9","_x10","handleDownloadRequest","_ref6","_x11"],"sourceRoot":"../../../src","sources":["utils/fileDownload.ts"],"mappings":"wSAKA,IAAAA,YAAA,CAAAC,OAAA,iBACA,IAAAC,OAAA,CAAAD,OAAA,aAQA,GAAM,CAAAE,YAAY,CAAG,QAAf,CAAAA,YAAYA,CAAIC,GAAW,CAAa,CAC5C,MAAO,CAAAA,GAAG,cAAHA,GAAG,CAAEC,IAAI,CAAC,CAAC,CACpB,CAAC,CAED,GAAM,CAAAC,cAAc,CAAG,QAAjB,CAAAA,cAAcA,CAAIF,GAAY,CAAa,KAAAG,UAAA,CAAAC,iBAAA,CAAAC,qBAAA,CAC/C,GAAM,CAAAC,UAAU,CAAG,CAAAN,GAAG,eAAAG,UAAA,CAAHH,GAAG,CAAEO,KAAK,CAAC,GAAG,CAAC,eAAfJ,UAAA,CAAkB,CAAC,CAAC,GAAI,EAAE,CAC7C,MAAO,CAAAG,UAAU,eAAAF,iBAAA,CAAVE,UAAU,CAAEC,KAAK,CAAC,GAAG,CAAC,gBAAAF,qBAAA,CAAtBD,iBAAA,CAAwBI,GAAG,CAAC,CAAC,eAA7BH,qBAAA,CAA+BJ,IAAI,CAAC,CAAC,GAAI,EAAE,CACpD,CAAC,CAED,GAAM,CAAAQ,oBAAoB,CAAG,QAAvB,CAAAA,oBAAoBA,CAAIC,IAAa,CAAa,CACtD,GAAI,EAACA,IAAI,QAAJA,IAAI,CAAEC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAO,EAAE,CACnC,MAAO,CAAAD,IAAI,CAACE,SAAS,CAACF,IAAI,CAACG,WAAW,CAAC,GAAG,CAAC,CAAC,CAC9C,CAAC,CAED,GAAM,CAAAC,uBAAuB,CAAG,QAA1B,CAAAA,uBAAuBA,CAAIC,QAAiB,CAAEf,GAAY,CAAa,CAC3E,GAAM,CAAAgB,WAAW,CAAGD,QAAQ,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e,CAAjC9D,GAAG,CAAEe,QAAQ,CAAK+C,eAAe,CAA5B/C,QAAQ,CAErB,GAAI,CAACf,GAAG,CAAE,CACRmC,cAAM,CAACkC,KAAK,CAAC,8BAA8B,CAAC,CAC5C,OACF,CAEA,GAAI,CACF,KAAM,CAAAtB,YAAY,CAChB/C,GAAG,CACHe,QAAQ,CACR8C,wBAAwB,CAACC,eAAe,CAC1C,CAAC,CACH,CAAE,MAAOO,KAAK,CAAE,CACdlC,cAAM,CAACkC,KAAK,CAAC,mCAAmC,CAAE,CAChDP,eAAe,CAAfA,eAAe,CACfO,KAAK,CAALA,KACF,CAAC,CAAC,CAEJ,CACF,CAAC,iBAvBY,CAAAI,qBAAqBA,CAAAE,IAAA,SAAAD,KAAA,CAAAhC,KAAA,MAAAC,SAAA,OAuBjC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:true});exports.SDK_VERSION=void 0;var SDK_VERSION=exports.SDK_VERSION='2.0.31-staging.
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:true});exports.SDK_VERSION=void 0;var SDK_VERSION=exports.SDK_VERSION='2.0.31-staging.5';
|
|
2
2
|
//# sourceMappingURL=version.staging.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDownload.d.ts","sourceRoot":"","sources":["../../../src/utils/fileDownload.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;
|
|
1
|
+
{"version":3,"file":"fileDownload.d.ts","sourceRoot":"","sources":["../../../src/utils/fileDownload.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAyGD;;;;GAIG;AACH,eAAO,MAAM,YAAY,QAClB,MAAM,aACA,MAAM,YACP,OAAO,KAChB,QAAQ,IAAI,CA0Cd,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,oBACf,eAAe,KAC/B,QAAQ,IAAI,CAqBd,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.31-staging.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.31-staging.5";
|
|
2
2
|
//# sourceMappingURL=version.staging.d.ts.map
|
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "robylon-react-native-sdk"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.license = package["license"]
|
|
10
|
+
s.authors = package["author"]
|
|
11
|
+
s.homepage = "https://github.com/OneWorldNation/robylon-react-native-sdk"
|
|
12
|
+
s.platforms = { :ios => "13.0" }
|
|
13
|
+
s.source = { :git => "https://github.com/OneWorldNation/robylon-react-native-sdk.git", :tag => "#{s.version}" }
|
|
14
|
+
|
|
15
|
+
s.source_files = "ios/**/*.{h,m,mm}"
|
|
16
|
+
|
|
17
|
+
s.dependency "React-Core"
|
|
18
|
+
end
|
|
@@ -16,11 +16,28 @@ const normalizeUrl = (url: string): string => {
|
|
|
16
16
|
return url?.trim();
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
const
|
|
19
|
+
const getUrlPathTail = (url?: string): string => {
|
|
20
|
+
const cleanedUrl = url?.split("?")?.[0] || "";
|
|
21
|
+
return cleanedUrl?.split("/")?.pop()?.trim() || "";
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getExtensionFromName = (name?: string): string => {
|
|
25
|
+
if (!name?.includes(".")) return "";
|
|
26
|
+
return name.substring(name.lastIndexOf("."));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const resolveDownloadFileName = (filename?: string, url?: string): string => {
|
|
21
30
|
const trimmedName = filename?.trim();
|
|
22
|
-
if (
|
|
23
|
-
|
|
31
|
+
if (trimmedName) {
|
|
32
|
+
const sanitizedName = trimmedName.replace(/[<>:"/\\|?*\x00-\x1F]/g, "_");
|
|
33
|
+
const urlExtension = getExtensionFromName(getUrlPathTail(url));
|
|
34
|
+
if (getExtensionFromName(sanitizedName) || !urlExtension)
|
|
35
|
+
return sanitizedName;
|
|
36
|
+
return `${sanitizedName}${urlExtension}`;
|
|
37
|
+
}
|
|
38
|
+
const tailName = getUrlPathTail(url);
|
|
39
|
+
if (tailName) return tailName.replace(/[<>:"/\\|?*\x00-\x1F]/g, "_");
|
|
40
|
+
return `download-robylon-${Date.now()}`;
|
|
24
41
|
};
|
|
25
42
|
|
|
26
43
|
type RobylonDownloadNativeModule = {
|
|
@@ -32,7 +49,10 @@ const isValidHttpUrl = (url: string): boolean => {
|
|
|
32
49
|
};
|
|
33
50
|
|
|
34
51
|
const getNativeDownloadModule = (): RobylonDownloadNativeModule | null => {
|
|
35
|
-
return (
|
|
52
|
+
return (
|
|
53
|
+
(NativeModules?.RobylonDownloadModule as RobylonDownloadNativeModule) ||
|
|
54
|
+
null
|
|
55
|
+
);
|
|
36
56
|
};
|
|
37
57
|
|
|
38
58
|
const openUrlWithFallback = async (url: string): Promise<void> => {
|
|
@@ -49,10 +69,15 @@ const openUrlWithFallback = async (url: string): Promise<void> => {
|
|
|
49
69
|
});
|
|
50
70
|
}
|
|
51
71
|
|
|
52
|
-
await Linking.openURL(
|
|
72
|
+
await Linking.openURL(
|
|
73
|
+
`https://docs.google.com/viewer?url=${encodeURIComponent(url)}`,
|
|
74
|
+
);
|
|
53
75
|
};
|
|
54
76
|
|
|
55
|
-
const downloadOnAndroid = async (
|
|
77
|
+
const downloadOnAndroid = async (
|
|
78
|
+
url: string,
|
|
79
|
+
filename: string,
|
|
80
|
+
): Promise<void> => {
|
|
56
81
|
const module = getNativeDownloadModule();
|
|
57
82
|
if (!module?.downloadFile) {
|
|
58
83
|
throw new Error("Robylon native download module is not linked on Android");
|
|
@@ -60,19 +85,33 @@ const downloadOnAndroid = async (url: string, filename: string): Promise<void> =
|
|
|
60
85
|
await module.downloadFile(url, filename);
|
|
61
86
|
};
|
|
62
87
|
|
|
88
|
+
const downloadOniOS = async (url: string, filename: string): Promise<void> => {
|
|
89
|
+
const module = getNativeDownloadModule();
|
|
90
|
+
if (!module?.downloadFile) {
|
|
91
|
+
throw new Error("Robylon native download module is not linked on iOS");
|
|
92
|
+
}
|
|
93
|
+
await module.downloadFile(url, filename);
|
|
94
|
+
};
|
|
95
|
+
|
|
63
96
|
const downloadWithNativeStorage = async (
|
|
64
97
|
url: string,
|
|
65
|
-
filename?: string
|
|
98
|
+
filename?: string,
|
|
66
99
|
): Promise<void> => {
|
|
67
|
-
const safeName =
|
|
100
|
+
const safeName = resolveDownloadFileName(filename, url);
|
|
68
101
|
if (Platform.OS === "android") {
|
|
69
102
|
await downloadOnAndroid(url, safeName);
|
|
70
103
|
return;
|
|
71
104
|
}
|
|
105
|
+
if (Platform.OS === "ios") {
|
|
106
|
+
await downloadOniOS(url, safeName);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
72
109
|
await openUrlWithFallback(url);
|
|
73
110
|
};
|
|
74
111
|
|
|
75
|
-
const shouldUseInPlaceDownload = (
|
|
112
|
+
const shouldUseInPlaceDownload = (
|
|
113
|
+
downloadRequest?: DownloadRequest,
|
|
114
|
+
): boolean => {
|
|
76
115
|
return downloadRequest?.inPlace === true;
|
|
77
116
|
};
|
|
78
117
|
|
|
@@ -84,7 +123,7 @@ const shouldUseInPlaceDownload = (downloadRequest?: DownloadRequest): boolean =>
|
|
|
84
123
|
export const downloadFile = async (
|
|
85
124
|
url: string,
|
|
86
125
|
filename?: string,
|
|
87
|
-
inPlace?: boolean
|
|
126
|
+
inPlace?: boolean,
|
|
88
127
|
): Promise<void> => {
|
|
89
128
|
try {
|
|
90
129
|
const normalizedUrl = normalizeUrl(url);
|
|
@@ -134,7 +173,7 @@ export const downloadFile = async (
|
|
|
134
173
|
* @param downloadRequest - The download request object
|
|
135
174
|
*/
|
|
136
175
|
export const handleDownloadRequest = async (
|
|
137
|
-
downloadRequest: DownloadRequest
|
|
176
|
+
downloadRequest: DownloadRequest,
|
|
138
177
|
): Promise<void> => {
|
|
139
178
|
const { url, filename } = downloadRequest;
|
|
140
179
|
|
|
@@ -144,7 +183,11 @@ export const handleDownloadRequest = async (
|
|
|
144
183
|
}
|
|
145
184
|
|
|
146
185
|
try {
|
|
147
|
-
await downloadFile(
|
|
186
|
+
await downloadFile(
|
|
187
|
+
url,
|
|
188
|
+
filename,
|
|
189
|
+
shouldUseInPlaceDownload(downloadRequest),
|
|
190
|
+
);
|
|
148
191
|
} catch (error) {
|
|
149
192
|
logger.error("Failed to handle download request", {
|
|
150
193
|
downloadRequest,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated. Do not modify it manually.
|
|
2
|
-
export const SDK_VERSION = '2.0.31-staging.
|
|
2
|
+
export const SDK_VERSION = '2.0.31-staging.5';
|