react-native-cloud-storage 0.6.0 → 1.0.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 +0 -2
- package/ios/CloudStorage.m +1 -0
- package/ios/CloudStorage.swift +106 -65
- package/ios/CloudStorage.xcodeproj/project.pbxproj +1 -3
- package/ios/CloudStorage.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/CloudStorage.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/CloudStorage.xcodeproj/project.xcworkspace/xcuserdata/max.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/CloudStorage.xcodeproj/xcuserdata/max.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/commonjs/RNCloudStorage.js +26 -12
- package/lib/commonjs/RNCloudStorage.js.map +1 -1
- package/lib/commonjs/expo-plugin/types/index.js +2 -0
- package/lib/commonjs/expo-plugin/types/index.js.map +1 -0
- package/lib/commonjs/expo-plugin/withRNCloudStorage.js +1 -1
- package/lib/commonjs/expo-plugin/withRNCloudStorage.js.map +1 -1
- package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js +3 -3
- package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js.map +1 -1
- package/lib/commonjs/google-drive/index.js +33 -4
- package/lib/commonjs/google-drive/index.js.map +1 -1
- package/lib/commonjs/hooks/useCloudFile.js +14 -3
- package/lib/commonjs/hooks/useCloudFile.js.map +1 -1
- package/lib/commonjs/hooks/useIsCloudAvailable.js +0 -2
- package/lib/commonjs/hooks/useIsCloudAvailable.js.map +1 -1
- package/lib/commonjs/index.js +10 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/native.js +1 -1
- package/lib/commonjs/utils/helpers.js +23 -0
- package/lib/commonjs/utils/helpers.js.map +1 -0
- package/lib/module/RNCloudStorage.js +26 -12
- package/lib/module/RNCloudStorage.js.map +1 -1
- package/lib/module/expo-plugin/types/index.js +2 -0
- package/lib/module/expo-plugin/types/index.js.map +1 -0
- package/lib/module/expo-plugin/withRNCloudStorage.js +1 -2
- package/lib/module/expo-plugin/withRNCloudStorage.js.map +1 -1
- package/lib/module/expo-plugin/withRNCloudStorageIos.js +3 -3
- package/lib/module/expo-plugin/withRNCloudStorageIos.js.map +1 -1
- package/lib/module/google-drive/index.js +33 -4
- package/lib/module/google-drive/index.js.map +1 -1
- package/lib/module/hooks/useCloudFile.js +15 -3
- package/lib/module/hooks/useCloudFile.js.map +1 -1
- package/lib/module/hooks/useIsCloudAvailable.js +0 -2
- package/lib/module/hooks/useIsCloudAvailable.js.map +1 -1
- package/lib/module/index.js +5 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/native.js +1 -1
- package/lib/module/utils/helpers.js +16 -0
- package/lib/module/utils/helpers.js.map +1 -0
- package/lib/typescript/RNCloudStorage.d.ts +22 -13
- package/lib/typescript/RNCloudStorage.d.ts.map +1 -1
- package/lib/typescript/expo-plugin/types/index.d.ts +7 -0
- package/lib/typescript/expo-plugin/types/index.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withRNCloudStorage.d.ts +1 -6
- package/lib/typescript/expo-plugin/withRNCloudStorage.d.ts.map +1 -1
- package/lib/typescript/expo-plugin/withRNCloudStorageIos.d.ts +3 -2
- package/lib/typescript/expo-plugin/withRNCloudStorageIos.d.ts.map +1 -1
- package/lib/typescript/google-drive/index.d.ts +8 -1
- package/lib/typescript/google-drive/index.d.ts.map +1 -1
- package/lib/typescript/hooks/useCloudFile.d.ts +13 -2
- package/lib/typescript/hooks/useCloudFile.d.ts.map +1 -1
- package/lib/typescript/hooks/useIsCloudAvailable.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +4 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/types/native.d.ts +2 -1
- package/lib/typescript/types/native.d.ts.map +1 -1
- package/lib/typescript/utils/helpers.d.ts +10 -0
- package/lib/typescript/utils/helpers.d.ts.map +1 -0
- package/package.json +24 -20
- package/react-native-cloud-storage.podspec +7 -1
- package/src/RNCloudStorage.ts +33 -19
- package/src/expo-plugin/types/index.ts +6 -0
- package/src/expo-plugin/withRNCloudStorage.ts +2 -7
- package/src/expo-plugin/withRNCloudStorageIos.ts +8 -10
- package/src/google-drive/index.ts +42 -4
- package/src/hooks/useCloudFile.ts +14 -3
- package/src/hooks/useIsCloudAvailable.ts +0 -2
- package/src/index.ts +5 -1
- package/src/types/native.ts +2 -1
- package/src/utils/helpers.ts +17 -0
package/README.md
CHANGED
|
@@ -4,8 +4,6 @@ Save to & read from iCloud and Google Drive using React Native
|
|
|
4
4
|
|
|
5
5
|
  
|
|
6
6
|
|
|
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
|
-
|
|
9
7
|
## Installation
|
|
10
8
|
|
|
11
9
|
```sh
|
package/ios/CloudStorage.m
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
RCT_EXTERN_METHOD(fileExists:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
6
6
|
RCT_EXTERN_METHOD(createFile:(NSString *)path withData:(NSString *)data withScope:(NSString *)scope withOverwrite:(BOOL)overwrite withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
7
7
|
RCT_EXTERN_METHOD(createDirectory:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
8
|
+
RCT_EXTERN_METHOD(listFiles:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
8
9
|
RCT_EXTERN_METHOD(readFile:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
9
10
|
RCT_EXTERN_METHOD(deleteFile:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
10
11
|
RCT_EXTERN_METHOD(statFile:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
package/ios/CloudStorage.swift
CHANGED
|
@@ -4,33 +4,31 @@ import Foundation
|
|
|
4
4
|
class CloudStorage: NSObject {
|
|
5
5
|
@objc(fileExists:withScope:withResolver:withRejecter:)
|
|
6
6
|
func fileExists(path: String, scope: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
7
|
-
let
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
let fileUrl: URL?
|
|
8
|
+
do {
|
|
9
|
+
fileUrl = try getFileURL(path, scope)
|
|
10
|
+
} catch let error as NSError {
|
|
11
|
+
reject(error.domain, error.userInfo["message"] as? String, error)
|
|
11
12
|
return
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
let
|
|
14
|
+
|
|
15
|
+
let fileManager = FileManager.default
|
|
16
|
+
let fileExists = fileManager.fileExists(atPath: fileUrl!.path)
|
|
15
17
|
resolve(fileExists)
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
@objc(createFile:withData:withScope:withOverwrite:withResolver:withRejecter:)
|
|
19
21
|
func createFile(path: String, data: String, scope: String, overwrite: Bool, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
let filePath = directory?.appendingPathComponent(path)
|
|
27
|
-
let fileExists = fileManager.fileExists(atPath: filePath!.path)
|
|
28
|
-
if (fileExists && !overwrite) {
|
|
29
|
-
reject("ERR_FILE_EXISTS", "File \(path) already exists", nil)
|
|
22
|
+
let fileUrl: URL?
|
|
23
|
+
do {
|
|
24
|
+
fileUrl = try getFileURL(path, scope, overwrite ? nil : false)
|
|
25
|
+
} catch let error as NSError {
|
|
26
|
+
reject(error.domain, error.userInfo["message"] as? String, error)
|
|
30
27
|
return
|
|
31
28
|
}
|
|
29
|
+
|
|
32
30
|
do {
|
|
33
|
-
try data.write(to:
|
|
31
|
+
try data.write(to: fileUrl!, atomically: true, encoding: .utf8)
|
|
34
32
|
resolve(true)
|
|
35
33
|
} catch {
|
|
36
34
|
reject("ERR_WRITE_ERROR", "Error writing file \(path)", error)
|
|
@@ -39,42 +37,54 @@ class CloudStorage: NSObject {
|
|
|
39
37
|
|
|
40
38
|
@objc(createDirectory:withScope:withResolver:withRejecter:)
|
|
41
39
|
func createDirectory(path: String, scope: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
let dirPath = directory?.appendingPathComponent(path)
|
|
49
|
-
let dirExists = fileManager.fileExists(atPath: dirPath!.path)
|
|
50
|
-
if (dirExists) {
|
|
51
|
-
reject("ERR_FILE_EXISTS", "Directory \(path) already exists", nil)
|
|
40
|
+
let directoryUrl: URL?
|
|
41
|
+
do {
|
|
42
|
+
directoryUrl = try getFileURL(path, scope, false)
|
|
43
|
+
} catch let error as NSError {
|
|
44
|
+
reject(error.domain, error.userInfo["message"] as? String, error)
|
|
52
45
|
return
|
|
53
46
|
}
|
|
47
|
+
|
|
48
|
+
let fileManager = FileManager.default
|
|
54
49
|
do {
|
|
55
|
-
try fileManager.createDirectory(at:
|
|
50
|
+
try fileManager.createDirectory(at: directoryUrl!, withIntermediateDirectories: true, attributes: nil)
|
|
56
51
|
resolve(true)
|
|
57
52
|
} catch {
|
|
58
53
|
reject("ERR_WRITE_ERROR", "Error creating directory \(path)", error)
|
|
59
54
|
}
|
|
60
55
|
}
|
|
61
56
|
|
|
62
|
-
@objc(
|
|
63
|
-
func
|
|
64
|
-
let
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
@objc(listFiles:withScope:withResolver:withRejecter:)
|
|
58
|
+
func listFiles(path: String, scope: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
59
|
+
let directoryUrl: URL?
|
|
60
|
+
do {
|
|
61
|
+
directoryUrl = try getFileURL(path, scope, true)
|
|
62
|
+
} catch let error as NSError {
|
|
63
|
+
reject(error.domain, error.userInfo["message"] as? String, error)
|
|
68
64
|
return
|
|
69
65
|
}
|
|
70
|
-
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
|
|
67
|
+
let fileManager = FileManager.default
|
|
68
|
+
do {
|
|
69
|
+
let files = try fileManager.contentsOfDirectory(atPath: directoryUrl!.path)
|
|
70
|
+
resolve(files)
|
|
71
|
+
} catch {
|
|
72
|
+
reject("ERR_READ_ERROR", "Error reading directory \(path)", error)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@objc(readFile:withScope:withResolver:withRejecter:)
|
|
77
|
+
func readFile(path: String, scope: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
78
|
+
let fileUrl: URL?
|
|
79
|
+
do {
|
|
80
|
+
fileUrl = try getFileURL(path, scope, true)
|
|
81
|
+
} catch let error as NSError {
|
|
82
|
+
reject(error.domain, error.userInfo["message"] as? String, error)
|
|
74
83
|
return
|
|
75
84
|
}
|
|
85
|
+
|
|
76
86
|
do {
|
|
77
|
-
let fileContents = try String(contentsOf:
|
|
87
|
+
let fileContents = try String(contentsOf: fileUrl!, encoding: .utf8)
|
|
78
88
|
resolve(fileContents)
|
|
79
89
|
} catch {
|
|
80
90
|
reject("ERR_READ_ERROR", "Error reading file \(path)", error)
|
|
@@ -83,20 +93,17 @@ class CloudStorage: NSObject {
|
|
|
83
93
|
|
|
84
94
|
@objc(deleteFile:withScope:withResolver:withRejecter:)
|
|
85
95
|
func deleteFile(path: String, scope: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
86
|
-
let
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
let filePath = directory?.appendingPathComponent(path)
|
|
93
|
-
let fileExists = fileManager.fileExists(atPath: filePath!.path)
|
|
94
|
-
if (!fileExists) {
|
|
95
|
-
reject("ERR_FILE_NOT_FOUND", "File \(path) not found", nil)
|
|
96
|
+
let fileUrl: URL?
|
|
97
|
+
do {
|
|
98
|
+
fileUrl = try getFileURL(path, scope, true)
|
|
99
|
+
} catch let error as NSError {
|
|
100
|
+
reject(error.domain, error.userInfo["message"] as? String, error)
|
|
96
101
|
return
|
|
97
102
|
}
|
|
103
|
+
|
|
104
|
+
let fileManager = FileManager.default
|
|
98
105
|
do {
|
|
99
|
-
try fileManager.removeItem(at:
|
|
106
|
+
try fileManager.removeItem(at: fileUrl!)
|
|
100
107
|
resolve(true)
|
|
101
108
|
} catch {
|
|
102
109
|
reject("ERR_DELETE_ERROR", "Error deleting file \(path)", error)
|
|
@@ -105,20 +112,17 @@ class CloudStorage: NSObject {
|
|
|
105
112
|
|
|
106
113
|
@objc(statFile:withScope:withResolver:withRejecter:)
|
|
107
114
|
func statFile(path: String, scope: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
108
|
-
let
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
let filePath = directory?.appendingPathComponent(path)
|
|
115
|
-
let fileExists = fileManager.fileExists(atPath: filePath!.path)
|
|
116
|
-
if (!fileExists) {
|
|
117
|
-
reject("ERR_FILE_NOT_FOUND", "File \(path) not found", nil)
|
|
115
|
+
let fileUrl: URL?
|
|
116
|
+
do {
|
|
117
|
+
fileUrl = try getFileURL(path, scope, true)
|
|
118
|
+
} catch let error as NSError {
|
|
119
|
+
reject(error.domain, error.userInfo["message"] as? String, error)
|
|
118
120
|
return
|
|
119
121
|
}
|
|
122
|
+
|
|
123
|
+
let fileManager = FileManager.default
|
|
120
124
|
do {
|
|
121
|
-
let attributes = try fileManager.attributesOfItem(atPath:
|
|
125
|
+
let attributes = try fileManager.attributesOfItem(atPath: fileUrl!.path)
|
|
122
126
|
let size = attributes[FileAttributeKey.size] as! UInt64
|
|
123
127
|
let birthtime = attributes[FileAttributeKey.creationDate] as! Date
|
|
124
128
|
let mtime = attributes[FileAttributeKey.modificationDate] as! Date
|
|
@@ -143,18 +147,55 @@ class CloudStorage: NSObject {
|
|
|
143
147
|
resolve(token != nil)
|
|
144
148
|
}
|
|
145
149
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
/**
|
|
151
|
+
Returns the iCloud directory URL for the given scope.
|
|
152
|
+
|
|
153
|
+
- Parameter scope: The scope of the directory. Can be either "documents" or "app_data".
|
|
154
|
+
- Returns: The URL of the iCloud directory.
|
|
155
|
+
*/
|
|
150
156
|
private func getDirectory(_ scope: String) -> URL? {
|
|
151
157
|
let fileManager = FileManager.default
|
|
152
158
|
let isDocumentDirectory = scope.caseInsensitiveCompare("documents") == .orderedSame
|
|
153
159
|
let ubiquityURL = fileManager.url(forUbiquityContainerIdentifier: nil)
|
|
160
|
+
print(ubiquityURL)
|
|
154
161
|
if (isDocumentDirectory) {
|
|
155
162
|
return fileManager.urls(for: .documentDirectory, in: .userDomainMask).first
|
|
156
163
|
} else {
|
|
157
164
|
return ubiquityURL
|
|
158
165
|
}
|
|
159
166
|
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
Parses a given path and directory scope to a full file URL. Does not check if the file exists.
|
|
170
|
+
|
|
171
|
+
- Parameter path: The path of the file.
|
|
172
|
+
- Parameter scope: The scope of the directory. Can be either "documents" or "app_data".
|
|
173
|
+
- Parameter shouldExist: Whether the file should exist. If true, throws an error if the file does not exist. If false, throws an error if the file exists. If nil, does not check if the file exists.
|
|
174
|
+
- Returns: The full URL of the file.
|
|
175
|
+
- Throws: An NSError if the scope directory couldn't be found or the file should exist but doesn't or vice versa.
|
|
176
|
+
*/
|
|
177
|
+
private func getFileURL(_ path: String, _ scope: String, _ shouldExist: Bool? = nil) throws -> URL? {
|
|
178
|
+
let fileManager = FileManager.default
|
|
179
|
+
|
|
180
|
+
guard let directory = getDirectory(scope) else {
|
|
181
|
+
throw NSError(domain: "ERR_DIRECTORY_NOT_FOUND", code: 0, userInfo: ["message": "Directory for scope \(scope) not found"])
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// remove leading slashes
|
|
185
|
+
let path = path.replacingOccurrences(of: "^/+", with: "", options: .regularExpression)
|
|
186
|
+
|
|
187
|
+
// append path to scope directory and return URL
|
|
188
|
+
let filePath = directory.appendingPathComponent(path)
|
|
189
|
+
|
|
190
|
+
if (shouldExist != nil) {
|
|
191
|
+
let fileExists = fileManager.fileExists(atPath: filePath.path)
|
|
192
|
+
if (shouldExist! && !fileExists) {
|
|
193
|
+
throw NSError(domain: "ERR_FILE_NOT_FOUND", code: 0, userInfo: ["message": "File or directory \(path) not found"])
|
|
194
|
+
} else if (!shouldExist! && fileExists) {
|
|
195
|
+
throw NSError(domain: "ERR_FILE_EXISTS", code: 0, userInfo: ["message": "File or directory \(path) already exists"])
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return filePath
|
|
200
|
+
}
|
|
160
201
|
}
|
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
objects = {
|
|
8
8
|
|
|
9
9
|
/* Begin PBXBuildFile section */
|
|
10
|
-
|
|
11
|
-
F4FF95D7245B92E800C19C63 /* CloudStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* CloudStorage.swift */; };
|
|
10
|
+
F4FF95D7245B92E800C19C63 /* CloudStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* CloudStorage.swift */; };
|
|
12
11
|
/* End PBXBuildFile section */
|
|
13
12
|
|
|
14
13
|
/* Begin PBXCopyFilesBuildPhase section */
|
|
@@ -117,7 +116,6 @@
|
|
|
117
116
|
buildActionMask = 2147483647;
|
|
118
117
|
files = (
|
|
119
118
|
F4FF95D7245B92E800C19C63 /* CloudStorage.swift in Sources */,
|
|
120
|
-
B3E7B58A1CC2AC0600A0062D /* CloudStorage.m in Sources */,
|
|
121
119
|
);
|
|
122
120
|
runOnlyForDeploymentPostprocessing = 0;
|
|
123
121
|
};
|
|
Binary file
|
package/ios/CloudStorage.xcodeproj/xcuserdata/max.xcuserdatad/xcschemes/xcschememanagement.plist
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>SchemeUserState</key>
|
|
6
|
+
<dict>
|
|
7
|
+
<key>CloudStorage.xcscheme_^#shared#^_</key>
|
|
8
|
+
<dict>
|
|
9
|
+
<key>orderHint</key>
|
|
10
|
+
<integer>0</integer>
|
|
11
|
+
</dict>
|
|
12
|
+
</dict>
|
|
13
|
+
</dict>
|
|
14
|
+
</plist>
|
|
@@ -6,10 +6,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _createRNCloudStorage = _interopRequireDefault(require("./createRNCloudStorage"));
|
|
8
8
|
var _googleDrive = _interopRequireDefault(require("./google-drive"));
|
|
9
|
+
var _main = require("./types/main");
|
|
9
10
|
var _reactNative = require("react-native");
|
|
11
|
+
var _helpers = require("./utils/helpers");
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
const nativeInstance = (0, _createRNCloudStorage.default)();
|
|
14
|
+
let defaultScope = _main.CloudStorageScope.AppData;
|
|
12
15
|
const RNCloudStorage = {
|
|
16
|
+
getDefaultScope: () => defaultScope,
|
|
17
|
+
setDefaultScope: scope => defaultScope = scope,
|
|
13
18
|
getGoogleDriveAccessToken: () => _googleDrive.default.accessToken,
|
|
14
19
|
setGoogleDriveAccessToken: accessToken => _googleDrive.default.accessToken = accessToken,
|
|
15
20
|
setThrowOnFilesWithSameName: enable => _googleDrive.default.throwOnFilesWithSameName = enable,
|
|
@@ -32,57 +37,66 @@ const RNCloudStorage = {
|
|
|
32
37
|
/**
|
|
33
38
|
* Tests whether or not the file at the given path exists.
|
|
34
39
|
* @param path The path to test.
|
|
35
|
-
* @param scope The directory scope the path is in.
|
|
40
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
36
41
|
* @returns A promise that resolves to true if the path exists, false otherwise.
|
|
37
42
|
*/
|
|
38
43
|
exists: (path, scope) => {
|
|
39
|
-
return nativeInstance.fileExists(path, scope);
|
|
44
|
+
return nativeInstance.fileExists((0, _helpers.verifyLeadingSlash)(path), scope ?? defaultScope);
|
|
40
45
|
},
|
|
41
46
|
/**
|
|
42
47
|
* Writes to the file at the given path, creating it if it doesn't exist or overwriting it if it does.
|
|
43
48
|
* @param path The file to write to.
|
|
44
49
|
* @param data The data to write.
|
|
45
|
-
* @param scope The directory scope the path is in.
|
|
50
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
46
51
|
* @returns A promise that resolves when the file has been written.
|
|
47
52
|
*/
|
|
48
53
|
writeFile: (path, data, scope) => {
|
|
49
|
-
return nativeInstance.createFile(path, data, scope, true);
|
|
54
|
+
return nativeInstance.createFile((0, _helpers.verifyLeadingSlash)(path), data, scope ?? defaultScope, true);
|
|
50
55
|
},
|
|
51
56
|
/**
|
|
52
57
|
* Creates a new directory at the given path.
|
|
53
58
|
* @param path The directory to create.
|
|
54
|
-
* @param scope The directory scope the path is in.
|
|
59
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
55
60
|
* @returns A promise that resolves when the directory has been created.
|
|
56
61
|
*/
|
|
57
62
|
mkdir: (path, scope) => {
|
|
58
|
-
return nativeInstance.createDirectory(path, scope);
|
|
63
|
+
return nativeInstance.createDirectory((0, _helpers.verifyLeadingSlash)(path), scope ?? defaultScope);
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Lists the contents of the directory at the given path.
|
|
67
|
+
* @param path The directory to list.
|
|
68
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
69
|
+
* @returns A promise that resolves to an array of file names, excluding '.' and '..'.
|
|
70
|
+
*/
|
|
71
|
+
readdir: (path, scope) => {
|
|
72
|
+
return nativeInstance.listFiles((0, _helpers.verifyLeadingSlash)(path), scope ?? defaultScope);
|
|
59
73
|
},
|
|
60
74
|
/**
|
|
61
75
|
* Reads the contents of the file at the given path.
|
|
62
76
|
* @param path The file to read.
|
|
63
|
-
* @param scope The directory scope the path is in.
|
|
77
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
64
78
|
* @returns A promise that resolves to the contents of the file.
|
|
65
79
|
*/
|
|
66
80
|
readFile: (path, scope) => {
|
|
67
|
-
return nativeInstance.readFile(path, scope);
|
|
81
|
+
return nativeInstance.readFile((0, _helpers.verifyLeadingSlash)(path), scope ?? defaultScope);
|
|
68
82
|
},
|
|
69
83
|
/**
|
|
70
84
|
* Deletes the file at the given path.
|
|
71
85
|
* @param path The file to delete.
|
|
72
|
-
* @param scope The directory scope the path is in.
|
|
86
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
73
87
|
* @returns A promise that resolves when the file has been deleted.
|
|
74
88
|
*/
|
|
75
89
|
unlink: (path, scope) => {
|
|
76
|
-
return nativeInstance.deleteFile(path, scope);
|
|
90
|
+
return nativeInstance.deleteFile((0, _helpers.verifyLeadingSlash)(path), scope ?? defaultScope);
|
|
77
91
|
},
|
|
78
92
|
/**
|
|
79
93
|
* Gets the size, creation time, and modification time of the file at the given path.
|
|
80
94
|
* @param path The file to stat.
|
|
81
|
-
* @param scope The directory scope the path is in.
|
|
95
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
82
96
|
* @returns A promise that resolves to the CloudStorageFileStat object.
|
|
83
97
|
*/
|
|
84
98
|
stat: async (path, scope) => {
|
|
85
|
-
const native = await nativeInstance.statFile(path, scope);
|
|
99
|
+
const native = await nativeInstance.statFile((0, _helpers.verifyLeadingSlash)(path), scope ?? defaultScope);
|
|
86
100
|
return {
|
|
87
101
|
...native,
|
|
88
102
|
birthtime: new Date(native.birthtimeMs),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_createRNCloudStorage","_interopRequireDefault","require","_googleDrive","_reactNative","obj","__esModule","default","nativeInstance","createRNCloudStorage","RNCloudStorage","getGoogleDriveAccessToken","GoogleDriveApiClient","accessToken","setGoogleDriveAccessToken","setThrowOnFilesWithSameName","enable","throwOnFilesWithSameName","subscribeToFilesWithSameName","Platform","OS","subscriber","remove","bind","isCloudAvailable","exists","path","
|
|
1
|
+
{"version":3,"names":["_createRNCloudStorage","_interopRequireDefault","require","_googleDrive","_main","_reactNative","_helpers","obj","__esModule","default","nativeInstance","createRNCloudStorage","defaultScope","CloudStorageScope","AppData","RNCloudStorage","getDefaultScope","setDefaultScope","scope","getGoogleDriveAccessToken","GoogleDriveApiClient","accessToken","setGoogleDriveAccessToken","setThrowOnFilesWithSameName","enable","throwOnFilesWithSameName","subscribeToFilesWithSameName","Platform","OS","subscriber","remove","bind","isCloudAvailable","exists","path","fileExists","verifyLeadingSlash","writeFile","data","createFile","mkdir","createDirectory","readdir","listFiles","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,OA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,KAAK,IAAIN,YAAY,CAAC;IAE7F,OAAO;MACL,GAAGoC,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,GAEa1C,cAAc;AAAA2C,OAAA,CAAAjD,OAAA,GAAAgD,QAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../../src","sources":["expo-plugin/types/index.ts"],"mappings":""}
|
|
@@ -8,7 +8,7 @@ var _withRNCloudStorageIos = _interopRequireDefault(require("./withRNCloudStorag
|
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
9
|
// Android config plugin not needed as there's no native code to configure.
|
|
10
10
|
|
|
11
|
-
const withRNCloudStorage = (config, options) => (0, _withRNCloudStorageIos.default)(config,
|
|
11
|
+
const withRNCloudStorage = (config, options) => (0, _withRNCloudStorageIos.default)(config, options);
|
|
12
12
|
var _default = withRNCloudStorage;
|
|
13
13
|
exports.default = _default;
|
|
14
14
|
//# sourceMappingURL=withRNCloudStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_withRNCloudStorageIos","_interopRequireDefault","require","obj","__esModule","default","withRNCloudStorage","config","options","withRNCloudStorageIos","
|
|
1
|
+
{"version":3,"names":["_withRNCloudStorageIos","_interopRequireDefault","require","obj","__esModule","default","withRNCloudStorage","config","options","withRNCloudStorageIos","_default","exports"],"sourceRoot":"../../../src","sources":["expo-plugin/withRNCloudStorage.ts"],"mappings":";;;;;;AACA,IAAAA,sBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4D,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAG5D;;AAEA,MAAMG,kBAAmE,GAAGA,CAACC,MAAM,EAAEC,OAAO,KAC1F,IAAAC,8BAAqB,EAACF,MAAM,EAAEC,OAAO,CAAC;AAAC,IAAAE,QAAA,GAE1BJ,kBAAkB;AAAAK,OAAA,CAAAN,OAAA,GAAAK,QAAA"}
|
|
@@ -20,7 +20,7 @@ const withRNCloudStorageInfoPlist = config => (0, _configPlugins.withInfoPlist)(
|
|
|
20
20
|
};
|
|
21
21
|
return newConfig;
|
|
22
22
|
});
|
|
23
|
-
const withRNCloudStorageEntitlementsPlist = (config,
|
|
23
|
+
const withRNCloudStorageEntitlementsPlist = (config, options) => (0, _configPlugins.withEntitlementsPlist)(config, async newConfig => {
|
|
24
24
|
var _config$ios2;
|
|
25
25
|
if (!((_config$ios2 = config.ios) !== null && _config$ios2 !== void 0 && _config$ios2.bundleIdentifier)) {
|
|
26
26
|
throw new Error('Missing iOS bundle identifier');
|
|
@@ -28,12 +28,12 @@ const withRNCloudStorageEntitlementsPlist = (config, iCloudContainerEnvironment)
|
|
|
28
28
|
const entitlementsPlist = newConfig.modResults;
|
|
29
29
|
entitlementsPlist['com.apple.developer.icloud-container-identifiers'] = [`iCloud.${config.ios.bundleIdentifier}`];
|
|
30
30
|
entitlementsPlist['com.apple.developer.icloud-services'] = ['CloudDocuments'];
|
|
31
|
-
entitlementsPlist['com.apple.developer.icloud-container-environment'] = iCloudContainerEnvironment;
|
|
31
|
+
entitlementsPlist['com.apple.developer.icloud-container-environment'] = (options === null || options === void 0 ? void 0 : options.iCloudContainerEnvironment) ?? 'Production';
|
|
32
32
|
entitlementsPlist['com.apple.developer.ubiquity-container-identifiers'] = [`iCloud.${config.ios.bundleIdentifier}`];
|
|
33
33
|
entitlementsPlist['com.apple.developer.ubiquity-kvstore-identifier'] = `$(TeamIdentifierPrefix)${config.ios.bundleIdentifier}`;
|
|
34
34
|
return newConfig;
|
|
35
35
|
});
|
|
36
|
-
const withRNCloudStorageIos = (config,
|
|
36
|
+
const withRNCloudStorageIos = (config, options) => (0, _configPlugins.withPlugins)(config, [withRNCloudStorageInfoPlist, [withRNCloudStorageEntitlementsPlist, options]]);
|
|
37
37
|
var _default = withRNCloudStorageIos;
|
|
38
38
|
exports.default = _default;
|
|
39
39
|
//# sourceMappingURL=withRNCloudStorageIos.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_configPlugins","require","withRNCloudStorageInfoPlist","config","withInfoPlist","newConfig","_config$ios","ios","bundleIdentifier","Error","infoPlist","modResults","NSUbiquitousContainers","NSUbiquitousContainerIsDocumentScopePublic","NSUbiquitousContainerSupportedFolderLevels","NSUbiquitousContainerName","slug","withRNCloudStorageEntitlementsPlist","
|
|
1
|
+
{"version":3,"names":["_configPlugins","require","withRNCloudStorageInfoPlist","config","withInfoPlist","newConfig","_config$ios","ios","bundleIdentifier","Error","infoPlist","modResults","NSUbiquitousContainers","NSUbiquitousContainerIsDocumentScopePublic","NSUbiquitousContainerSupportedFolderLevels","NSUbiquitousContainerName","slug","withRNCloudStorageEntitlementsPlist","options","withEntitlementsPlist","_config$ios2","entitlementsPlist","iCloudContainerEnvironment","withRNCloudStorageIos","withPlugins","_default","exports","default"],"sourceRoot":"../../../src","sources":["expo-plugin/withRNCloudStorageIos.ts"],"mappings":";;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAGA,MAAMC,2BAAyC,GAAIC,MAAM,IACvD,IAAAC,4BAAa,EAACD,MAAM,EAAE,MAAOE,SAAS,IAAK;EAAA,IAAAC,WAAA;EACzC,IAAI,GAAAA,WAAA,GAACH,MAAM,CAACI,GAAG,cAAAD,WAAA,eAAVA,WAAA,CAAYE,gBAAgB,GAAE;IACjC,MAAM,IAAIC,KAAK,CAAC,+BAA+B,CAAC;EAClD;EACA,MAAMC,SAAS,GAAGL,SAAS,CAACM,U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AAC,CAAC,CAAC;AAAC,IAAAO,QAAA,GAEtFF,qBAAqB;AAAAG,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -96,7 +96,20 @@ class GoogleDriveApiClient {
|
|
|
96
96
|
}
|
|
97
97
|
return currentDirectoryId;
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Gets the Google Drive ID of the root directory for the given scope.
|
|
102
|
+
* @param scope The scope to get the root directory for.
|
|
103
|
+
* @returns A promise that resolves to the ID of the root directory or null if it could not be found.
|
|
104
|
+
*/
|
|
105
|
+
async getRootDirectoryId(scope) {
|
|
106
|
+
const files = await this.listInternalFiles(scope);
|
|
107
|
+
for (const file of files) {
|
|
108
|
+
if (!files.find(f => f.id === file.parents[0])) return file.parents[0] ?? null;
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
async listInternalFiles(scope) {
|
|
100
113
|
const files = await GoogleDriveApiClient.drive.files.list({
|
|
101
114
|
spaces: [this.getRootDirectory(scope)],
|
|
102
115
|
fields: 'files(id,kind,mimeType,name,parents,spaces)'
|
|
@@ -123,7 +136,12 @@ class GoogleDriveApiClient {
|
|
|
123
136
|
async getFileId(path, scope) {
|
|
124
137
|
let throwIfDirectory = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
125
138
|
try {
|
|
126
|
-
const files = await this.
|
|
139
|
+
const files = await this.listInternalFiles(scope);
|
|
140
|
+
if (path === '' || path === '/') {
|
|
141
|
+
const rootDirectoryId = await this.getRootDirectoryId(scope);
|
|
142
|
+
if (!rootDirectoryId) throw new _CloudStorageError.default(`Root directory in scope ${scope} not found`, _native.CloudStorageErrorCode.DIRECTORY_NOT_FOUND);
|
|
143
|
+
return rootDirectoryId;
|
|
144
|
+
}
|
|
127
145
|
const {
|
|
128
146
|
directories,
|
|
129
147
|
filename
|
|
@@ -188,7 +206,7 @@ class GoogleDriveApiClient {
|
|
|
188
206
|
}
|
|
189
207
|
const uploader = GoogleDriveApiClient.drive.files.newMultipartUploader().setData(data, _reactNativeGoogleDriveApiWrapperJs.MimeTypes.TEXT);
|
|
190
208
|
if (fileId) uploader.setIdOfFileToUpdate(fileId);else {
|
|
191
|
-
const files = await this.
|
|
209
|
+
const files = await this.listInternalFiles(scope);
|
|
192
210
|
const {
|
|
193
211
|
directories,
|
|
194
212
|
filename
|
|
@@ -201,6 +219,17 @@ class GoogleDriveApiClient {
|
|
|
201
219
|
}
|
|
202
220
|
await uploader.execute();
|
|
203
221
|
}
|
|
222
|
+
async listFiles(path, scope) {
|
|
223
|
+
const allFiles = await this.listInternalFiles(scope);
|
|
224
|
+
if (path !== '') {
|
|
225
|
+
const fileId = await this.getFileId(path, scope, false);
|
|
226
|
+
const files = allFiles.filter(f => (f.parents ?? [])[0] === fileId);
|
|
227
|
+
return Array.from(new Set(files.map(f => f.name)));
|
|
228
|
+
} else {
|
|
229
|
+
const rootDirectoryId = await this.getRootDirectoryId(scope);
|
|
230
|
+
return Array.from(new Set(allFiles.filter(f => (f.parents ?? [])[0] === rootDirectoryId).map(f => f.name)));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
204
233
|
async createDirectory(path, scope) {
|
|
205
234
|
try {
|
|
206
235
|
await this.getFileId(path, scope);
|
|
@@ -215,7 +244,7 @@ class GoogleDriveApiClient {
|
|
|
215
244
|
}
|
|
216
245
|
}
|
|
217
246
|
const uploader = GoogleDriveApiClient.drive.files.newMetadataOnlyUploader();
|
|
218
|
-
const files = await this.
|
|
247
|
+
const files = await this.listInternalFiles(scope);
|
|
219
248
|
const {
|
|
220
249
|
directories,
|
|
221
250
|
filename
|