react-native-cloud-storage 2.2.1 → 2.3.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/LICENSE +1 -1
- package/android/build.gradle +101 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/voicekit/CloudStorageError.kt +86 -0
- package/android/src/main/java/com/voicekit/CloudStorageLocalFileSystemModule.kt +236 -0
- package/android/src/main/java/com/voicekit/CloudStoragePackage.kt +17 -0
- package/android/src/main/java/com/voicekit/FileUtils.kt +41 -0
- package/android/src/main/java/com/voicekit/Types.kt +6 -0
- package/app.plugin.js +1 -1
- package/{lib/commonjs/RNCloudStorage.js → dist/commonjs/cloud-storage.js} +130 -80
- package/dist/commonjs/cloud-storage.js.map +1 -0
- package/dist/commonjs/expo-plugin/index.js +13 -0
- package/dist/commonjs/expo-plugin/index.js.map +1 -0
- package/{lib/commonjs/expo-plugin/withRNCloudStorageIos.js → dist/commonjs/expo-plugin/ios.js} +1 -1
- package/dist/commonjs/expo-plugin/ios.js.map +1 -0
- package/{lib/commonjs/hooks/useCloudFile.js → dist/commonjs/hooks/use-cloud-file.js} +26 -8
- package/dist/commonjs/hooks/use-cloud-file.js.map +1 -0
- package/{lib/commonjs/hooks/useIsCloudAvailable.js → dist/commonjs/hooks/use-is-cloud-available.js} +3 -3
- package/dist/commonjs/hooks/use-is-cloud-available.js.map +1 -0
- package/{lib → dist}/commonjs/index.js +10 -10
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/storages/cloudkit.js +10 -0
- package/dist/commonjs/storages/cloudkit.js.map +1 -0
- package/{lib/commonjs → dist/commonjs/storages}/google-drive/client.js +82 -39
- package/dist/commonjs/storages/google-drive/client.js.map +1 -0
- package/{lib/commonjs → dist/commonjs/storages}/google-drive/index.js +120 -64
- package/dist/commonjs/storages/google-drive/index.js.map +1 -0
- package/dist/commonjs/storages/google-drive/types.js.map +1 -0
- package/dist/commonjs/types/native.js +28 -0
- package/dist/commonjs/types/native.js.map +1 -0
- package/{lib/commonjs/utils/CloudStorageError.js → dist/commonjs/utils/cloud-storage-error.js} +3 -1
- package/dist/commonjs/utils/cloud-storage-error.js.map +1 -0
- package/dist/commonjs/utils/constants.js +24 -0
- package/dist/commonjs/utils/constants.js.map +1 -0
- package/dist/commonjs/utils/local-fs.js +16 -0
- package/dist/commonjs/utils/local-fs.js.map +1 -0
- package/dist/commonjs/utils/native.js +35 -0
- package/dist/commonjs/utils/native.js.map +1 -0
- package/{lib/module/RNCloudStorage.js → dist/module/cloud-storage.js} +130 -80
- package/dist/module/cloud-storage.js.map +1 -0
- package/dist/module/expo-plugin/index.js +8 -0
- package/dist/module/expo-plugin/index.js.map +1 -0
- package/{lib/module/expo-plugin/withRNCloudStorageIos.js → dist/module/expo-plugin/ios.js} +1 -1
- package/dist/module/expo-plugin/ios.js.map +1 -0
- package/{lib/module/hooks/useCloudFile.js → dist/module/hooks/use-cloud-file.js} +25 -7
- package/dist/module/hooks/use-cloud-file.js.map +1 -0
- package/{lib/module/hooks/useIsCloudAvailable.js → dist/module/hooks/use-is-cloud-available.js} +2 -2
- package/dist/module/hooks/use-is-cloud-available.js.map +1 -0
- package/dist/module/index.js +9 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/storages/cloudkit.js +6 -0
- package/dist/module/storages/cloudkit.js.map +1 -0
- package/{lib/module → dist/module/storages}/google-drive/client.js +82 -39
- package/dist/module/storages/google-drive/client.js.map +1 -0
- package/{lib/module → dist/module/storages}/google-drive/index.js +119 -62
- package/dist/module/storages/google-drive/index.js.map +1 -0
- package/dist/module/storages/google-drive/types.js.map +1 -0
- package/dist/module/types/native.js +24 -0
- package/dist/module/types/native.js.map +1 -0
- package/{lib/module/utils/CloudStorageError.js → dist/module/utils/cloud-storage-error.js} +3 -1
- package/dist/module/utils/cloud-storage-error.js.map +1 -0
- package/dist/module/utils/constants.js +20 -0
- package/dist/module/utils/constants.js.map +1 -0
- package/dist/module/utils/local-fs.js +12 -0
- package/dist/module/utils/local-fs.js.map +1 -0
- package/dist/module/utils/native.js +30 -0
- package/dist/module/utils/native.js.map +1 -0
- package/{lib/typescript/RNCloudStorage.d.ts → dist/typescript/cloud-storage.d.ts} +60 -8
- package/dist/typescript/cloud-storage.d.ts.map +1 -0
- package/{lib/typescript/expo-plugin/withRNCloudStorage.d.ts → dist/typescript/expo-plugin/index.d.ts} +1 -1
- package/dist/typescript/expo-plugin/index.d.ts.map +1 -0
- package/{lib/typescript/expo-plugin/withRNCloudStorageIos.d.ts → dist/typescript/expo-plugin/ios.d.ts} +1 -1
- package/dist/typescript/expo-plugin/ios.d.ts.map +1 -0
- package/{lib/typescript/hooks/useCloudFile.d.ts → dist/typescript/hooks/use-cloud-file.d.ts} +22 -4
- package/dist/typescript/hooks/use-cloud-file.d.ts.map +1 -0
- package/{lib/typescript/hooks/useIsCloudAvailable.d.ts → dist/typescript/hooks/use-is-cloud-available.d.ts} +2 -2
- package/dist/typescript/hooks/use-is-cloud-available.d.ts.map +1 -0
- package/dist/typescript/index.d.ts +7 -0
- package/dist/typescript/index.d.ts.map +1 -0
- package/dist/typescript/storages/cloudkit.d.ts +3 -0
- package/dist/typescript/storages/cloudkit.d.ts.map +1 -0
- package/{lib/typescript → dist/typescript/storages}/google-drive/client.d.ts +9 -2
- package/dist/typescript/storages/google-drive/client.d.ts.map +1 -0
- package/dist/typescript/storages/google-drive/index.d.ts +35 -0
- package/dist/typescript/storages/google-drive/index.d.ts.map +1 -0
- package/dist/typescript/storages/google-drive/types.d.ts.map +1 -0
- package/dist/typescript/types/native.d.ts +64 -0
- package/dist/typescript/types/native.d.ts.map +1 -0
- package/dist/typescript/utils/cloud-storage-error.d.ts +8 -0
- package/dist/typescript/utils/cloud-storage-error.d.ts.map +1 -0
- package/dist/typescript/utils/constants.d.ts +4 -0
- package/dist/typescript/utils/constants.d.ts.map +1 -0
- package/{lib → dist}/typescript/utils/helpers.d.ts.map +1 -1
- package/dist/typescript/utils/local-fs.d.ts +3 -0
- package/dist/typescript/utils/local-fs.d.ts.map +1 -0
- package/dist/typescript/utils/native.d.ts +7 -0
- package/dist/typescript/utils/native.d.ts.map +1 -0
- package/ios/CloudStorage.xcodeproj/project.pbxproj +12 -6
- package/ios/{CloudStorage.m → CloudStorageCloudKit.m} +4 -2
- package/ios/{CloudStorage.swift → CloudStorageCloudKit.swift} +60 -5
- package/ios/CloudStorageLocalFileSystem.m +15 -0
- package/ios/CloudStorageLocalFileSystem.swift +215 -0
- package/ios/Utils/CloudKitUtils.swift +4 -4
- package/ios/Utils/CloudStorageError.swift +8 -0
- package/ios/Utils/FileUtils.swift +19 -0
- package/ios/Utils/Types.swift +7 -1
- package/package.json +44 -103
- package/src/{RNCloudStorage.ts → cloud-storage.ts} +147 -85
- package/src/expo-plugin/{withRNCloudStorage.ts → index.ts} +2 -2
- package/src/hooks/{useCloudFile.ts → use-cloud-file.ts} +24 -6
- package/src/hooks/{useIsCloudAvailable.ts → use-is-cloud-available.ts} +1 -1
- package/src/index.ts +5 -6
- package/src/storages/cloudkit.ts +5 -0
- package/src/{google-drive → storages/google-drive}/client.ts +99 -40
- package/src/{google-drive → storages/google-drive}/index.ts +172 -89
- package/src/types/native.ts +50 -14
- package/src/utils/cloud-storage-error.ts +15 -0
- package/src/utils/constants.ts +20 -0
- package/src/utils/local-fs.ts +19 -0
- package/src/utils/native.ts +40 -0
- package/lib/commonjs/RNCloudStorage.js.map +0 -1
- package/lib/commonjs/expo-plugin/withRNCloudStorage.js +0 -13
- package/lib/commonjs/expo-plugin/withRNCloudStorage.js.map +0 -1
- package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js.map +0 -1
- package/lib/commonjs/google-drive/client.js.map +0 -1
- package/lib/commonjs/google-drive/index.js.map +0 -1
- package/lib/commonjs/google-drive/types.js.map +0 -1
- package/lib/commonjs/hooks/useCloudFile.js.map +0 -1
- package/lib/commonjs/hooks/useIsCloudAvailable.js.map +0 -1
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/types/native.js +0 -26
- package/lib/commonjs/types/native.js.map +0 -1
- package/lib/commonjs/utils/CloudStorageError.js.map +0 -1
- package/lib/module/RNCloudStorage.js.map +0 -1
- package/lib/module/expo-plugin/withRNCloudStorage.js +0 -8
- package/lib/module/expo-plugin/withRNCloudStorage.js.map +0 -1
- package/lib/module/expo-plugin/withRNCloudStorageIos.js.map +0 -1
- package/lib/module/google-drive/client.js.map +0 -1
- package/lib/module/google-drive/index.js.map +0 -1
- package/lib/module/google-drive/types.js.map +0 -1
- package/lib/module/hooks/useCloudFile.js.map +0 -1
- package/lib/module/hooks/useIsCloudAvailable.js.map +0 -1
- package/lib/module/index.js +0 -10
- package/lib/module/index.js.map +0 -1
- package/lib/module/types/native.js +0 -22
- package/lib/module/types/native.js.map +0 -1
- package/lib/module/utils/CloudStorageError.js.map +0 -1
- package/lib/typescript/RNCloudStorage.d.ts.map +0 -1
- package/lib/typescript/expo-plugin/withRNCloudStorage.d.ts.map +0 -1
- package/lib/typescript/expo-plugin/withRNCloudStorageIos.d.ts.map +0 -1
- package/lib/typescript/google-drive/client.d.ts.map +0 -1
- package/lib/typescript/google-drive/index.d.ts +0 -34
- package/lib/typescript/google-drive/index.d.ts.map +0 -1
- package/lib/typescript/google-drive/types.d.ts.map +0 -1
- package/lib/typescript/hooks/useCloudFile.d.ts.map +0 -1
- package/lib/typescript/hooks/useIsCloudAvailable.d.ts.map +0 -1
- package/lib/typescript/index.d.ts +0 -8
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/types/native.d.ts +0 -40
- package/lib/typescript/types/native.d.ts.map +0 -1
- package/lib/typescript/utils/CloudStorageError.d.ts +0 -8
- package/lib/typescript/utils/CloudStorageError.d.ts.map +0 -1
- package/src/utils/CloudStorageError.ts +0 -14
- /package/{lib → dist}/commonjs/expo-plugin/types/index.js +0 -0
- /package/{lib → dist}/commonjs/expo-plugin/types/index.js.map +0 -0
- /package/{lib/commonjs → dist/commonjs/storages}/google-drive/types.js +0 -0
- /package/{lib → dist}/commonjs/types/main.js +0 -0
- /package/{lib → dist}/commonjs/types/main.js.map +0 -0
- /package/{lib → dist}/commonjs/utils/helpers.js +0 -0
- /package/{lib → dist}/commonjs/utils/helpers.js.map +0 -0
- /package/{lib → dist}/module/expo-plugin/types/index.js +0 -0
- /package/{lib → dist}/module/expo-plugin/types/index.js.map +0 -0
- /package/{lib → dist}/module/package.json +0 -0
- /package/{lib/module → dist/module/storages}/google-drive/types.js +0 -0
- /package/{lib → dist}/module/types/main.js +0 -0
- /package/{lib → dist}/module/types/main.js.map +0 -0
- /package/{lib → dist}/module/utils/helpers.js +0 -0
- /package/{lib → dist}/module/utils/helpers.js.map +0 -0
- /package/{lib → dist}/typescript/expo-plugin/types/index.d.ts +0 -0
- /package/{lib → dist}/typescript/expo-plugin/types/index.d.ts.map +0 -0
- /package/{lib/typescript → dist/typescript/storages}/google-drive/types.d.ts +0 -0
- /package/{lib → dist}/typescript/types/main.d.ts +0 -0
- /package/{lib → dist}/typescript/types/main.d.ts.map +0 -0
- /package/{lib → dist}/typescript/utils/helpers.d.ts +0 -0
- /package/src/expo-plugin/{withRNCloudStorageIos.ts → ios.ts} +0 -0
- /package/src/{google-drive → storages/google-drive}/types.ts +0 -0
|
@@ -5,60 +5,19 @@ import {
|
|
|
5
5
|
type CloudStorageProviderOptions,
|
|
6
6
|
type DeepRequired,
|
|
7
7
|
} from './types/main';
|
|
8
|
-
import type
|
|
8
|
+
import { NativeCloudStorageErrorCode, type NativeStorage } from './types/native';
|
|
9
9
|
import { isProviderSupported } from './utils/helpers';
|
|
10
10
|
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
const LINKING_ERROR =
|
|
16
|
-
`The package 'react-native-cloud-storage' doesn't seem to be linked. Make sure: \n\n` +
|
|
17
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
18
|
-
'- You rebuilt the app after installing the package\n' +
|
|
19
|
-
'- You are not using Expo Go\n';
|
|
20
|
-
|
|
21
|
-
// proxy NativeModules.CloudStorage to catch any errors thrown by the native module and wrap them in a CloudStorageError
|
|
22
|
-
const nativeIosInstance = NativeModules.CloudStorage
|
|
23
|
-
? new Proxy(NativeModules.CloudStorage, {
|
|
24
|
-
get(target: NativeRNCloudStorage, prop: keyof NativeRNCloudStorage) {
|
|
25
|
-
const originalFunction = target[prop];
|
|
26
|
-
if (typeof originalFunction === 'function') {
|
|
27
|
-
return async (...args: any[]) => {
|
|
28
|
-
try {
|
|
29
|
-
// @ts-expect-error - we can't know the types of the functions and their arguments
|
|
30
|
-
return await originalFunction(...args);
|
|
31
|
-
} catch (error: any) {
|
|
32
|
-
if (error?.code && Object.values(CloudStorageErrorCode).includes(error.code)) {
|
|
33
|
-
throw new CloudStorageError(error?.message || '', error.code as CloudStorageErrorCode);
|
|
34
|
-
} else {
|
|
35
|
-
throw new CloudStorageError('Unknown error', CloudStorageErrorCode.UNKNOWN, error);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
return originalFunction;
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
: null;
|
|
44
|
-
|
|
45
|
-
const defaultProviderOptions: DeepRequired<CloudStorageProviderOptions> = {
|
|
46
|
-
[CloudStorageProvider.ICloud]: {
|
|
47
|
-
scope: CloudStorageScope.AppData,
|
|
48
|
-
},
|
|
49
|
-
[CloudStorageProvider.GoogleDrive]: {
|
|
50
|
-
scope: CloudStorageScope.AppData,
|
|
51
|
-
accessToken: null,
|
|
52
|
-
strictFilenames: false,
|
|
53
|
-
timeout: 3000,
|
|
54
|
-
},
|
|
55
|
-
};
|
|
11
|
+
import GoogleDrive from './storages/google-drive';
|
|
12
|
+
import { NativeCloudKit } from './storages/cloudkit';
|
|
13
|
+
import { DEFAULT_PROVIDER_OPTIONS, LINKING_ERROR } from './utils/constants';
|
|
14
|
+
import CloudStorageError from './utils/cloud-storage-error';
|
|
56
15
|
|
|
57
16
|
export default class RNCloudStorage {
|
|
58
17
|
private static defaultInstance: RNCloudStorage;
|
|
59
18
|
private provider: {
|
|
60
19
|
provider: CloudStorageProvider;
|
|
61
|
-
options: (typeof
|
|
20
|
+
options: (typeof DEFAULT_PROVIDER_OPTIONS)[keyof typeof DEFAULT_PROVIDER_OPTIONS];
|
|
62
21
|
};
|
|
63
22
|
private cloudAvailabilityListeners: ((available: boolean) => void)[] = [];
|
|
64
23
|
|
|
@@ -77,7 +36,7 @@ export default class RNCloudStorage {
|
|
|
77
36
|
|
|
78
37
|
this.provider = {
|
|
79
38
|
provider: provider ?? RNCloudStorage.getDefaultProvider(),
|
|
80
|
-
options:
|
|
39
|
+
options: DEFAULT_PROVIDER_OPTIONS[provider ?? RNCloudStorage.getDefaultProvider()],
|
|
81
40
|
};
|
|
82
41
|
|
|
83
42
|
this.setProvider(provider ?? RNCloudStorage.getDefaultProvider());
|
|
@@ -86,22 +45,24 @@ export default class RNCloudStorage {
|
|
|
86
45
|
}
|
|
87
46
|
}
|
|
88
47
|
|
|
89
|
-
private get
|
|
48
|
+
private get nativeStorage(): NativeStorage {
|
|
90
49
|
switch (this.provider.provider) {
|
|
91
|
-
case CloudStorageProvider.ICloud:
|
|
50
|
+
case CloudStorageProvider.ICloud: {
|
|
92
51
|
return (
|
|
93
|
-
|
|
94
|
-
new Proxy(
|
|
52
|
+
NativeCloudKit ??
|
|
53
|
+
(new Proxy(
|
|
95
54
|
{},
|
|
96
55
|
{
|
|
97
56
|
get() {
|
|
98
57
|
throw new Error(LINKING_ERROR);
|
|
99
58
|
},
|
|
100
59
|
}
|
|
101
|
-
)
|
|
60
|
+
) as NativeStorage)
|
|
102
61
|
);
|
|
103
|
-
|
|
62
|
+
}
|
|
63
|
+
default: {
|
|
104
64
|
return new GoogleDrive(this.provider.options as DeepRequired<CloudStorageProviderOptions['googledrive']>);
|
|
65
|
+
}
|
|
105
66
|
}
|
|
106
67
|
}
|
|
107
68
|
|
|
@@ -111,10 +72,12 @@ export default class RNCloudStorage {
|
|
|
111
72
|
*/
|
|
112
73
|
static getDefaultProvider(): CloudStorageProvider {
|
|
113
74
|
switch (Platform.OS) {
|
|
114
|
-
case 'ios':
|
|
75
|
+
case 'ios': {
|
|
115
76
|
return CloudStorageProvider.ICloud;
|
|
116
|
-
|
|
77
|
+
}
|
|
78
|
+
default: {
|
|
117
79
|
return CloudStorageProvider.GoogleDrive;
|
|
80
|
+
}
|
|
118
81
|
}
|
|
119
82
|
}
|
|
120
83
|
|
|
@@ -123,7 +86,7 @@ export default class RNCloudStorage {
|
|
|
123
86
|
* @returns An array of supported CloudStorageProviders.
|
|
124
87
|
*/
|
|
125
88
|
static getSupportedProviders(): CloudStorageProvider[] {
|
|
126
|
-
return Object.values(CloudStorageProvider).filter(isProviderSupported);
|
|
89
|
+
return Object.values(CloudStorageProvider).filter((provider) => isProviderSupported(provider));
|
|
127
90
|
}
|
|
128
91
|
|
|
129
92
|
/**
|
|
@@ -145,23 +108,23 @@ export default class RNCloudStorage {
|
|
|
145
108
|
|
|
146
109
|
this.provider = {
|
|
147
110
|
provider,
|
|
148
|
-
options:
|
|
111
|
+
options: DEFAULT_PROVIDER_OPTIONS[provider],
|
|
149
112
|
};
|
|
150
113
|
|
|
151
114
|
// Emit an event to notify useIsCloudAvailable() hook consumers of the new cloud availability status
|
|
152
|
-
this.
|
|
153
|
-
this.cloudAvailabilityListeners
|
|
115
|
+
this.nativeStorage.isCloudAvailable().then((available) => {
|
|
116
|
+
for (const listener of this.cloudAvailabilityListeners) {
|
|
154
117
|
listener(available);
|
|
155
|
-
}
|
|
118
|
+
}
|
|
156
119
|
});
|
|
157
120
|
|
|
158
121
|
if (provider === CloudStorageProvider.ICloud) {
|
|
159
122
|
// Listen to native cloud availability change events
|
|
160
123
|
const eventEmitter = new NativeEventEmitter(NativeModules.CloudStorageEventEmitter);
|
|
161
124
|
eventEmitter.addListener('RNCloudStorage.cloud.availability-changed', (event: { available: boolean }) => {
|
|
162
|
-
this.cloudAvailabilityListeners
|
|
125
|
+
for (const listener of this.cloudAvailabilityListeners) {
|
|
163
126
|
listener(event.available);
|
|
164
|
-
}
|
|
127
|
+
}
|
|
165
128
|
});
|
|
166
129
|
}
|
|
167
130
|
}
|
|
@@ -187,11 +150,11 @@ export default class RNCloudStorage {
|
|
|
187
150
|
|
|
188
151
|
if (this.provider.provider === CloudStorageProvider.GoogleDrive && 'accessToken' in newOptions) {
|
|
189
152
|
// Emit an event to notify useIsCloudAvailable() hook consumers of the new cloud availability status
|
|
190
|
-
this.cloudAvailabilityListeners
|
|
153
|
+
for (const listener of this.cloudAvailabilityListeners) {
|
|
191
154
|
listener(
|
|
192
155
|
!!(newOptions as Required<CloudStorageProviderOptions[CloudStorageProvider.GoogleDrive]>).accessToken?.length
|
|
193
156
|
);
|
|
194
|
-
}
|
|
157
|
+
}
|
|
195
158
|
}
|
|
196
159
|
}
|
|
197
160
|
|
|
@@ -211,7 +174,7 @@ export default class RNCloudStorage {
|
|
|
211
174
|
* @returns A promise that resolves to true if the cloud storage is available, false otherwise.
|
|
212
175
|
*/
|
|
213
176
|
isCloudAvailable(): Promise<boolean> {
|
|
214
|
-
return this.
|
|
177
|
+
return this.nativeStorage.isCloudAvailable();
|
|
215
178
|
}
|
|
216
179
|
|
|
217
180
|
/**
|
|
@@ -222,7 +185,7 @@ export default class RNCloudStorage {
|
|
|
222
185
|
* @returns A promise that resolves when the data has been appended.
|
|
223
186
|
*/
|
|
224
187
|
appendFile(path: string, data: string, scope?: CloudStorageScope): Promise<void> {
|
|
225
|
-
return this.
|
|
188
|
+
return this.nativeStorage.appendToFile(path, data, scope ?? this.provider.options.scope);
|
|
226
189
|
}
|
|
227
190
|
|
|
228
191
|
/**
|
|
@@ -232,7 +195,7 @@ export default class RNCloudStorage {
|
|
|
232
195
|
* @returns A promise that resolves to true if the path exists, false otherwise.
|
|
233
196
|
*/
|
|
234
197
|
exists(path: string, scope?: CloudStorageScope): Promise<boolean> {
|
|
235
|
-
return this.
|
|
198
|
+
return this.nativeStorage.fileExists(path, scope ?? this.provider.options.scope);
|
|
236
199
|
}
|
|
237
200
|
|
|
238
201
|
/**
|
|
@@ -243,7 +206,7 @@ export default class RNCloudStorage {
|
|
|
243
206
|
* @returns A promise that resolves when the file has been written.
|
|
244
207
|
*/
|
|
245
208
|
writeFile(path: string, data: string, scope?: CloudStorageScope): Promise<void> {
|
|
246
|
-
return this.
|
|
209
|
+
return this.nativeStorage.createFile(path, data, scope ?? this.provider.options.scope, true);
|
|
247
210
|
}
|
|
248
211
|
|
|
249
212
|
/**
|
|
@@ -253,7 +216,7 @@ export default class RNCloudStorage {
|
|
|
253
216
|
* @returns A promise that resolves when the directory has been created.
|
|
254
217
|
*/
|
|
255
218
|
mkdir(path: string, scope?: CloudStorageScope): Promise<void> {
|
|
256
|
-
return this.
|
|
219
|
+
return this.nativeStorage.createDirectory(path, scope ?? this.provider.options.scope);
|
|
257
220
|
}
|
|
258
221
|
|
|
259
222
|
/**
|
|
@@ -263,7 +226,7 @@ export default class RNCloudStorage {
|
|
|
263
226
|
* @returns A promise that resolves to an array of file names, excluding '.' and '..'.
|
|
264
227
|
*/
|
|
265
228
|
readdir(path: string, scope?: CloudStorageScope): Promise<string[]> {
|
|
266
|
-
return this.
|
|
229
|
+
return this.nativeStorage.listFiles(path, scope ?? this.provider.options.scope);
|
|
267
230
|
}
|
|
268
231
|
|
|
269
232
|
/**
|
|
@@ -273,17 +236,72 @@ export default class RNCloudStorage {
|
|
|
273
236
|
* @returns A promise that resolves to the contents of the file.
|
|
274
237
|
*/
|
|
275
238
|
readFile(path: string, scope?: CloudStorageScope): Promise<string> {
|
|
276
|
-
return this.
|
|
239
|
+
return this.nativeStorage.readFile(path, scope ?? this.provider.options.scope);
|
|
277
240
|
}
|
|
278
241
|
|
|
279
242
|
/**
|
|
280
|
-
*
|
|
281
|
-
* @param path The file to trigger
|
|
243
|
+
* Triggers synchronization for the file at the given path. Does not have any effect on Google Drive.
|
|
244
|
+
* @param path The file to trigger synchronization for.
|
|
282
245
|
* @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
|
|
283
|
-
* @returns A promise that resolves once the
|
|
246
|
+
* @returns A promise that resolves once the synchronization has been triggered.
|
|
284
247
|
*/
|
|
285
|
-
|
|
286
|
-
return this.
|
|
248
|
+
triggerSync(path: string, scope?: CloudStorageScope): Promise<void> {
|
|
249
|
+
return this.nativeStorage.triggerSync(path, scope ?? this.provider.options.scope);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Uploads the file at the given local path to the given path, creating it if it doesn't exist or overwriting it if it does.
|
|
254
|
+
* @param remotePath The remote path to upload to.
|
|
255
|
+
* @param localPath The local path of the file to upload.
|
|
256
|
+
* @param options The options for the upload. Must contain a `mimeType` property.
|
|
257
|
+
* @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
|
|
258
|
+
* @returns A promise that resolves when the file has been uploaded.
|
|
259
|
+
*/
|
|
260
|
+
uploadFile(
|
|
261
|
+
remotePath: string,
|
|
262
|
+
localPath: string,
|
|
263
|
+
options: { mimeType: string },
|
|
264
|
+
scope?: CloudStorageScope
|
|
265
|
+
): Promise<void> {
|
|
266
|
+
return this.nativeStorage.uploadFile(
|
|
267
|
+
remotePath,
|
|
268
|
+
localPath,
|
|
269
|
+
options.mimeType,
|
|
270
|
+
scope ?? this.provider.options.scope,
|
|
271
|
+
true
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Triggers synchronization for the file at the given path. Does not have any effect on Google Drive.
|
|
277
|
+
* @param path The file to trigger synchronization for.
|
|
278
|
+
* @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
|
|
279
|
+
* @returns A promise that resolves once the synchronization has been triggered.
|
|
280
|
+
* @deprecated Use `triggerSync` instead.
|
|
281
|
+
*/
|
|
282
|
+
downloadFile(path: string, scope?: CloudStorageScope): Promise<void>;
|
|
283
|
+
/**
|
|
284
|
+
* Downloads the cloud file at the given remote path to the given local path.
|
|
285
|
+
* @param remotePath The remote path of the file to download from the cloud.
|
|
286
|
+
* @param localPath The local path to download the cloud file to.
|
|
287
|
+
* @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
|
|
288
|
+
*/
|
|
289
|
+
downloadFile(remotePath: string, localPath: string, scope?: CloudStorageScope): Promise<void>;
|
|
290
|
+
downloadFile(remotePathOrPath: string, localPathOrScope?: string, scope?: CloudStorageScope): Promise<void> {
|
|
291
|
+
if (
|
|
292
|
+
!localPathOrScope ||
|
|
293
|
+
(!scope &&
|
|
294
|
+
typeof localPathOrScope === 'string' &&
|
|
295
|
+
Object.values(CloudStorageScope).includes(localPathOrScope as CloudStorageScope))
|
|
296
|
+
) {
|
|
297
|
+
// deprecated `triggerSync` call
|
|
298
|
+
return this.triggerSync(remotePathOrPath, scope);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (!localPathOrScope) {
|
|
302
|
+
throw new CloudStorageError('Invalid arguments provided to downloadFile', NativeCloudStorageErrorCode.UNKNOWN);
|
|
303
|
+
}
|
|
304
|
+
return this.nativeStorage.downloadFile(remotePathOrPath, localPathOrScope, scope ?? this.provider.options.scope);
|
|
287
305
|
}
|
|
288
306
|
|
|
289
307
|
/**
|
|
@@ -293,7 +311,7 @@ export default class RNCloudStorage {
|
|
|
293
311
|
* @returns A promise that resolves when the file has been deleted.
|
|
294
312
|
*/
|
|
295
313
|
unlink(path: string, scope?: CloudStorageScope): Promise<void> {
|
|
296
|
-
return this.
|
|
314
|
+
return this.nativeStorage.deleteFile(path, scope ?? this.provider.options.scope);
|
|
297
315
|
}
|
|
298
316
|
|
|
299
317
|
/**
|
|
@@ -304,7 +322,7 @@ export default class RNCloudStorage {
|
|
|
304
322
|
* @returns A promise that resolves when the directory has been deleted.
|
|
305
323
|
*/
|
|
306
324
|
rmdir(path: string, options?: { recursive?: boolean }, scope?: CloudStorageScope): Promise<void> {
|
|
307
|
-
return this.
|
|
325
|
+
return this.nativeStorage.deleteDirectory(path, options?.recursive ?? false, scope ?? this.provider.options.scope);
|
|
308
326
|
}
|
|
309
327
|
|
|
310
328
|
/**
|
|
@@ -314,7 +332,7 @@ export default class RNCloudStorage {
|
|
|
314
332
|
* @returns A promise that resolves to the CloudStorageFileStat object.
|
|
315
333
|
*/
|
|
316
334
|
async stat(path: string, scope?: CloudStorageScope): Promise<CloudStorageFileStat> {
|
|
317
|
-
const native = await this.
|
|
335
|
+
const native = await this.nativeStorage.statFile(path, scope ?? this.provider.options.scope);
|
|
318
336
|
|
|
319
337
|
return {
|
|
320
338
|
...native,
|
|
@@ -438,13 +456,57 @@ export default class RNCloudStorage {
|
|
|
438
456
|
}
|
|
439
457
|
|
|
440
458
|
/**
|
|
441
|
-
*
|
|
442
|
-
* @param path The file to trigger
|
|
459
|
+
* Triggers synchronization for the file at the given path in the provider of the default static instance. Does not have any effect on Google Drive.
|
|
460
|
+
* @param path The file to trigger synchronization for.
|
|
443
461
|
* @param scope The directory scope the path is in. Defaults to the default scope set for the default static instance.
|
|
444
|
-
* @returns A promise that resolves once the
|
|
462
|
+
* @returns A promise that resolves once the synchronization has been triggered.
|
|
463
|
+
*/
|
|
464
|
+
static triggerSync(path: string, scope?: CloudStorageScope): Promise<void> {
|
|
465
|
+
return RNCloudStorage.getDefaultInstance().triggerSync(path, scope);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Uploads the file at the given local path to the given path in the provider of the default static instance, creating it if it doesn't exist or overwriting it if it does.
|
|
470
|
+
* @param remotePath The remote path to upload to.
|
|
471
|
+
* @param localPath The local path of the file to upload.
|
|
472
|
+
* @param options The options for the upload. Must contain a `mimeType` property.
|
|
473
|
+
* @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
|
|
474
|
+
* @returns A promise that resolves when the file has been uploaded.
|
|
445
475
|
*/
|
|
446
|
-
static
|
|
447
|
-
|
|
476
|
+
static uploadFile(
|
|
477
|
+
remotePath: string,
|
|
478
|
+
localPath: string,
|
|
479
|
+
options: { mimeType: string },
|
|
480
|
+
scope?: CloudStorageScope
|
|
481
|
+
): Promise<void> {
|
|
482
|
+
return RNCloudStorage.getDefaultInstance().uploadFile(remotePath, localPath, options, scope);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Triggers synchronization for the file at the given path in the provider of the default static instance. Does not have any effect on Google Drive.
|
|
487
|
+
* @param path The file to trigger synchronization for.
|
|
488
|
+
* @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
|
|
489
|
+
* @returns A promise that resolves once the synchronization has been triggered.
|
|
490
|
+
* @deprecated Use `triggerSync` instead.
|
|
491
|
+
*/
|
|
492
|
+
static downloadFile(path: string, scope?: CloudStorageScope): Promise<void>;
|
|
493
|
+
/**
|
|
494
|
+
* Downloads the cloud file at the given remote path to the given local path.
|
|
495
|
+
* @param remotePath The remote path of the file to download from the cloud.
|
|
496
|
+
* @param localPath The local path to download the cloud file to.
|
|
497
|
+
* @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
|
|
498
|
+
*/
|
|
499
|
+
static downloadFile(remotePath: string, localPath: string, scope?: CloudStorageScope): Promise<void>;
|
|
500
|
+
static downloadFile(remotePathOrPath: string, localPathOrScope?: string, scope?: CloudStorageScope): Promise<void> {
|
|
501
|
+
if (typeof scope === 'string') {
|
|
502
|
+
if (!localPathOrScope) {
|
|
503
|
+
throw new CloudStorageError('Invalid arguments provided to downloadFile', NativeCloudStorageErrorCode.UNKNOWN);
|
|
504
|
+
}
|
|
505
|
+
return RNCloudStorage.getDefaultInstance().downloadFile(remotePathOrPath, localPathOrScope, scope);
|
|
506
|
+
} else {
|
|
507
|
+
// deprecated `triggerSync` call
|
|
508
|
+
return RNCloudStorage.getDefaultInstance().triggerSync(remotePathOrPath, scope);
|
|
509
|
+
}
|
|
448
510
|
}
|
|
449
511
|
|
|
450
512
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { RNCloudStorageConfigPluginOptions } from './types';
|
|
2
|
-
import withRNCloudStorageIos from './
|
|
2
|
+
import withRNCloudStorageIos from './ios';
|
|
3
3
|
import type { ConfigPlugin } from '@expo/config-plugins';
|
|
4
4
|
|
|
5
|
-
// Android config plugin not needed as there's
|
|
5
|
+
// Android config plugin not needed as there's nothing to configure.
|
|
6
6
|
|
|
7
7
|
const withRNCloudStorage: ConfigPlugin<RNCloudStorageConfigPluginOptions> = (config, options) =>
|
|
8
8
|
withRNCloudStorageIos(config, options);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CloudStorageScope } from '../types/main';
|
|
2
|
-
import RNCloudStorage from '../
|
|
2
|
+
import RNCloudStorage from '../cloud-storage';
|
|
3
3
|
import { useCallback, useEffect, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -39,19 +39,37 @@ export const useCloudFile = (path: string, scope?: CloudStorageScope, cloudStora
|
|
|
39
39
|
setContent(null);
|
|
40
40
|
}, [path, scope, instance]);
|
|
41
41
|
|
|
42
|
-
const
|
|
43
|
-
await instance.
|
|
42
|
+
const sync = useCallback(async () => {
|
|
43
|
+
await instance.triggerSync(path, scope);
|
|
44
44
|
}, [path, scope, instance]);
|
|
45
45
|
|
|
46
46
|
return {
|
|
47
|
+
/**
|
|
48
|
+
* The content of the file.
|
|
49
|
+
*/
|
|
47
50
|
content,
|
|
51
|
+
/**
|
|
52
|
+
* Reads the file from the cloud.
|
|
53
|
+
*/
|
|
48
54
|
read,
|
|
55
|
+
/**
|
|
56
|
+
* Writes new content to the file.
|
|
57
|
+
*/
|
|
49
58
|
write,
|
|
59
|
+
/**
|
|
60
|
+
* Deletes the file.
|
|
61
|
+
*/
|
|
50
62
|
remove,
|
|
51
63
|
/**
|
|
52
|
-
*
|
|
53
|
-
* Google Drive.
|
|
64
|
+
* Triggers synchronization for the file. Needed if the file hasn't been synced yet from iCloud.
|
|
65
|
+
* Has no effect on Google Drive.
|
|
66
|
+
*/
|
|
67
|
+
sync,
|
|
68
|
+
/**
|
|
69
|
+
* Triggers synchronization for the file. Needed if the file hasn't been synced yet from iCloud.
|
|
70
|
+
* Has no effect on Google Drive.
|
|
71
|
+
* @deprecated Use `sync` instead.
|
|
54
72
|
*/
|
|
55
|
-
download,
|
|
73
|
+
download: sync,
|
|
56
74
|
};
|
|
57
75
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import RNCloudStorage from './RNCloudStorage';
|
|
2
|
-
import { CloudStorageErrorCode } from './types/native';
|
|
3
1
|
export * from './types/main';
|
|
4
|
-
export * from './hooks/
|
|
5
|
-
export * from './hooks/
|
|
6
|
-
import CloudStorageError from './utils/CloudStorageError';
|
|
2
|
+
export * from './hooks/use-cloud-file';
|
|
3
|
+
export * from './hooks/use-is-cloud-available';
|
|
7
4
|
|
|
8
|
-
export {
|
|
5
|
+
export { NativeCloudStorageErrorCode as CloudStorageErrorCode } from './types/native';
|
|
6
|
+
export { default as CloudStorageError } from './utils/cloud-storage-error';
|
|
7
|
+
export { default as CloudStorage } from './cloud-storage';
|