react-native-cloud-storage 1.2.2 → 1.2.3

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.
@@ -124,36 +124,38 @@ class CloudStorage: NSObject {
124
124
  }
125
125
 
126
126
  @objc(downloadFile:withScope:withResolver:withRejecter:)
127
- func downloadFile(path: String, scope: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
128
- let fileManager = FileManager.default
129
-
130
- guard let directory = getDirectory(scope) else {
131
- reject("ERR_READ_ERROR", "Error reading directory \(scope)", NSError())
132
- return
133
- }
134
-
135
- // remove leading slashes
136
- let path = path.replacingOccurrences(of: "^/+", with: "", options: .regularExpression)
137
-
138
- // append path to scope directory and return URL
139
- let filePath = directory.appendingPathComponent(path)
140
-
141
- let isDownloadable = fileManager.isUbiquitousItem(at: filePath)
142
-
143
- if (!isDownloadable) {
144
- reject("ERR_FILE_NOT_DOWNLOADABLE", "File or directory \(path) is not an iCloud file", NSError())
145
- return
146
- }
147
- do {
148
- // trigger download of file
149
- try fileManager.startDownloadingUbiquitousItem(at: filePath)
150
- } catch {
151
- reject("ERR_FILE_NOT_DOWNLOADABLE", "File or directory \(path) not downloadable", error)
152
- return
153
- }
154
- resolve(true)
127
+ func downloadFile(path: String, scope: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
128
+ let fileManager = FileManager.default
129
+
130
+ guard let directory = getDirectory(scope) else {
131
+ let error = NSError(domain: "", code: 200, userInfo: [NSLocalizedDescriptionKey : "Error reading directory \(scope)"])
132
+ reject("ERR_READ_ERROR", "Error reading directory \(scope)", error)
133
+ return
155
134
  }
156
135
 
136
+ // remove leading slashes
137
+ let path = path.replacingOccurrences(of: "^/+", with: "", options: .regularExpression)
138
+
139
+ // append path to scope directory and return URL
140
+ let filePath = directory.appendingPathComponent(path)
141
+
142
+ let isDownloadable = fileManager.isUbiquitousItem(at: filePath)
143
+
144
+ if (!isDownloadable) {
145
+ reject("ERR_FILE_NOT_DOWNLOADABLE", "File or directory \(path) is not an iCloud file", NSError(domain: "", code: 202, userInfo: [NSLocalizedDescriptionKey : "File or directory \(path) is not an iCloud file"]))
146
+ return
147
+ }
148
+ do {
149
+ // trigger download of file
150
+ try fileManager.startDownloadingUbiquitousItem(at: filePath)
151
+ } catch {
152
+ let error = NSError(domain: "", code: 202, userInfo: [NSLocalizedDescriptionKey : "File or directory \(path) not downloadable"])
153
+ reject("ERR_FILE_NOT_DOWNLOADABLE", "File or directory \(path) not downloadable", error)
154
+ return
155
+ }
156
+ resolve(true)
157
+ }
158
+
157
159
 
158
160
  @objc(deleteFile:withScope:withResolver:withRejecter:)
159
161
  func deleteFile(path: String, scope: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-cloud-storage",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
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",