react-native-cloud-storage 1.5.0 → 1.5.1
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/LICENSE +1 -1
- package/README.md +5 -6
- package/ios/CloudStorage.swift +262 -52
- package/ios/CloudStorage.xcodeproj/project.pbxproj +0 -28
- 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 +22 -0
- package/ios/CloudStorageEventEmitter.swift +4 -4
- package/lib/commonjs/RNCloudStorage.js +66 -361
- package/lib/commonjs/RNCloudStorage.js.map +1 -1
- package/lib/commonjs/createRNCloudStorage.js +48 -0
- package/lib/commonjs/createRNCloudStorage.js.map +1 -0
- package/lib/commonjs/expo-plugin/types/index.js.map +1 -1
- package/lib/commonjs/expo-plugin/withRNCloudStorage.js +3 -2
- package/lib/commonjs/expo-plugin/withRNCloudStorage.js.map +1 -1
- package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js +7 -4
- package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js.map +1 -1
- package/lib/commonjs/google-drive/client.js +20 -16
- package/lib/commonjs/google-drive/client.js.map +1 -1
- package/lib/commonjs/google-drive/index.js +64 -42
- package/lib/commonjs/google-drive/index.js.map +1 -1
- package/lib/commonjs/google-drive/types.js +2 -1
- package/lib/commonjs/google-drive/types.js.map +1 -1
- package/lib/commonjs/hooks/useCloudFile.js +17 -14
- package/lib/commonjs/hooks/useCloudFile.js.map +1 -1
- package/lib/commonjs/hooks/useIsCloudAvailable.js +21 -11
- package/lib/commonjs/hooks/useIsCloudAvailable.js.map +1 -1
- package/lib/commonjs/index.js +7 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/main.js +3 -8
- package/lib/commonjs/types/main.js.map +1 -1
- package/lib/commonjs/types/native.js +3 -3
- package/lib/commonjs/types/native.js.map +1 -1
- package/lib/commonjs/utils/CloudStorageError.js +2 -1
- package/lib/commonjs/utils/CloudStorageError.js.map +1 -1
- package/lib/commonjs/utils/helpers.js +15 -8
- package/lib/commonjs/utils/helpers.js.map +1 -1
- package/lib/module/RNCloudStorage.js +65 -362
- package/lib/module/RNCloudStorage.js.map +1 -1
- package/lib/module/createRNCloudStorage.js +41 -0
- package/lib/module/createRNCloudStorage.js.map +1 -0
- package/lib/module/expo-plugin/types/index.js +1 -1
- package/lib/module/expo-plugin/types/index.js.map +1 -1
- package/lib/module/expo-plugin/withRNCloudStorage.js +0 -2
- package/lib/module/expo-plugin/withRNCloudStorage.js.map +1 -1
- package/lib/module/expo-plugin/withRNCloudStorageIos.js +5 -5
- package/lib/module/expo-plugin/withRNCloudStorageIos.js.map +1 -1
- package/lib/module/google-drive/client.js +20 -18
- package/lib/module/google-drive/client.js.map +1 -1
- package/lib/module/google-drive/index.js +62 -41
- package/lib/module/google-drive/index.js.map +1 -1
- package/lib/module/google-drive/types.js +0 -2
- package/lib/module/google-drive/types.js.map +1 -1
- package/lib/module/hooks/useCloudFile.js +16 -15
- package/lib/module/hooks/useCloudFile.js.map +1 -1
- package/lib/module/hooks/useIsCloudAvailable.js +21 -13
- package/lib/module/hooks/useIsCloudAvailable.js.map +1 -1
- package/lib/module/index.js +5 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/main.js +0 -9
- package/lib/module/types/main.js.map +1 -1
- package/lib/module/types/native.js +1 -4
- package/lib/module/types/native.js.map +1 -1
- package/lib/module/utils/CloudStorageError.js +0 -2
- package/lib/module/utils/CloudStorageError.js.map +1 -1
- package/lib/module/utils/helpers.js +13 -8
- package/lib/module/utils/helpers.js.map +1 -1
- package/lib/typescript/RNCloudStorage.d.ts +39 -159
- package/lib/typescript/RNCloudStorage.d.ts.map +1 -1
- package/lib/typescript/createRNCloudStorage.d.ts +3 -0
- package/lib/typescript/createRNCloudStorage.d.ts.map +1 -0
- package/lib/typescript/google-drive/client.d.ts +3 -3
- package/lib/typescript/google-drive/client.d.ts.map +1 -1
- package/lib/typescript/google-drive/index.d.ts +18 -6
- package/lib/typescript/google-drive/index.d.ts.map +1 -1
- package/lib/typescript/hooks/useCloudFile.d.ts +7 -4
- package/lib/typescript/hooks/useCloudFile.d.ts.map +1 -1
- package/lib/typescript/hooks/useIsCloudAvailable.d.ts +2 -3
- package/lib/typescript/hooks/useIsCloudAvailable.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +4 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/types/main.d.ts +0 -33
- package/lib/typescript/types/main.d.ts.map +1 -1
- package/lib/typescript/types/native.d.ts +1 -2
- package/lib/typescript/types/native.d.ts.map +1 -1
- package/lib/typescript/utils/helpers.d.ts +9 -2
- package/lib/typescript/utils/helpers.d.ts.map +1 -1
- package/package.json +11 -9
- package/src/RNCloudStorage.ts +68 -387
- package/src/createRNCloudStorage.ts +53 -0
- package/src/google-drive/client.ts +7 -8
- package/src/google-drive/index.ts +63 -38
- package/src/hooks/useCloudFile.ts +16 -13
- package/src/hooks/useIsCloudAvailable.ts +25 -12
- package/src/index.ts +5 -0
- package/src/types/main.ts +0 -38
- package/src/types/native.ts +1 -2
- package/src/utils/helpers.ts +15 -8
- package/ios/Utils/CloudKitUtils.swift +0 -112
- package/ios/Utils/CloudStorageError.swift +0 -78
- package/ios/Utils/FileUtils.swift +0 -132
- package/ios/Utils/Promise.swift +0 -58
- package/ios/Utils/Types.swift +0 -36
- package/lib/commonjs/package.json +0 -1
- package/lib/module/package.json +0 -1
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// FileUtils.swift
|
|
3
|
-
// CloudStorage
|
|
4
|
-
//
|
|
5
|
-
// Created by Maximilian Krause on 27.09.24.
|
|
6
|
-
// Copyright © 2024 Kuatsu App Agency. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
import Foundation
|
|
10
|
-
|
|
11
|
-
enum FileUtils {
|
|
12
|
-
private static let fileManager = FileManager.default
|
|
13
|
-
|
|
14
|
-
static func checkFileExists(fileUrl: URL) throws -> Bool {
|
|
15
|
-
fileManager.fileExists(atPath: fileUrl.path)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
Reads a file and returns its content as a string.
|
|
20
|
-
|
|
21
|
-
- Parameter fileUrl: The URL of the file to read.
|
|
22
|
-
- Returns: The content of the file as a string.
|
|
23
|
-
- Throws: An NSError if the file couldn't be read.
|
|
24
|
-
*/
|
|
25
|
-
static func readFile(fileUrl: URL) throws -> String {
|
|
26
|
-
if try !checkFileExists(fileUrl: fileUrl) {
|
|
27
|
-
throw CloudStorageError.fileNotFound(path: fileUrl.path)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
do {
|
|
31
|
-
let fileContents = try String(contentsOf: fileUrl, encoding: .utf8)
|
|
32
|
-
return fileContents
|
|
33
|
-
} catch {
|
|
34
|
-
throw CloudStorageError.readError(path: fileUrl.path)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
Writes a string to a file. If the file already exists, it will be overwritten.
|
|
40
|
-
|
|
41
|
-
- Parameter fileUrl: The URL of the file to write to.
|
|
42
|
-
- Parameter content: The string to write to the file.
|
|
43
|
-
- Throws: An NSError if the file couldn't be written to.
|
|
44
|
-
*/
|
|
45
|
-
static func writeFile(fileUrl: URL, content: String) throws {
|
|
46
|
-
do {
|
|
47
|
-
try content.write(to: fileUrl, atomically: true, encoding: .utf8)
|
|
48
|
-
} catch {
|
|
49
|
-
throw CloudStorageError.writeError(path: fileUrl.path)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
Creates a directory.
|
|
55
|
-
|
|
56
|
-
- Parameter directoryUrl: The URL of the directory to create.
|
|
57
|
-
- Throws: An NSError if the directory couldn't be created.
|
|
58
|
-
*/
|
|
59
|
-
static func createDirectory(directoryUrl: URL) throws {
|
|
60
|
-
do {
|
|
61
|
-
try fileManager.createDirectory(at: directoryUrl, withIntermediateDirectories: true, attributes: nil)
|
|
62
|
-
} catch {
|
|
63
|
-
throw CloudStorageError.writeError(path: directoryUrl.path)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
Lists the files in a directory.
|
|
69
|
-
|
|
70
|
-
- Parameter directoryUrl: The URL of the directory to list the files of.
|
|
71
|
-
- Returns: An array of Strings representing the file names.
|
|
72
|
-
- Throws: An NSError if the directory couldn't be read.
|
|
73
|
-
*/
|
|
74
|
-
static func listFiles(directoryUrl: URL) throws -> [String] {
|
|
75
|
-
do {
|
|
76
|
-
let fileUrls = try fileManager.contentsOfDirectory(atPath: directoryUrl.path)
|
|
77
|
-
return fileUrls
|
|
78
|
-
} catch {
|
|
79
|
-
throw CloudStorageError.readError(path: directoryUrl.path)
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
Deletes a file or directory.
|
|
85
|
-
|
|
86
|
-
- Parameter fileUrl: The URL of the file or directory to delete.
|
|
87
|
-
- Throws: An NSError if the file / directory couldn't be deleted.
|
|
88
|
-
*/
|
|
89
|
-
static func deleteFileOrDirectory(fileUrl: URL) throws {
|
|
90
|
-
do {
|
|
91
|
-
try fileManager.removeItem(at: fileUrl)
|
|
92
|
-
} catch {
|
|
93
|
-
throw CloudStorageError.deleteError(path: fileUrl.path)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
Gets the stats of a file.
|
|
99
|
-
|
|
100
|
-
- Parameter fileUrl: The URL of the file to get the stats of.
|
|
101
|
-
- Returns: The stats of the file.
|
|
102
|
-
- Throws: An NSError if the stats couldn't be retrieved.
|
|
103
|
-
*/
|
|
104
|
-
static func statFile(fileUrl: URL) throws -> FileStat {
|
|
105
|
-
if try !checkFileExists(fileUrl: fileUrl) {
|
|
106
|
-
throw CloudStorageError.fileNotFound(path: fileUrl.path)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
do {
|
|
110
|
-
let attributes = try fileManager.attributesOfItem(atPath: fileUrl.path)
|
|
111
|
-
let size = attributes[FileAttributeKey.size] as! UInt64
|
|
112
|
-
let birthtime = attributes[FileAttributeKey.creationDate] as! Date
|
|
113
|
-
let mtime = attributes[FileAttributeKey.modificationDate] as! Date
|
|
114
|
-
let isDirectory = attributes[FileAttributeKey.type] as! FileAttributeType == FileAttributeType.typeDirectory
|
|
115
|
-
let isFile = attributes[FileAttributeKey.type] as! FileAttributeType == FileAttributeType.typeRegular
|
|
116
|
-
|
|
117
|
-
return FileStat(
|
|
118
|
-
size: size,
|
|
119
|
-
birthtimeMs: birthtime.timeIntervalSince1970 * 1000,
|
|
120
|
-
mtimeMs: mtime.timeIntervalSince1970 * 1000,
|
|
121
|
-
isDirectory: isDirectory,
|
|
122
|
-
isFile: isFile
|
|
123
|
-
)
|
|
124
|
-
} catch {
|
|
125
|
-
throw CloudStorageError.statError(path: fileUrl.path)
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
static func sanitizePath(path: String) -> String {
|
|
130
|
-
path.replacingOccurrences(of: "^/+", with: "", options: .regularExpression)
|
|
131
|
-
}
|
|
132
|
-
}
|
package/ios/Utils/Promise.swift
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Promise.swift
|
|
3
|
-
// CloudStorage
|
|
4
|
-
//
|
|
5
|
-
// Created by Maximilian Krause on 27.09.24.
|
|
6
|
-
// Copyright © 2024 Kuatsu App Agency. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
import Foundation
|
|
10
|
-
|
|
11
|
-
// MARK: - Promise
|
|
12
|
-
|
|
13
|
-
class Promise {
|
|
14
|
-
private let resolver: RCTPromiseResolveBlock
|
|
15
|
-
private let rejecter: RCTPromiseRejectBlock
|
|
16
|
-
|
|
17
|
-
init(resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
|
|
18
|
-
self.resolver = resolver
|
|
19
|
-
self.rejecter = rejecter
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
func reject(error: CloudStorageError, cause: NSError? = nil) {
|
|
23
|
-
rejecter(error.code, error.message, cause)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
func resolve(_ value: Any? = nil) {
|
|
27
|
-
resolver(value)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Wrap a code block with automatic promise resolution and rejection handling, simplifying error handling.
|
|
33
|
-
*
|
|
34
|
-
* The `block` should return a value that can be serialized by the React Native bridge (or `nil`).
|
|
35
|
-
* Any error thrown within the `block` should be of type `CloudStorageError`, otherwise it will be treated as
|
|
36
|
-
* `CloudStorageError.unknown`.
|
|
37
|
-
*/
|
|
38
|
-
func withPromise(_ promise: Promise, _ block: () throws -> Any?) {
|
|
39
|
-
do {
|
|
40
|
-
let result = try block()
|
|
41
|
-
promise.resolve(result)
|
|
42
|
-
} catch let error as CloudStorageError {
|
|
43
|
-
promise.reject(error: error)
|
|
44
|
-
} catch let error as NSError {
|
|
45
|
-
promise.reject(error: CloudStorageError.unknown(message: error.description), cause: error)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Wrap a code block with automatic promise resolution and rejection handling, simplifying error handling.
|
|
51
|
-
*
|
|
52
|
-
* The `block` should return a value that can be serialized by the React Native bridge (or `nil`).
|
|
53
|
-
* Any error thrown within the `block` should be of type `CloudStorageError`, otherwise it will be treated as
|
|
54
|
-
* `CloudStorageError.unknown`.
|
|
55
|
-
*/
|
|
56
|
-
func withPromise(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock, _ block: () throws -> Any?) {
|
|
57
|
-
withPromise(Promise(resolver: resolve, rejecter: reject), block)
|
|
58
|
-
}
|
package/ios/Utils/Types.swift
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Types.swift
|
|
3
|
-
// CloudStorage
|
|
4
|
-
//
|
|
5
|
-
// Created by Maximilian Krause on 27.09.24.
|
|
6
|
-
// Copyright © 2024 Kuatsu App Agency. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
import Foundation
|
|
10
|
-
|
|
11
|
-
// MARK: - DirectoryScope
|
|
12
|
-
|
|
13
|
-
@frozen
|
|
14
|
-
enum DirectoryScope: String {
|
|
15
|
-
case appData = "app_data"
|
|
16
|
-
case documents
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// MARK: - FileStat
|
|
20
|
-
|
|
21
|
-
struct FileStat: Encodable {
|
|
22
|
-
let size: UInt64
|
|
23
|
-
let birthtimeMs: Double
|
|
24
|
-
let mtimeMs: Double
|
|
25
|
-
let isDirectory: Bool
|
|
26
|
-
let isFile: Bool
|
|
27
|
-
|
|
28
|
-
func toDictionary() -> [String: Any] {
|
|
29
|
-
guard let data = try? JSONEncoder().encode(self),
|
|
30
|
-
let dictionary = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any]
|
|
31
|
-
else {
|
|
32
|
-
return [:]
|
|
33
|
-
}
|
|
34
|
-
return dictionary
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|
package/lib/module/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|