react-native-cloud-storage 0.2.0 → 0.4.0
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/README.md +3 -3
- package/ios/CloudStorage.m +1 -0
- package/ios/CloudStorage.swift +7 -8
- package/lib/commonjs/RNCloudStorage.js +8 -0
- package/lib/commonjs/RNCloudStorage.js.map +1 -1
- package/lib/commonjs/createRNCloudStorage.js +1 -4
- package/lib/commonjs/createRNCloudStorage.js.map +1 -1
- package/lib/commonjs/google-drive/index.js +12 -8
- package/lib/commonjs/google-drive/index.js.map +1 -1
- package/lib/commonjs/hooks/useIsCloudAvailable.js +32 -0
- package/lib/commonjs/hooks/useIsCloudAvailable.js.map +1 -0
- package/lib/commonjs/index.js +12 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/main.js +1 -1
- package/lib/commonjs/types/native.js +1 -0
- package/lib/commonjs/types/native.js.map +1 -1
- package/lib/module/RNCloudStorage.js +8 -0
- package/lib/module/RNCloudStorage.js.map +1 -1
- package/lib/module/createRNCloudStorage.js +1 -4
- package/lib/module/createRNCloudStorage.js.map +1 -1
- package/lib/module/google-drive/index.js +11 -8
- package/lib/module/google-drive/index.js.map +1 -1
- package/lib/module/hooks/useIsCloudAvailable.js +25 -0
- package/lib/module/hooks/useIsCloudAvailable.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/main.js +1 -1
- package/lib/module/types/native.js +1 -0
- package/lib/module/types/native.js.map +1 -1
- package/lib/typescript/RNCloudStorage.d.ts +6 -0
- package/lib/typescript/RNCloudStorage.d.ts.map +1 -1
- package/lib/typescript/createRNCloudStorage.d.ts.map +1 -1
- package/lib/typescript/google-drive/index.d.ts +2 -1
- package/lib/typescript/google-drive/index.d.ts.map +1 -1
- package/lib/typescript/hooks/useIsCloudAvailable.d.ts +2 -0
- package/lib/typescript/hooks/useIsCloudAvailable.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/types/main.d.ts +1 -1
- package/lib/typescript/types/main.d.ts.map +1 -1
- package/lib/typescript/types/native.d.ts +4 -2
- package/lib/typescript/types/native.d.ts.map +1 -1
- package/lib/typescript/utils/NativeStorageError.d.ts +1 -1
- package/lib/typescript/utils/NativeStorageError.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/RNCloudStorage.ts +10 -0
- package/src/createRNCloudStorage.ts +1 -5
- package/src/google-drive/index.ts +30 -9
- package/src/hooks/useIsCloudAvailable.ts +25 -0
- package/src/index.ts +1 -0
- package/src/types/main.ts +1 -1
- package/src/types/native.ts +3 -1
- package/src/utils/NativeStorageError.ts +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# ☁️ react-native-cloud-storage
|
|
2
2
|
|
|
3
|
-
Save & read from iCloud and Google Drive using React Native
|
|
3
|
+
Save to & read from iCloud and Google Drive using React Native
|
|
4
4
|
|
|
5
|
-
  
|
|
5
|
+
  
|
|
6
6
|
|
|
7
7
|
**⚠️ WARNING**: This project is still considered unstable. The API might change drastically in new versions. Please proceed with caution and report any issues you're encountering.
|
|
8
8
|
|
|
@@ -24,7 +24,7 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
|
|
|
24
24
|
|
|
25
25
|
## Example Project
|
|
26
26
|
|
|
27
|
-
There's a demo application available within the `example` directory. To use
|
|
27
|
+
There's a demo application available within the `example` directory. To use the Google Drive implementation for Android (and any other platforms except iOS), you'll need to provide a valid access token for the Google Drive API. You can create one using the [Google OAuth 2.0 Playground](https://developers.google.com/oauthplayground). If you're using an Android emulator, you can make your life easier by feeding the token into the emulator using `adb shell input text '{some_token}'`.
|
|
28
28
|
|
|
29
29
|
## License
|
|
30
30
|
|
package/ios/CloudStorage.m
CHANGED
|
@@ -7,6 +7,7 @@ RCT_EXTERN_METHOD(createFile:(NSString *)path withData:(NSString *)data withScop
|
|
|
7
7
|
RCT_EXTERN_METHOD(readFile:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
8
8
|
RCT_EXTERN_METHOD(deleteFile:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
9
9
|
RCT_EXTERN_METHOD(statFile:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
10
|
+
RCT_EXTERN_METHOD(isCloudAvailable:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
10
11
|
|
|
11
12
|
+ (BOOL)requiresMainQueueSetup
|
|
12
13
|
{
|
package/ios/CloudStorage.swift
CHANGED
|
@@ -81,13 +81,6 @@ class CloudStorage: NSObject {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
/* return an object with the following properties:
|
|
85
|
-
* size: filesize in bytes
|
|
86
|
-
* birthtimeMs: creation time in milliseconds
|
|
87
|
-
* mtimeMs: modification time in milliseconds
|
|
88
|
-
* isDirectory: true if the path is a directory
|
|
89
|
-
* isFile: true if the path is a file
|
|
90
|
-
*/
|
|
91
84
|
@objc(statFile:withScope:withResolver:withRejecter:)
|
|
92
85
|
func statFile(path: String, scope: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
93
86
|
let fileManager = FileManager.default
|
|
@@ -122,9 +115,15 @@ class CloudStorage: NSObject {
|
|
|
122
115
|
}
|
|
123
116
|
}
|
|
124
117
|
|
|
118
|
+
@objc(isCloudAvailable:withRejecter:)
|
|
119
|
+
func isCloudAvailable(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
120
|
+
let token = FileManager.default.ubiquityIdentityToken
|
|
121
|
+
resolve(token != nil)
|
|
122
|
+
}
|
|
123
|
+
|
|
125
124
|
/// Returns the iCloud directory URL for the given scope.
|
|
126
125
|
///
|
|
127
|
-
/// - Parameter scope: The scope of the directory. Can be either "documents" or "
|
|
126
|
+
/// - Parameter scope: The scope of the directory. Can be either "documents" or "app_data".
|
|
128
127
|
/// - Returns: The URL of the iCloud directory.
|
|
129
128
|
private func getDirectory(_ scope: String) -> URL? {
|
|
130
129
|
let fileManager = FileManager.default
|
|
@@ -10,6 +10,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
10
10
|
const nativeInstance = (0, _createRNCloudStorage.default)();
|
|
11
11
|
const RNCloudStorage = {
|
|
12
12
|
setGoogleDriveAccessToken: accessToken => _googleDrive.default.accessToken = accessToken,
|
|
13
|
+
/**
|
|
14
|
+
* Tests whether or not the cloud storage is available. Always returns true for Google Drive. iCloud may be
|
|
15
|
+
* unavailable right after app launch or if the user is not logged in.
|
|
16
|
+
* @returns A promise that resolves to true if the cloud storage is available, false otherwise.
|
|
17
|
+
*/
|
|
18
|
+
isCloudAvailable: async () => {
|
|
19
|
+
return nativeInstance.isCloudAvailable();
|
|
20
|
+
},
|
|
13
21
|
/**
|
|
14
22
|
* Tests whether or not the file at the given path exists.
|
|
15
23
|
* @param path The path to test.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_createRNCloudStorage","_interopRequireDefault","require","_googleDrive","obj","__esModule","default","nativeInstance","createRNCloudStorage","RNCloudStorage","setGoogleDriveAccessToken","accessToken","GoogleDriveApiClient","exists","path","scope","fileExists","writeFile","data","createFile","readFile","unlink","deleteFile","stat","native","statFile","birthtime","Date","birthtimeMs","mtime","mtimeMs","isDirectory","isFile","_default","exports"],"sourceRoot":"../../src","sources":["RNCloudStorage.ts"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAkD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGlD,MAAMG,cAAc,GAAG,IAAAC,6BAAoB,GAAE;AAC7C,MAAMC,cAAc,GAAG;EACrBC,yBAAyB,EAAGC,WAAmB,IAAMC,oBAAoB,CAACD,WAAW,GAAGA,WAAY;
|
|
1
|
+
{"version":3,"names":["_createRNCloudStorage","_interopRequireDefault","require","_googleDrive","obj","__esModule","default","nativeInstance","createRNCloudStorage","RNCloudStorage","setGoogleDriveAccessToken","accessToken","GoogleDriveApiClient","isCloudAvailable","exists","path","scope","fileExists","writeFile","data","createFile","readFile","unlink","deleteFile","stat","native","statFile","birthtime","Date","birthtimeMs","mtime","mtimeMs","isDirectory","isFile","_default","exports"],"sourceRoot":"../../src","sources":["RNCloudStorage.ts"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAkD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGlD,MAAMG,cAAc,GAAG,IAAAC,6BAAoB,GAAE;AAC7C,MAAMC,cAAc,GAAG;EACrBC,yBAAyB,EAAGC,WAAmB,IAAMC,oBAAoB,CAACD,WAAW,GAAGA,WAAY;EAEpG;AACF;AACA;AACA;AACA;EACEE,gBAAgB,EAAE,MAAAA,CAAA,KAA8B;IAC9C,OAAON,cAAc,CAACM,gBAAgB,EAAE;EAC1C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEC,MAAM,EAAEA,CAACC,IAAY,EAAEC,KAAmB,KAAuB;IAC/D,OAAOT,cAAc,CAACU,UAAU,CAACF,IAAI,EAAEC,KAAK,CAAC;EAC/C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;EACEE,SAAS,EAAEA,CAACH,IAAY,EAAEI,IAAY,EAAEH,KAAmB,KAAoB;IAC7E,OAAOT,cAAc,CAACa,UAAU,CAACL,IAAI,EAAEI,IAAI,EAAEH,KAAK,EAAE,IAAI,CAAC;EAC3D,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEK,QAAQ,EAAEA,CAACN,IAAY,EAAEC,KAAmB,KAAsB;IAChE,OAAOT,cAAc,CAACc,QAAQ,CAACN,IAAI,EAAEC,KAAK,CAAC;EAC7C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEM,MAAM,EAAEA,CAACP,IAAY,EAAEC,KAAmB,KAAoB;IAC5D,OAAOT,cAAc,CAACgB,UAAU,CAACR,IAAI,EAAEC,KAAK,CAAC;EAC/C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEQ,IAAI,EAAE,MAAAA,CAAOT,IAAY,EAAEC,KAAmB,KAA+B;IAC3E,MAAMS,MAAM,GAAG,MAAMlB,cAAc,CAACmB,QAAQ,CAACX,IAAI,EAAEC,KAAK,CAAC;IAEzD,OAAO;MACL,GAAGS,MAAM;MACTE,SAAS,EAAE,IAAIC,IAAI,CAACH,MAAM,CAACI,WAAW,CAAC;MACvCC,KAAK,EAAE,IAAIF,IAAI,CAACH,MAAM,CAACM,OAAO,CAAC;MAC/BC,WAAW,EAAEA,CAAA,KAAMP,MAAM,CAACO,WAAW;MACrCC,MAAM,EAAEA,CAAA,KAAMR,MAAM,CAACQ;IACvB,CAAC;EACH;AACF,CAAC;AAAC,IAAAC,QAAA,GAEazB,cAAc;AAAA0B,OAAA,CAAA7B,OAAA,GAAA4B,QAAA"}
|
|
@@ -43,9 +43,6 @@ function createRNCloudStorage() {
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
return new _googleDrive.default();
|
|
48
|
-
}
|
|
49
|
-
throw new Error('Unsupported platform');
|
|
46
|
+
return new _googleDrive.default();
|
|
50
47
|
}
|
|
51
48
|
//# sourceMappingURL=createRNCloudStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_googleDrive","_interopRequireDefault","_native","_NativeStorageError","obj","__esModule","default","LINKING_ERROR","Platform","select","ios","nativeIosInstance","NativeModules","CloudStorage","Proxy","get","target","prop","originalFunction","arguments","error","code","Object","values","NativeStorageErrorCode","includes","NativeStorageError","message","UNKNOWN","createRNCloudStorage","OS","Error","GoogleDriveApiClient"],"sourceRoot":"../../src","sources":["createRNCloudStorage.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAF,sBAAA,CAAAF,OAAA;AAA4D,SAAAE,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5D,MAAMG,aAAa,GAChB,qFAAoF,GACrFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEJ,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMK,iBAAiB,GAAGC,0BAAa,CAACC,YAAY,GAChD,IAAIC,KAAK,CAACF,0BAAa,CAACC,YAAY,EAAE;EACpCE,GAAGA,CAACC,MAA4B,EAAEC,IAAgC,EAAE;IAClE,MAAMC,gBAAgB,GAAGF,MAAM,CAACC,IAAI,CAAC;IACrC,IAAI,OAAOC,gBAAgB,KAAK,UAAU,EAAE;MAC1C,OAAO,kBAA0B;QAC/B,IAAI;UACF;UACA,OAAO,MAAMA,gBAAgB,CAAC,GAAAC,SAAO,CAAC;QACxC,CAAC,CAAC,OAAOC,KAAU,EAAE;UACnB,IAAIA,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEC,IAAI,IAAIC,MAAM,CAACC,MAAM,CAACC,8BAAsB,CAAC,CAACC,QAAQ,CAACL,KAAK,CAACC,IAAI,CAAC,EAAE;YAC7E,MAAM,IAAIK,2BAAkB,CAAC,CAAAN,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEO,OAAO,KAAI,EAAE,EAAEP,KAAK,CAACC,IAAI,CAA2B;UAC1F,CAAC,MAAM;YACL,MAAM,IAAIK,2BAAkB,CAAC,eAAe,EAAEF,8BAAsB,CAACI,OAAO,EAAER,KAAK,CAAC;UACtF;QACF;MACF,CAAC;IACH;IACA,OAAOF,gBAAgB;EACzB;AACF,CAAC,CAAC,GACF,IAAI;AAEO,SAASW,oBAAoBA,CAAA,EAAyB;EACnE,IAAIrB,qBAAQ,CAACsB,EAAE,KAAK,KAAK,EAAE;IACzB,OACEnB,iBAAiB,IACjB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;MACEC,GAAGA,CAAA,EAAG;QACJ,MAAM,IAAIgB,KAAK,CAACxB,aAAa,CAAC;MAChC;IACF,CAAC,CACF;EAEL;EAEA,
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_googleDrive","_interopRequireDefault","_native","_NativeStorageError","obj","__esModule","default","LINKING_ERROR","Platform","select","ios","nativeIosInstance","NativeModules","CloudStorage","Proxy","get","target","prop","originalFunction","arguments","error","code","Object","values","NativeStorageErrorCode","includes","NativeStorageError","message","UNKNOWN","createRNCloudStorage","OS","Error","GoogleDriveApiClient"],"sourceRoot":"../../src","sources":["createRNCloudStorage.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAF,sBAAA,CAAAF,OAAA;AAA4D,SAAAE,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5D,MAAMG,aAAa,GAChB,qFAAoF,GACrFC,qBAAQ,CAACC,MAAM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AE;AACnC"}
|
|
@@ -5,6 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _reactNativeGoogleDriveApiWrapperJs = require("react-native-google-drive-api-wrapper-js");
|
|
8
|
+
var _native = require("../types/native");
|
|
9
|
+
var _NativeStorageError = _interopRequireDefault(require("../utils/NativeStorageError"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
11
|
class GoogleDriveApiClient {
|
|
9
12
|
static drive = new _reactNativeGoogleDriveApiWrapperJs.GDrive();
|
|
10
13
|
constructor() {
|
|
@@ -14,7 +17,7 @@ class GoogleDriveApiClient {
|
|
|
14
17
|
get(target, prop) {
|
|
15
18
|
if (typeof target[prop] === 'function') {
|
|
16
19
|
if (!GoogleDriveApiClient.drive.accessToken) {
|
|
17
|
-
throw new
|
|
20
|
+
throw new _NativeStorageError.default(`Google Drive access token is not set, cannot call function ${prop.toString()}`, _native.NativeStorageErrorCode.GOOGLE_DRIVE_ACCESS_TOKEN_MISSING);
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
return target[prop];
|
|
@@ -29,11 +32,12 @@ class GoogleDriveApiClient {
|
|
|
29
32
|
static get accessToken() {
|
|
30
33
|
return GoogleDriveApiClient.drive.accessToken;
|
|
31
34
|
}
|
|
35
|
+
isCloudAvailable = async () => true;
|
|
32
36
|
getRootDirectory(scope) {
|
|
33
37
|
switch (scope) {
|
|
34
38
|
case 'documents':
|
|
35
39
|
return 'drive';
|
|
36
|
-
case '
|
|
40
|
+
case 'app_data':
|
|
37
41
|
return 'appDataFolder';
|
|
38
42
|
}
|
|
39
43
|
}
|
|
@@ -64,16 +68,16 @@ class GoogleDriveApiClient {
|
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
if (!topDirectoryId) {
|
|
67
|
-
throw new
|
|
71
|
+
throw new _NativeStorageError.default(`Could not find top directory with name ${directoryTree[0]}`, _native.NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
// now, we traverse the directories array and get the id of the last directory from the files array
|
|
71
75
|
let currentDirectoryId = topDirectoryId;
|
|
72
76
|
for (let i = 1; i < directoryTree.length; i++) {
|
|
73
77
|
const currentDirectory = files.find(f => f.id === currentDirectoryId);
|
|
74
|
-
if (!currentDirectory) throw new
|
|
78
|
+
if (!currentDirectory) throw new _NativeStorageError.default(`Could not find directory with id ${currentDirectoryId}`, _native.NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
|
|
75
79
|
const nextDirectory = files.find(f => f.name === directoryTree[i] && f.parents[0] === currentDirectoryId);
|
|
76
|
-
if (!nextDirectory) throw new
|
|
80
|
+
if (!nextDirectory) throw new _NativeStorageError.default(`Could not find directory with name ${directoryTree[i]}`, _native.NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
|
|
77
81
|
currentDirectoryId = nextDirectory.id;
|
|
78
82
|
}
|
|
79
83
|
return currentDirectoryId;
|
|
@@ -100,7 +104,7 @@ class GoogleDriveApiClient {
|
|
|
100
104
|
} else {
|
|
101
105
|
file = files.find(f => f.name === filename && f.parents[0] === parentDirectoryId);
|
|
102
106
|
}
|
|
103
|
-
if (!file) throw new
|
|
107
|
+
if (!file) throw new _NativeStorageError.default(`File not found`, _native.NativeStorageErrorCode.FILE_NOT_FOUND);
|
|
104
108
|
return file.id;
|
|
105
109
|
}
|
|
106
110
|
async fileExists(path, scope) {
|
|
@@ -108,7 +112,7 @@ class GoogleDriveApiClient {
|
|
|
108
112
|
await this.getFileId(path, scope);
|
|
109
113
|
return true;
|
|
110
114
|
} catch (e) {
|
|
111
|
-
if (e.
|
|
115
|
+
if (e instanceof _NativeStorageError.default && e.code === _native.NativeStorageErrorCode.FILE_NOT_FOUND) return false;else throw e;
|
|
112
116
|
}
|
|
113
117
|
}
|
|
114
118
|
async createFile(path, data, scope, overwrite) {
|
|
@@ -130,7 +134,7 @@ class GoogleDriveApiClient {
|
|
|
130
134
|
const parentDirectoryId = this.findParentDirectoryId(files, directories);
|
|
131
135
|
uploader.setRequestBody({
|
|
132
136
|
name: filename,
|
|
133
|
-
parents: parentDirectoryId ? [parentDirectoryId] : scope === '
|
|
137
|
+
parents: parentDirectoryId ? [parentDirectoryId] : scope === 'app_data' ? [this.getRootDirectory(scope)] : undefined
|
|
134
138
|
});
|
|
135
139
|
}
|
|
136
140
|
await uploader.execute();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeGoogleDriveApiWrapperJs","require","GoogleDriveApiClient","drive","GDrive","constructor","fetchTimeout","Proxy","get","target","prop","accessToken","
|
|
1
|
+
{"version":3,"names":["_reactNativeGoogleDriveApiWrapperJs","require","_native","_NativeStorageError","_interopRequireDefault","obj","__esModule","default","GoogleDriveApiClient","drive","GDrive","constructor","fetchTimeout","Proxy","get","target","prop","accessToken","NativeStorageError","toString","NativeStorageErrorCode","GOOGLE_DRIVE_ACCESS_TOKEN_MISSING","isCloudAvailable","getRootDirectory","scope","resolvePathToDirectories","path","startsWith","slice","endsWith","directories","split","actualFilename","pop","filename","findParentDirectoryId","files","directoryTree","possibleTopDirectories","filter","f","mimeType","MimeTypes","FOLDER","name","topDirectoryId","length","id","possibleTopDirectory","find","parents","DIRECTORY_NOT_FOUND","currentDirectoryId","i","currentDirectory","nextDirectory","listFiles","list","spaces","fields","getFileId","parentDirectoryId","file","f2","FILE_NOT_FOUND","fileExists","e","code","createFile","data","overwrite","fileId","uploader","newMultipartUploader","setData","TEXT","setIdOfFileToUpdate","setRequestBody","undefined","execute","readFile","content","getText","deleteFile","delete","statFile","size","birthtimeMs","Date","createdTime","getTime","mtimeMs","modifiedTime","isDirectory","isFile","_default","exports"],"sourceRoot":"../../../src","sources":["google-drive/index.ts"],"mappings":";;;;;;AAAA,IAAAA,mCAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAMA,IAAAE,mBAAA,GAAA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AAS,CAAClC,IAAI,EAAEF,KAAK,CAAC;IAChD,MAAMhB,oBAAoB,CAACC,KAAK,CAAC2B,KAAK,CAACgD,MAAM,CAACb,MAAM,CAAC;EACvD;EAEA,MAAMc,QAAQA,CAAC3D,IAAY,EAAEF,KAAgC,EAAyC;IACpG,MAAM+C,MAAM,GAAG,MAAM,IAAI,CAACX,SAAS,CAAClC,IAAI,EAAEF,KAAK,CAAC;IAChD,MAAMsC,IAA6B,GAAG,MAAMtD,oBAAoB,CAACC,KAAK,CAAC2B,KAAK,CAACtB,GAAG,CAACyD,MAAM,EAAE;MACvFZ,MAAM,EAAE;IACV,CAAC,CAAC;IACF,OAAO;MACL2B,IAAI,EAAExB,IAAI,CAACwB,IAAI,IAAI,CAAC;MACpBC,WAAW,EAAE,IAAIC,IAAI,CAAC1B,IAAI,CAAC2B,WAAW,CAAE,CAACC,OAAO,EAAE;MAClDC,OAAO,EAAE,IAAIH,IAAI,CAAC1B,IAAI,CAAC8B,YAAY,CAAE,CAACF,OAAO,EAAE;MAC/CG,WAAW,EAAE/B,IAAI,CAACrB,QAAQ,KAAKC,6CAAS,CAACC,MAAM;MAC/CmD,MAAM,EAAEhC,IAAI,CAACrB,QAAQ,KAAKC,6CAAS,CAACC;IACtC,CAAC;EACH;AACF;AAAC,IAAAoD,QAAA,GAEcvF,oBAAoB;AAAAwF,OAAA,CAAAzF,OAAA,GAAAwF,QAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useIsCloudAvailable = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _RNCloudStorage = _interopRequireDefault(require("../RNCloudStorage"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
// TODO: there must be a better way to do this without a timeout?
|
|
12
|
+
const useIsCloudAvailable = function () {
|
|
13
|
+
let timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
14
|
+
const [isCloudAvailable, setIsCloudAvailable] = (0, _react.useState)(_reactNative.Platform.OS !== 'ios');
|
|
15
|
+
const [firstCheck] = (0, _react.useState)(new Date());
|
|
16
|
+
(0, _react.useEffect)(() => {
|
|
17
|
+
const checkCloudAvailability = async () => {
|
|
18
|
+
const isAvailable = await _RNCloudStorage.default.isCloudAvailable();
|
|
19
|
+
if (isAvailable) {
|
|
20
|
+
setIsCloudAvailable(true);
|
|
21
|
+
} else if (new Date().getTime() - firstCheck.getTime() < timeout * 1000) {
|
|
22
|
+
setTimeout(checkCloudAvailability, 500);
|
|
23
|
+
} else {
|
|
24
|
+
console.log('Cloud storage is not available.');
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
checkCloudAvailability();
|
|
28
|
+
}, [firstCheck, timeout]);
|
|
29
|
+
return isCloudAvailable;
|
|
30
|
+
};
|
|
31
|
+
exports.useIsCloudAvailable = useIsCloudAvailable;
|
|
32
|
+
//# sourceMappingURL=useIsCloudAvailable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_RNCloudStorage","_interopRequireDefault","obj","__esModule","default","useIsCloudAvailable","timeout","arguments","length","undefined","isCloudAvailable","setIsCloudAvailable","useState","Platform","OS","firstCheck","Date","useEffect","checkCloudAvailability","isAvailable","RNCloudStorage","getTime","setTimeout","console","log","exports"],"sourceRoot":"../../../src","sources":["hooks/useIsCloudAvailable.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAC,sBAAA,CAAAH,OAAA;AAA+C,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE/C;AACO,MAAMG,mBAAmB,GAAG,SAAAA,CAAA,EAAkB;EAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAC9C,MAAM,CAACG,gBAAgB,EAAEC,mBAAmB,CAAC,GAAG,IAAAC,eAAQ,EAACC,qBAAQ,CAACC,EAAE,KAAK,KAAK,CAAC;EAC/E,MAAM,CAACC,UAAU,CAAC,GAAG,IAAAH,eAAQ,EAAC,IAAII,IAAI,EAAE,CAAC;EAEzC,IAAAC,gBAAS,EAAC,MAAM;IACd,MAAMC,sBAAsB,GAAG,MAAAA,CAAA,KAAY;MACzC,MAAMC,WAAW,GAAG,MAAMC,uBAAc,CAACV,gBAAgB,EAAE;MAC3D,IAAIS,WAAW,EAAE;QACfR,mBAAmB,CAAC,IAAI,CAAC;MAC3B,CAAC,MAAM,IAAI,IAAIK,IAAI,EAAE,CAACK,OAAO,EAAE,GAAGN,UAAU,CAACM,OAAO,EAAE,GAAGf,OAAO,GAAG,IAAI,EAAE;QACvEgB,UAAU,CAACJ,sBAAsB,EAAE,GAAG,CAAC;MACzC,CAAC,MAAM;QACLK,OAAO,CAACC,GAAG,CAAC,iCAAiC,CAAC;MAChD;IACF,CAAC;IACDN,sBAAsB,EAAE;EAC1B,CAAC,EAAE,CAACH,UAAU,EAAET,OAAO,CAAC,CAAC;EAEzB,OAAOI,gBAAgB;AACzB,CAAC;AAACe,OAAA,CAAApB,mBAAA,GAAAA,mBAAA"}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -46,6 +46,18 @@ Object.keys(_useCloudFile).forEach(function (key) {
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
|
+
var _useIsCloudAvailable = require("./hooks/useIsCloudAvailable");
|
|
50
|
+
Object.keys(_useIsCloudAvailable).forEach(function (key) {
|
|
51
|
+
if (key === "default" || key === "__esModule") return;
|
|
52
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
53
|
+
if (key in exports && exports[key] === _useIsCloudAvailable[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _useIsCloudAvailable[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
49
61
|
var _NativeStorageError = _interopRequireDefault(require("./utils/NativeStorageError"));
|
|
50
62
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
51
63
|
var _default = _RNCloudStorage.default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_RNCloudStorage","_interopRequireDefault","require","_native","_main","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_useCloudFile","_NativeStorageError","obj","__esModule","default","_default","RNCloudStorage"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAF,KAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,KAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,KAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,aAAA,GAAAf,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAW,aAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,aAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,aAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,mBAAA,
|
|
1
|
+
{"version":3,"names":["_RNCloudStorage","_interopRequireDefault","require","_native","_main","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_useCloudFile","_useIsCloudAvailable","_NativeStorageError","obj","__esModule","default","_default","RNCloudStorage"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAF,KAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,KAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,KAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,aAAA,GAAAf,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAW,aAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,aAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,aAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,oBAAA,GAAAhB,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAY,oBAAA,EAAAX,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAU,oBAAA,CAAAV,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,oBAAA,CAAAV,GAAA;IAAA;EAAA;AAAA;AACA,IAAAW,mBAAA,GAAAlB,sBAAA,CAAAC,OAAA;AAA4D,SAAAD,uBAAAmB,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,IAAAG,QAAA,GAI7CC,uBAAc;AAAAX,OAAA,CAAAS,OAAA,GAAAC,QAAA"}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.StorageScope = void 0;
|
|
7
7
|
let StorageScope = /*#__PURE__*/function (StorageScope) {
|
|
8
8
|
StorageScope["Documents"] = "documents";
|
|
9
|
-
StorageScope["
|
|
9
|
+
StorageScope["AppData"] = "app_data";
|
|
10
10
|
return StorageScope;
|
|
11
11
|
}({});
|
|
12
12
|
exports.StorageScope = StorageScope;
|
|
@@ -13,6 +13,7 @@ let NativeStorageErrorCode = /*#__PURE__*/function (NativeStorageErrorCode) {
|
|
|
13
13
|
NativeStorageErrorCode["DELETE_ERROR"] = "ERR_DELETE_ERROR";
|
|
14
14
|
NativeStorageErrorCode["STAT_ERROR"] = "ERR_STAT_ERROR";
|
|
15
15
|
NativeStorageErrorCode["UNKNOWN"] = "ERR_UNKNOWN";
|
|
16
|
+
NativeStorageErrorCode["GOOGLE_DRIVE_ACCESS_TOKEN_MISSING"] = "ERR_GOOGLE_DRIVE_ACCESS_TOKEN_MISSING";
|
|
16
17
|
return NativeStorageErrorCode;
|
|
17
18
|
}({});
|
|
18
19
|
exports.NativeStorageErrorCode = NativeStorageErrorCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeStorageErrorCode","exports"],"sourceRoot":"../../../src","sources":["types/native.ts"],"mappings":";;;;;;IAUYA,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AAAAC,OAAA,CAAAD,sBAAA,GAAAA,sBAAA"}
|
|
1
|
+
{"version":3,"names":["NativeStorageErrorCode","exports"],"sourceRoot":"../../../src","sources":["types/native.ts"],"mappings":";;;;;;IAUYA,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AAAAC,OAAA,CAAAD,sBAAA,GAAAA,sBAAA"}
|
|
@@ -3,6 +3,14 @@ import GoogleDriveApiClient from './google-drive';
|
|
|
3
3
|
const nativeInstance = createRNCloudStorage();
|
|
4
4
|
const RNCloudStorage = {
|
|
5
5
|
setGoogleDriveAccessToken: accessToken => GoogleDriveApiClient.accessToken = accessToken,
|
|
6
|
+
/**
|
|
7
|
+
* Tests whether or not the cloud storage is available. Always returns true for Google Drive. iCloud may be
|
|
8
|
+
* unavailable right after app launch or if the user is not logged in.
|
|
9
|
+
* @returns A promise that resolves to true if the cloud storage is available, false otherwise.
|
|
10
|
+
*/
|
|
11
|
+
isCloudAvailable: async () => {
|
|
12
|
+
return nativeInstance.isCloudAvailable();
|
|
13
|
+
},
|
|
6
14
|
/**
|
|
7
15
|
* Tests whether or not the file at the given path exists.
|
|
8
16
|
* @param path The path to test.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createRNCloudStorage","GoogleDriveApiClient","nativeInstance","RNCloudStorage","setGoogleDriveAccessToken","accessToken","exists","path","scope","fileExists","writeFile","data","createFile","readFile","unlink","deleteFile","stat","native","statFile","birthtime","Date","birthtimeMs","mtime","mtimeMs","isDirectory","isFile"],"sourceRoot":"../../src","sources":["RNCloudStorage.ts"],"mappings":"AAAA,OAAOA,oBAAoB,MAAM,wBAAwB;AACzD,OAAOC,oBAAoB,MAAM,gBAAgB;AAGjD,MAAMC,cAAc,GAAGF,oBAAoB,EAAE;AAC7C,MAAMG,cAAc,GAAG;EACrBC,yBAAyB,EAAGC,WAAmB,IAAMJ,oBAAoB,CAACI,WAAW,GAAGA,WAAY;
|
|
1
|
+
{"version":3,"names":["createRNCloudStorage","GoogleDriveApiClient","nativeInstance","RNCloudStorage","setGoogleDriveAccessToken","accessToken","isCloudAvailable","exists","path","scope","fileExists","writeFile","data","createFile","readFile","unlink","deleteFile","stat","native","statFile","birthtime","Date","birthtimeMs","mtime","mtimeMs","isDirectory","isFile"],"sourceRoot":"../../src","sources":["RNCloudStorage.ts"],"mappings":"AA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S,EAAE,IAAIC,IAAI,CAACH,MAAM,CAACI,WAAW,CAAC;MACvCC,KAAK,EAAE,IAAIF,IAAI,CAACH,MAAM,CAACM,OAAO,CAAC;MAC/BC,WAAW,EAAEA,CAAA,KAAMP,MAAM,CAACO,WAAW;MACrCC,MAAM,EAAEA,CAAA,KAAMR,MAAM,CAACQ;IACvB,CAAC;EACH;AACF,CAAC;AAED,eAAevB,cAAc"}
|
|
@@ -36,9 +36,6 @@ export default function createRNCloudStorage() {
|
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
return new GoogleDriveApiClient();
|
|
41
|
-
}
|
|
42
|
-
throw new Error('Unsupported platform');
|
|
39
|
+
return new GoogleDriveApiClient();
|
|
43
40
|
}
|
|
44
41
|
//# sourceMappingURL=createRNCloudStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","GoogleDriveApiClient","NativeStorageErrorCode","NativeStorageError","LINKING_ERROR","select","ios","default","nativeIosInstance","CloudStorage","Proxy","get","target","prop","originalFunction","arguments","error","code","Object","values","includes","message","UNKNOWN","createRNCloudStorage","OS","Error"],"sourceRoot":"../../src","sources":["createRNCloudStorage.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,OAAOC,oBAAoB,MAAM,gBAAgB;AACjD,SAASC,sBAAsB,QAAQ,gBAAgB;AACvD,OAAOC,kBAAkB,MAAM,4BAA4B;AAE3D,MAAMC,aAAa,GAChB,qFAAoF,GACrFJ,QAAQ,CAACK,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,iBAAiB,GAAGT,aAAa,CAACU,YAAY,GAChD,IAAIC,KAAK,CAACX,aAAa,CAACU,YAAY,EAAE;EACpCE,GAAGA,CAACC,MAA4B,EAAEC,IAAgC,EAAE;IAClE,MAAMC,gBAAgB,GAAGF,MAAM,CAACC,IAAI,CAAC;IACrC,IAAI,OAAOC,gBAAgB,KAAK,UAAU,EAAE;MAC1C,OAAO,kBAA0B;QAC/B,IAAI;UACF;UACA,OAAO,MAAMA,gBAAgB,CAAC,GAAAC,SAAO,CAAC;QACxC,CAAC,CAAC,OAAOC,KAAU,EAAE;UACnB,IAAIA,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEC,IAAI,IAAIC,MAAM,CAACC,MAAM,CAACjB,sBAAsB,CAAC,CAACkB,QAAQ,CAACJ,KAAK,CAACC,IAAI,CAAC,EAAE;YAC7E,MAAM,IAAId,kBAAkB,CAAC,CAAAa,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEK,OAAO,KAAI,EAAE,EAAEL,KAAK,CAACC,IAAI,CAA2B;UAC1F,CAAC,MAAM;YACL,MAAM,IAAId,kBAAkB,CAAC,eAAe,EAAED,sBAAsB,CAACoB,OAAO,EAAEN,KAAK,CAAC;UACtF;QACF;MACF,CAAC;IACH;IACA,OAAOF,gBAAgB;EACzB;AACF,CAAC,CAAC,GACF,IAAI;AAER,eAAe,SAASS,oBAAoBA,CAAA,EAAyB;EACnE,IAAIvB,QAAQ,CAACwB,EAAE,KAAK,KAAK,EAAE;IACzB,OACEhB,iBAAiB,IACjB,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;MACEC,GAAGA,CAAA,EAAG;QACJ,MAAM,IAAIc,KAAK,CAACrB,aAAa,CAAC;MAChC;IACF,CAAC,CACF;EAEL;EAEA,
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","GoogleDriveApiClient","NativeStorageErrorCode","NativeStorageError","LINKING_ERROR","select","ios","default","nativeIosInstance","CloudStorage","Proxy","get","target","prop","originalFunction","arguments","error","code","Object","values","includes","message","UNKNOWN","createRNCloudStorage","OS","Error"],"sourceRoot":"../../src","sources":["createRNCloudStorage.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAA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zB,OACEhB,iBAAiB,IACjB,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;MACEC,GAAGA,CAAA,EAAG;QACJ,MAAM,IAAIc,KAAK,CAACrB,aAAa,CAAC;MAChC;IACF,CAAC,CACF;EAEL;EAEA,OAAO,IAAIH,oBAAoB,EAAE;AACnC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { GDrive, MimeTypes } from 'react-native-google-drive-api-wrapper-js';
|
|
2
|
+
import { NativeStorageErrorCode } from '../types/native';
|
|
3
|
+
import NativeStorageError from '../utils/NativeStorageError';
|
|
2
4
|
class GoogleDriveApiClient {
|
|
3
5
|
static drive = new GDrive();
|
|
4
6
|
constructor() {
|
|
@@ -8,7 +10,7 @@ class GoogleDriveApiClient {
|
|
|
8
10
|
get(target, prop) {
|
|
9
11
|
if (typeof target[prop] === 'function') {
|
|
10
12
|
if (!GoogleDriveApiClient.drive.accessToken) {
|
|
11
|
-
throw new
|
|
13
|
+
throw new NativeStorageError(`Google Drive access token is not set, cannot call function ${prop.toString()}`, NativeStorageErrorCode.GOOGLE_DRIVE_ACCESS_TOKEN_MISSING);
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
return target[prop];
|
|
@@ -23,11 +25,12 @@ class GoogleDriveApiClient {
|
|
|
23
25
|
static get accessToken() {
|
|
24
26
|
return GoogleDriveApiClient.drive.accessToken;
|
|
25
27
|
}
|
|
28
|
+
isCloudAvailable = async () => true;
|
|
26
29
|
getRootDirectory(scope) {
|
|
27
30
|
switch (scope) {
|
|
28
31
|
case 'documents':
|
|
29
32
|
return 'drive';
|
|
30
|
-
case '
|
|
33
|
+
case 'app_data':
|
|
31
34
|
return 'appDataFolder';
|
|
32
35
|
}
|
|
33
36
|
}
|
|
@@ -58,16 +61,16 @@ class GoogleDriveApiClient {
|
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
if (!topDirectoryId) {
|
|
61
|
-
throw new
|
|
64
|
+
throw new NativeStorageError(`Could not find top directory with name ${directoryTree[0]}`, NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
// now, we traverse the directories array and get the id of the last directory from the files array
|
|
65
68
|
let currentDirectoryId = topDirectoryId;
|
|
66
69
|
for (let i = 1; i < directoryTree.length; i++) {
|
|
67
70
|
const currentDirectory = files.find(f => f.id === currentDirectoryId);
|
|
68
|
-
if (!currentDirectory) throw new
|
|
71
|
+
if (!currentDirectory) throw new NativeStorageError(`Could not find directory with id ${currentDirectoryId}`, NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
|
|
69
72
|
const nextDirectory = files.find(f => f.name === directoryTree[i] && f.parents[0] === currentDirectoryId);
|
|
70
|
-
if (!nextDirectory) throw new
|
|
73
|
+
if (!nextDirectory) throw new NativeStorageError(`Could not find directory with name ${directoryTree[i]}`, NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
|
|
71
74
|
currentDirectoryId = nextDirectory.id;
|
|
72
75
|
}
|
|
73
76
|
return currentDirectoryId;
|
|
@@ -94,7 +97,7 @@ class GoogleDriveApiClient {
|
|
|
94
97
|
} else {
|
|
95
98
|
file = files.find(f => f.name === filename && f.parents[0] === parentDirectoryId);
|
|
96
99
|
}
|
|
97
|
-
if (!file) throw new
|
|
100
|
+
if (!file) throw new NativeStorageError(`File not found`, NativeStorageErrorCode.FILE_NOT_FOUND);
|
|
98
101
|
return file.id;
|
|
99
102
|
}
|
|
100
103
|
async fileExists(path, scope) {
|
|
@@ -102,7 +105,7 @@ class GoogleDriveApiClient {
|
|
|
102
105
|
await this.getFileId(path, scope);
|
|
103
106
|
return true;
|
|
104
107
|
} catch (e) {
|
|
105
|
-
if (e.
|
|
108
|
+
if (e instanceof NativeStorageError && e.code === NativeStorageErrorCode.FILE_NOT_FOUND) return false;else throw e;
|
|
106
109
|
}
|
|
107
110
|
}
|
|
108
111
|
async createFile(path, data, scope, overwrite) {
|
|
@@ -124,7 +127,7 @@ class GoogleDriveApiClient {
|
|
|
124
127
|
const parentDirectoryId = this.findParentDirectoryId(files, directories);
|
|
125
128
|
uploader.setRequestBody({
|
|
126
129
|
name: filename,
|
|
127
|
-
parents: parentDirectoryId ? [parentDirectoryId] : scope === '
|
|
130
|
+
parents: parentDirectoryId ? [parentDirectoryId] : scope === 'app_data' ? [this.getRootDirectory(scope)] : undefined
|
|
128
131
|
});
|
|
129
132
|
}
|
|
130
133
|
await uploader.execute();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GDrive","MimeTypes","GoogleDriveApiClient","drive","constructor","fetchTimeout","Proxy","get","target","prop","accessToken","
|
|
1
|
+
{"version":3,"names":["GDrive","MimeTypes","NativeStorageErrorCode","NativeStorageError","GoogleDriveApiClient","drive","constructor","fetchTimeout","Proxy","get","target","prop","accessToken","toString","GOOGLE_DRIVE_ACCESS_TOKEN_MISSING","isCloudAvailable","getRootDirectory","scope","resolvePathToDirectories","path","startsWith","slice","endsWith","directories","split","actualFilename","pop","filename","findParentDirectoryId","files","directoryTree","possibleTopDirectories","filter","f","mimeType","FOLDER","name","topDirectoryId","length","id","possibleTopDirectory","find","parents","DIRECTORY_NOT_FOUND","currentDirectoryId","i","currentDirectory","nextDirectory","listFiles","list","spaces","fields","getFileId","parentDirectoryId","file","f2","FILE_NOT_FOUND","fileExists","e","code","createFile","data","overwrite","fileId","uploader","newMultipartUploader","setData","TEXT","setIdOfFileToUpdate","setRequestBody","undefined","execute","readFile","content","getText","deleteFile","delete","statFile","size","birthtimeMs","Date","createdTime","getTime","mtimeMs","modifiedTime","isDirectory","isFile"],"sourceRoot":"../../../src","sources":["google-drive/index.ts"],"mappings":"AAAA,SAASA,MAAM,EAAEC,SAAS,QAAQ,0CAA0C;AAE5E,SACEC,sBAAsB,QAGjB,iBAAiB;AAExB,OAAOC,kBAAkB,MAAM,6BAA6B;AAE5D,MAAMC,oBAAoB,CAAiC;EACzD,OAAeC,KAAK,GAAW,IAAIL,MAAM,EAAE;EAE3CM,WAAWA,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I,EAAEF,KAAK,CAAC;IAChD,MAAMqC,IAA6B,GAAG,MAAMlD,oBAAoB,CAACC,KAAK,CAACwB,KAAK,CAACpB,GAAG,CAACsD,MAAM,EAAE;MACvFZ,MAAM,EAAE;IACV,CAAC,CAAC;IACF,OAAO;MACL2B,IAAI,EAAExB,IAAI,CAACwB,IAAI,IAAI,CAAC;MACpBC,WAAW,EAAE,IAAIC,IAAI,CAAC1B,IAAI,CAAC2B,WAAW,CAAE,CAACC,OAAO,EAAE;MAClDC,OAAO,EAAE,IAAIH,IAAI,CAAC1B,IAAI,CAAC8B,YAAY,CAAE,CAACF,OAAO,EAAE;MAC/CG,WAAW,EAAE/B,IAAI,CAACpB,QAAQ,KAAKjC,SAAS,CAACkC,MAAM;MAC/CmD,MAAM,EAAEhC,IAAI,CAACpB,QAAQ,KAAKjC,SAAS,CAACkC;IACtC,CAAC;EACH;AACF;AAEA,eAAe/B,oBAAoB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
import RNCloudStorage from '../RNCloudStorage';
|
|
4
|
+
|
|
5
|
+
// TODO: there must be a better way to do this without a timeout?
|
|
6
|
+
export const useIsCloudAvailable = function () {
|
|
7
|
+
let timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
8
|
+
const [isCloudAvailable, setIsCloudAvailable] = useState(Platform.OS !== 'ios');
|
|
9
|
+
const [firstCheck] = useState(new Date());
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const checkCloudAvailability = async () => {
|
|
12
|
+
const isAvailable = await RNCloudStorage.isCloudAvailable();
|
|
13
|
+
if (isAvailable) {
|
|
14
|
+
setIsCloudAvailable(true);
|
|
15
|
+
} else if (new Date().getTime() - firstCheck.getTime() < timeout * 1000) {
|
|
16
|
+
setTimeout(checkCloudAvailability, 500);
|
|
17
|
+
} else {
|
|
18
|
+
console.log('Cloud storage is not available.');
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
checkCloudAvailability();
|
|
22
|
+
}, [firstCheck, timeout]);
|
|
23
|
+
return isCloudAvailable;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=useIsCloudAvailable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useState","Platform","RNCloudStorage","useIsCloudAvailable","timeout","arguments","length","undefined","isCloudAvailable","setIsCloudAvailable","OS","firstCheck","Date","checkCloudAvailability","isAvailable","getTime","setTimeout","console","log"],"sourceRoot":"../../../src","sources":["hooks/useIsCloudAvailable.ts"],"mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,QAAQ,QAAQ,cAAc;AACvC,OAAOC,cAAc,MAAM,mBAAmB;;AAE9C;AACA,OAAO,MAAMC,mBAAmB,GAAG,SAAAA,CAAA,EAAkB;EAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAC9C,MAAM,CAACG,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGT,QAAQ,CAACC,QAAQ,CAACS,EAAE,KAAK,KAAK,CAAC;EAC/E,MAAM,CAACC,UAAU,CAAC,GAAGX,QAAQ,CAAC,IAAIY,IAAI,EAAE,CAAC;EAEzCb,SAAS,CAAC,MAAM;IACd,MAAMc,sBAAsB,GAAG,MAAAA,CAAA,KAAY;MACzC,MAAMC,WAAW,GAAG,MAAMZ,cAAc,CAACM,gBAAgB,EAAE;MAC3D,IAAIM,WAAW,EAAE;QACfL,mBAAmB,CAAC,IAAI,CAAC;MAC3B,CAAC,MAAM,IAAI,IAAIG,IAAI,EAAE,CAACG,OAAO,EAAE,GAAGJ,UAAU,CAACI,OAAO,EAAE,GAAGX,OAAO,GAAG,IAAI,EAAE;QACvEY,UAAU,CAACH,sBAAsB,EAAE,GAAG,CAAC;MACzC,CAAC,MAAM;QACLI,OAAO,CAACC,GAAG,CAAC,iCAAiC,CAAC;MAChD;IACF,CAAC;IACDL,sBAAsB,EAAE;EAC1B,CAAC,EAAE,CAACF,UAAU,EAAEP,OAAO,CAAC,CAAC;EAEzB,OAAOI,gBAAgB;AACzB,CAAC"}
|
package/lib/module/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import RNCloudStorage from './RNCloudStorage';
|
|
|
2
2
|
import { NativeStorageErrorCode } from './types/native';
|
|
3
3
|
export * from './types/main';
|
|
4
4
|
export * from './hooks/useCloudFile';
|
|
5
|
+
export * from './hooks/useIsCloudAvailable';
|
|
5
6
|
import NativeStorageError from './utils/NativeStorageError';
|
|
6
7
|
export { NativeStorageError };
|
|
7
8
|
export { NativeStorageErrorCode };
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["RNCloudStorage","NativeStorageErrorCode","NativeStorageError"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,OAAOA,cAAc,MAAM,kBAAkB;AAC7C,SAASC,sBAAsB,QAAQ,gBAAgB;AACvD,cAAc,cAAc;AAC5B,cAAc,sBAAsB;AACpC,OAAOC,kBAAkB,MAAM,4BAA4B;AAE3D,SAASA,kBAAkB;AAC3B,SAASD,sBAAsB;AAC/B,eAAeD,cAAc"}
|
|
1
|
+
{"version":3,"names":["RNCloudStorage","NativeStorageErrorCode","NativeStorageError"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,OAAOA,cAAc,MAAM,kBAAkB;AAC7C,SAASC,sBAAsB,QAAQ,gBAAgB;AACvD,cAAc,cAAc;AAC5B,cAAc,sBAAsB;AACpC,cAAc,6BAA6B;AAC3C,OAAOC,kBAAkB,MAAM,4BAA4B;AAE3D,SAASA,kBAAkB;AAC3B,SAASD,sBAAsB;AAC/B,eAAeD,cAAc"}
|
package/lib/module/types/main.js
CHANGED
|
@@ -7,6 +7,7 @@ export let NativeStorageErrorCode = /*#__PURE__*/function (NativeStorageErrorCod
|
|
|
7
7
|
NativeStorageErrorCode["DELETE_ERROR"] = "ERR_DELETE_ERROR";
|
|
8
8
|
NativeStorageErrorCode["STAT_ERROR"] = "ERR_STAT_ERROR";
|
|
9
9
|
NativeStorageErrorCode["UNKNOWN"] = "ERR_UNKNOWN";
|
|
10
|
+
NativeStorageErrorCode["GOOGLE_DRIVE_ACCESS_TOKEN_MISSING"] = "ERR_GOOGLE_DRIVE_ACCESS_TOKEN_MISSING";
|
|
10
11
|
return NativeStorageErrorCode;
|
|
11
12
|
}({});
|
|
12
13
|
//# sourceMappingURL=native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeStorageErrorCode"],"sourceRoot":"../../../src","sources":["types/native.ts"],"mappings":"AAUA,WAAYA,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA"}
|
|
1
|
+
{"version":3,"names":["NativeStorageErrorCode"],"sourceRoot":"../../../src","sources":["types/native.ts"],"mappings":"AAUA,WAAYA,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { StorageFileStat, StorageScope } from './types/main';
|
|
2
2
|
declare const RNCloudStorage: {
|
|
3
3
|
setGoogleDriveAccessToken: (accessToken: string) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Tests whether or not the cloud storage is available. Always returns true for Google Drive. iCloud may be
|
|
6
|
+
* unavailable right after app launch or if the user is not logged in.
|
|
7
|
+
* @returns A promise that resolves to true if the cloud storage is available, false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
isCloudAvailable: () => Promise<boolean>;
|
|
4
10
|
/**
|
|
5
11
|
* Tests whether or not the file at the given path exists.
|
|
6
12
|
* @param path The path to test.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RNCloudStorage.d.ts","sourceRoot":"","sources":["../../src/RNCloudStorage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGlE,QAAA,MAAM,cAAc;6CACuB,MAAM;
|
|
1
|
+
{"version":3,"file":"RNCloudStorage.d.ts","sourceRoot":"","sources":["../../src/RNCloudStorage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGlE,QAAA,MAAM,cAAc;6CACuB,MAAM;IAE/C;;;;OAIG;4BACyB,QAAQ,OAAO,CAAC;IAI5C;;;;;OAKG;mBACY,MAAM,SAAS,YAAY,KAAG,QAAQ,OAAO,CAAC;IAI7D;;;;;;OAMG;sBACe,MAAM,QAAQ,MAAM,SAAS,YAAY,KAAG,QAAQ,IAAI,CAAC;IAI3E;;;;;OAKG;qBACc,MAAM,SAAS,YAAY,KAAG,QAAQ,MAAM,CAAC;IAI9D;;;;;OAKG;mBACY,MAAM,SAAS,YAAY,KAAG,QAAQ,IAAI,CAAC;IAI1D;;;;;OAKG;iBACgB,MAAM,SAAS,YAAY,KAAG,QAAQ,eAAe,CAAC;CAW1E,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRNCloudStorage.d.ts","sourceRoot":"","sources":["../../src/createRNCloudStorage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,oBAAoB,MAAM,gBAAgB,CAAC;AAmCvD,MAAM,CAAC,OAAO,UAAU,oBAAoB,IAAI,oBAAoB,
|
|
1
|
+
{"version":3,"file":"createRNCloudStorage.d.ts","sourceRoot":"","sources":["../../src/createRNCloudStorage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,oBAAoB,MAAM,gBAAgB,CAAC;AAmCvD,MAAM,CAAC,OAAO,UAAU,oBAAoB,IAAI,oBAAoB,CAgBnE"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type NativeRNCloudStorage from '../types/native';
|
|
2
|
-
import type
|
|
2
|
+
import { type NativeRNCloudStorageFileStat, type NativeRNCloudStorageScope } from '../types/native';
|
|
3
3
|
declare class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
4
4
|
private static drive;
|
|
5
5
|
constructor();
|
|
6
6
|
static set accessToken(accessToken: string);
|
|
7
7
|
static get accessToken(): string;
|
|
8
|
+
isCloudAvailable: () => Promise<boolean>;
|
|
8
9
|
private getRootDirectory;
|
|
9
10
|
private resolvePathToDirectories;
|
|
10
11
|
private findParentDirectoryId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/google-drive/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,oBAAoB,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/google-drive/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,oBAAoB,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAEL,KAAK,4BAA4B,EACjC,KAAK,yBAAyB,EAC/B,MAAM,iBAAiB,CAAC;AAIzB,cAAM,oBAAqB,YAAW,oBAAoB;IACxD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAwB;;IAsB5C,WAAkB,WAAW,CAAC,WAAW,EAAE,MAAM,EAEhD;IAED,WAAkB,WAAW,IAAI,MAAM,CAEtC;IAEM,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAoB;IAEnE,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,wBAAwB;IAQhC,OAAO,CAAC,qBAAqB;YAiDf,SAAS;YAST,SAAS;IAgBjB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,OAAO,CAAC;IAU5E,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B3G,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC;IAMzE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,4BAA4B,CAAC;CAatG;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsCloudAvailable.d.ts","sourceRoot":"","sources":["../../../src/hooks/useIsCloudAvailable.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,mBAAmB,+BAmB/B,CAAC"}
|
|
@@ -2,6 +2,7 @@ import RNCloudStorage from './RNCloudStorage';
|
|
|
2
2
|
import { NativeStorageErrorCode } from './types/native';
|
|
3
3
|
export * from './types/main';
|
|
4
4
|
export * from './hooks/useCloudFile';
|
|
5
|
+
export * from './hooks/useIsCloudAvailable';
|
|
5
6
|
import NativeStorageError from './utils/NativeStorageError';
|
|
6
7
|
export { NativeStorageError };
|
|
7
8
|
export { NativeStorageErrorCode };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAClC,eAAe,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAClC,eAAe,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/types/main.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,SAAS,cAAc;IACvB,
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/types/main.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,SAAS,cAAc;IACvB,OAAO,aAAa;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,IAAI,CAAC;IACZ,WAAW,EAAE,MAAM,OAAO,CAAC;IAC3B,MAAM,EAAE,MAAM,OAAO,CAAC;CACvB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type NativeRNCloudStorageScope = 'documents' | '
|
|
1
|
+
export type NativeRNCloudStorageScope = 'documents' | 'app_data';
|
|
2
2
|
export interface NativeRNCloudStorageFileStat {
|
|
3
3
|
size: number;
|
|
4
4
|
birthtimeMs: number;
|
|
@@ -14,7 +14,8 @@ export declare enum NativeStorageErrorCode {
|
|
|
14
14
|
READ_ERROR = "ERR_READ_ERROR",
|
|
15
15
|
DELETE_ERROR = "ERR_DELETE_ERROR",
|
|
16
16
|
STAT_ERROR = "ERR_STAT_ERROR",
|
|
17
|
-
UNKNOWN = "ERR_UNKNOWN"
|
|
17
|
+
UNKNOWN = "ERR_UNKNOWN",
|
|
18
|
+
GOOGLE_DRIVE_ACCESS_TOKEN_MISSING = "ERR_GOOGLE_DRIVE_ACCESS_TOKEN_MISSING"
|
|
18
19
|
}
|
|
19
20
|
export default interface NativeRNCloudStorage {
|
|
20
21
|
fileExists: (path: string, scope: NativeRNCloudStorageScope) => Promise<boolean>;
|
|
@@ -22,5 +23,6 @@ export default interface NativeRNCloudStorage {
|
|
|
22
23
|
readFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<string>;
|
|
23
24
|
deleteFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<void>;
|
|
24
25
|
statFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<NativeRNCloudStorageFileStat>;
|
|
26
|
+
isCloudAvailable: () => Promise<boolean>;
|
|
25
27
|
}
|
|
26
28
|
//# sourceMappingURL=native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/types/native.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GAAG,WAAW,GAAG,
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/types/native.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GAAG,WAAW,GAAG,UAAU,CAAC;AAEjE,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,oBAAY,sBAAsB;IAChC,cAAc,uBAAuB;IACrC,mBAAmB,2BAA2B;IAC9C,mBAAmB,oBAAoB;IACvC,WAAW,oBAAoB;IAC/B,UAAU,mBAAmB;IAC7B,YAAY,qBAAqB;IACjC,UAAU,mBAAmB;IAC7B,OAAO,gBAAgB;IACvB,iCAAiC,0CAA0C;CAC5E;AAED,MAAM,CAAC,OAAO,WAAW,oBAAoB;IAC3C,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjF,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChH,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9E,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAAC,4BAA4B,CAAC,CAAC;IACpG,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeStorageError.d.ts","sourceRoot":"","sources":["../../../src/utils/NativeStorageError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"NativeStorageError.d.ts","sourceRoot":"","sources":["../../../src/utils/NativeStorageError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE9D,cAAM,kBAAmB,SAAQ,KAAK;IACpC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,CAAC,EAAE,GAAG,CAAC;gBAEF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,CAAC,EAAE,GAAG;CAKzE;AAED,eAAe,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-cloud-storage",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Save to & read from iCloud and Google Drive using React Native",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
7
7
|
"types": "lib/typescript/index.d.ts",
|
package/src/RNCloudStorage.ts
CHANGED
|
@@ -5,6 +5,16 @@ import type { StorageFileStat, StorageScope } from './types/main';
|
|
|
5
5
|
const nativeInstance = createRNCloudStorage();
|
|
6
6
|
const RNCloudStorage = {
|
|
7
7
|
setGoogleDriveAccessToken: (accessToken: string) => (GoogleDriveApiClient.accessToken = accessToken),
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Tests whether or not the cloud storage is available. Always returns true for Google Drive. iCloud may be
|
|
11
|
+
* unavailable right after app launch or if the user is not logged in.
|
|
12
|
+
* @returns A promise that resolves to true if the cloud storage is available, false otherwise.
|
|
13
|
+
*/
|
|
14
|
+
isCloudAvailable: async (): Promise<boolean> => {
|
|
15
|
+
return nativeInstance.isCloudAvailable();
|
|
16
|
+
},
|
|
17
|
+
|
|
8
18
|
/**
|
|
9
19
|
* Tests whether or not the file at the given path exists.
|
|
10
20
|
* @param path The path to test.
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { GDrive, MimeTypes } from 'react-native-google-drive-api-wrapper-js';
|
|
2
2
|
import type NativeRNCloudStorage from '../types/native';
|
|
3
|
-
import
|
|
3
|
+
import {
|
|
4
|
+
NativeStorageErrorCode,
|
|
5
|
+
type NativeRNCloudStorageFileStat,
|
|
6
|
+
type NativeRNCloudStorageScope,
|
|
7
|
+
} from '../types/native';
|
|
4
8
|
import type { GoogleDriveDetailedFile, GoogleDriveFile, GoogleDriveListOperationResponse } from './types';
|
|
9
|
+
import NativeStorageError from '../utils/NativeStorageError';
|
|
5
10
|
|
|
6
11
|
class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
7
12
|
private static drive: GDrive = new GDrive();
|
|
@@ -13,7 +18,10 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
13
18
|
get(target: GoogleDriveApiClient, prop: keyof GoogleDriveApiClient) {
|
|
14
19
|
if (typeof target[prop] === 'function') {
|
|
15
20
|
if (!GoogleDriveApiClient.drive.accessToken) {
|
|
16
|
-
throw new
|
|
21
|
+
throw new NativeStorageError(
|
|
22
|
+
`Google Drive access token is not set, cannot call function ${prop.toString()}`,
|
|
23
|
+
NativeStorageErrorCode.GOOGLE_DRIVE_ACCESS_TOKEN_MISSING
|
|
24
|
+
);
|
|
17
25
|
}
|
|
18
26
|
}
|
|
19
27
|
|
|
@@ -31,11 +39,13 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
31
39
|
return GoogleDriveApiClient.drive.accessToken;
|
|
32
40
|
}
|
|
33
41
|
|
|
42
|
+
public isCloudAvailable: () => Promise<boolean> = async () => true;
|
|
43
|
+
|
|
34
44
|
private getRootDirectory(scope: NativeRNCloudStorageScope): 'drive' | 'appDataFolder' {
|
|
35
45
|
switch (scope) {
|
|
36
46
|
case 'documents':
|
|
37
47
|
return 'drive';
|
|
38
|
-
case '
|
|
48
|
+
case 'app_data':
|
|
39
49
|
return 'appDataFolder';
|
|
40
50
|
}
|
|
41
51
|
}
|
|
@@ -70,16 +80,27 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
70
80
|
}
|
|
71
81
|
|
|
72
82
|
if (!topDirectoryId) {
|
|
73
|
-
throw new
|
|
83
|
+
throw new NativeStorageError(
|
|
84
|
+
`Could not find top directory with name ${directoryTree[0]}`,
|
|
85
|
+
NativeStorageErrorCode.DIRECTORY_NOT_FOUND
|
|
86
|
+
);
|
|
74
87
|
}
|
|
75
88
|
|
|
76
89
|
// now, we traverse the directories array and get the id of the last directory from the files array
|
|
77
90
|
let currentDirectoryId = topDirectoryId;
|
|
78
91
|
for (let i = 1; i < directoryTree.length; i++) {
|
|
79
92
|
const currentDirectory = files.find((f) => f.id === currentDirectoryId);
|
|
80
|
-
if (!currentDirectory)
|
|
93
|
+
if (!currentDirectory)
|
|
94
|
+
throw new NativeStorageError(
|
|
95
|
+
`Could not find directory with id ${currentDirectoryId}`,
|
|
96
|
+
NativeStorageErrorCode.DIRECTORY_NOT_FOUND
|
|
97
|
+
);
|
|
81
98
|
const nextDirectory = files.find((f) => f.name === directoryTree[i] && f.parents![0] === currentDirectoryId);
|
|
82
|
-
if (!nextDirectory)
|
|
99
|
+
if (!nextDirectory)
|
|
100
|
+
throw new NativeStorageError(
|
|
101
|
+
`Could not find directory with name ${directoryTree[i]}`,
|
|
102
|
+
NativeStorageErrorCode.DIRECTORY_NOT_FOUND
|
|
103
|
+
);
|
|
83
104
|
currentDirectoryId = nextDirectory.id;
|
|
84
105
|
}
|
|
85
106
|
|
|
@@ -107,7 +128,7 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
107
128
|
} else {
|
|
108
129
|
file = files.find((f) => f.name === filename && f.parents![0] === parentDirectoryId);
|
|
109
130
|
}
|
|
110
|
-
if (!file) throw new
|
|
131
|
+
if (!file) throw new NativeStorageError(`File not found`, NativeStorageErrorCode.FILE_NOT_FOUND);
|
|
111
132
|
return file.id;
|
|
112
133
|
}
|
|
113
134
|
|
|
@@ -116,7 +137,7 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
116
137
|
await this.getFileId(path, scope);
|
|
117
138
|
return true;
|
|
118
139
|
} catch (e: any) {
|
|
119
|
-
if (e.
|
|
140
|
+
if (e instanceof NativeStorageError && e.code === NativeStorageErrorCode.FILE_NOT_FOUND) return false;
|
|
120
141
|
else throw e;
|
|
121
142
|
}
|
|
122
143
|
}
|
|
@@ -140,7 +161,7 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
140
161
|
name: filename,
|
|
141
162
|
parents: parentDirectoryId
|
|
142
163
|
? [parentDirectoryId]
|
|
143
|
-
: scope === '
|
|
164
|
+
: scope === 'app_data'
|
|
144
165
|
? [this.getRootDirectory(scope)]
|
|
145
166
|
: undefined,
|
|
146
167
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
import RNCloudStorage from '../RNCloudStorage';
|
|
4
|
+
|
|
5
|
+
// TODO: there must be a better way to do this without a timeout?
|
|
6
|
+
export const useIsCloudAvailable = (timeout = 10) => {
|
|
7
|
+
const [isCloudAvailable, setIsCloudAvailable] = useState(Platform.OS !== 'ios');
|
|
8
|
+
const [firstCheck] = useState(new Date());
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const checkCloudAvailability = async () => {
|
|
12
|
+
const isAvailable = await RNCloudStorage.isCloudAvailable();
|
|
13
|
+
if (isAvailable) {
|
|
14
|
+
setIsCloudAvailable(true);
|
|
15
|
+
} else if (new Date().getTime() - firstCheck.getTime() < timeout * 1000) {
|
|
16
|
+
setTimeout(checkCloudAvailability, 500);
|
|
17
|
+
} else {
|
|
18
|
+
console.log('Cloud storage is not available.');
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
checkCloudAvailability();
|
|
22
|
+
}, [firstCheck, timeout]);
|
|
23
|
+
|
|
24
|
+
return isCloudAvailable;
|
|
25
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import RNCloudStorage from './RNCloudStorage';
|
|
|
2
2
|
import { NativeStorageErrorCode } from './types/native';
|
|
3
3
|
export * from './types/main';
|
|
4
4
|
export * from './hooks/useCloudFile';
|
|
5
|
+
export * from './hooks/useIsCloudAvailable';
|
|
5
6
|
import NativeStorageError from './utils/NativeStorageError';
|
|
6
7
|
|
|
7
8
|
export { NativeStorageError };
|
package/src/types/main.ts
CHANGED
package/src/types/native.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type NativeRNCloudStorageScope = 'documents' | '
|
|
1
|
+
export type NativeRNCloudStorageScope = 'documents' | 'app_data';
|
|
2
2
|
|
|
3
3
|
export interface NativeRNCloudStorageFileStat {
|
|
4
4
|
size: number;
|
|
@@ -17,6 +17,7 @@ export enum NativeStorageErrorCode {
|
|
|
17
17
|
DELETE_ERROR = 'ERR_DELETE_ERROR',
|
|
18
18
|
STAT_ERROR = 'ERR_STAT_ERROR',
|
|
19
19
|
UNKNOWN = 'ERR_UNKNOWN',
|
|
20
|
+
GOOGLE_DRIVE_ACCESS_TOKEN_MISSING = 'ERR_GOOGLE_DRIVE_ACCESS_TOKEN_MISSING',
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export default interface NativeRNCloudStorage {
|
|
@@ -25,4 +26,5 @@ export default interface NativeRNCloudStorage {
|
|
|
25
26
|
readFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<string>;
|
|
26
27
|
deleteFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<void>;
|
|
27
28
|
statFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<NativeRNCloudStorageFileStat>;
|
|
29
|
+
isCloudAvailable: () => Promise<boolean>;
|
|
28
30
|
}
|