react-native-cloud-storage 2.2.2 → 3.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/LICENSE +1 -1
- package/README.md +1 -1
- package/android/build.gradle +88 -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 +232 -0
- package/android/src/main/java/com/voicekit/CloudStoragePackage.kt +32 -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} +177 -92
- 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/specs/NativeCloudStorageCloudKitIOS.js +9 -0
- package/dist/commonjs/specs/NativeCloudStorageCloudKitIOS.js.map +1 -0
- package/dist/commonjs/specs/NativeCloudStorageLocalFileSystem.js +9 -0
- package/dist/commonjs/specs/NativeCloudStorageLocalFileSystem.js.map +1 -0
- package/dist/commonjs/storages/cloudkit.js +12 -0
- package/dist/commonjs/storages/cloudkit.js.map +1 -0
- package/{lib/commonjs → dist/commonjs/storages}/google-drive/client.js +83 -40
- package/dist/commonjs/storages/google-drive/client.js.map +1 -0
- package/dist/commonjs/storages/google-drive/index.js +399 -0
- package/dist/commonjs/storages/google-drive/index.js.map +1 -0
- package/dist/commonjs/storages/google-drive/types.js.map +1 -0
- package/{lib → dist}/commonjs/types/main.js.map +1 -1
- 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 +25 -0
- package/dist/commonjs/utils/constants.js.map +1 -0
- package/dist/commonjs/utils/local-fs.js +17 -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} +178 -93
- 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/specs/NativeCloudStorageCloudKitIOS.js +5 -0
- package/dist/module/specs/NativeCloudStorageCloudKitIOS.js.map +1 -0
- package/dist/module/specs/NativeCloudStorageLocalFileSystem.js +5 -0
- package/dist/module/specs/NativeCloudStorageLocalFileSystem.js.map +1 -0
- package/dist/module/storages/cloudkit.js +7 -0
- package/dist/module/storages/cloudkit.js.map +1 -0
- package/{lib/module → dist/module/storages}/google-drive/client.js +83 -40
- package/dist/module/storages/google-drive/client.js.map +1 -0
- package/dist/module/storages/google-drive/index.js +392 -0
- package/dist/module/storages/google-drive/index.js.map +1 -0
- package/dist/module/storages/google-drive/types.js.map +1 -0
- package/{lib → dist}/module/types/main.js.map +1 -1
- 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 +21 -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} +67 -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/specs/NativeCloudStorageCloudKitIOS.d.ts +30 -0
- package/dist/typescript/specs/NativeCloudStorageCloudKitIOS.d.ts.map +1 -0
- package/dist/typescript/specs/NativeCloudStorageLocalFileSystem.d.ts +24 -0
- package/dist/typescript/specs/NativeCloudStorageLocalFileSystem.d.ts.map +1 -0
- package/dist/typescript/storages/cloudkit.d.ts +6 -0
- package/dist/typescript/storages/cloudkit.d.ts.map +1 -0
- package/{lib/typescript → dist/typescript/storages}/google-drive/client.d.ts +10 -3
- package/dist/typescript/storages/google-drive/client.d.ts.map +1 -0
- package/dist/typescript/storages/google-drive/index.d.ts +41 -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/{lib → dist}/typescript/types/main.d.ts +8 -0
- package/dist/typescript/types/main.d.ts.map +1 -0
- package/dist/typescript/types/native.d.ts +27 -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 +2 -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-Bridging-Header.h +0 -1
- package/ios/CloudStorage.xcodeproj/project.pbxproj +12 -6
- package/ios/CloudStorageCloudKit.swift +159 -0
- package/ios/CloudStorageLocalFileSystem.swift +216 -0
- package/ios/RCTCloudStorageCloudKit.mm +209 -0
- package/ios/RCTCloudStorageLocalFileSystem.mm +149 -0
- package/ios/Utils/CloudKitUtils.swift +12 -6
- package/ios/Utils/CloudStorageError.swift +8 -0
- package/ios/Utils/FileUtils.swift +21 -4
- package/ios/Utils/Promise.swift +1 -0
- package/ios/Utils/Types.swift +8 -1
- package/ios/react_native_cloud_storage.h +6 -0
- package/package.json +64 -110
- package/react-native-cloud-storage.podspec +2 -0
- package/src/{RNCloudStorage.ts → cloud-storage.ts} +210 -100
- 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/specs/NativeCloudStorageCloudKitIOS.ts +33 -0
- package/src/specs/NativeCloudStorageLocalFileSystem.ts +28 -0
- package/src/storages/cloudkit.ts +13 -0
- package/src/{google-drive → storages/google-drive}/client.ts +100 -41
- package/src/storages/google-drive/index.ts +488 -0
- package/src/types/main.ts +9 -0
- package/src/types/native.ts +14 -22
- package/src/utils/cloud-storage-error.ts +15 -0
- package/src/utils/constants.ts +21 -0
- package/src/utils/local-fs.ts +19 -0
- package/src/utils/native.ts +40 -0
- package/ios/CloudStorage.m +0 -22
- package/ios/CloudStorage.swift +0 -103
- package/ios/CloudStorageEventEmitter.m +0 -16
- package/ios/CloudStorageEventEmitter.swift +0 -30
- 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 +0 -321
- 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 +0 -313
- 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/main.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/google-drive/index.ts +0 -399
- 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/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/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/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
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) Kuatsu App Agency
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
|
6
6
|
in the Software without restriction, including without limitation the rights
|
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
|
|
|
83
83
|
|
|
84
84
|
## Example Project
|
|
85
85
|
|
|
86
|
-
There's an example app available in the `example` directory. To use the Google Drive implementation
|
|
86
|
+
There's an example app available in the `example` directory. To use the Google Drive implementation, you'll need to provide a valid access token for the Google Drive API. For testing purposes, you can create one using the [Google OAuth 2.0 Playground](https://developers.google.com/oauthplayground).
|
|
87
87
|
|
|
88
88
|
## License
|
|
89
89
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
3
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["CloudStorage_kotlinVersion"]
|
|
4
|
+
|
|
5
|
+
repositories {
|
|
6
|
+
google()
|
|
7
|
+
mavenCentral()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
dependencies {
|
|
11
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
12
|
+
// noinspection DifferentKotlinGradleVersion
|
|
13
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
apply plugin: "com.android.library"
|
|
18
|
+
apply plugin: "kotlin-android"
|
|
19
|
+
apply plugin: "com.facebook.react"
|
|
20
|
+
|
|
21
|
+
def getExtOrDefault(name) {
|
|
22
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["CloudStorage_" + name]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
def getExtOrIntegerDefault(name) {
|
|
26
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["CloudStorage_" + name]).toInteger()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def supportsNamespace() {
|
|
30
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
31
|
+
def major = parsed[0].toInteger()
|
|
32
|
+
def minor = parsed[1].toInteger()
|
|
33
|
+
|
|
34
|
+
// Namespace support was added in 7.3.0
|
|
35
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
android {
|
|
39
|
+
if (supportsNamespace()) {
|
|
40
|
+
namespace "com.cloudstorage"
|
|
41
|
+
|
|
42
|
+
sourceSets {
|
|
43
|
+
main {
|
|
44
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
50
|
+
|
|
51
|
+
defaultConfig {
|
|
52
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
53
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
buildTypes {
|
|
58
|
+
release {
|
|
59
|
+
minifyEnabled false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
lintOptions {
|
|
64
|
+
disable "GradleCompatible"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
compileOptions {
|
|
68
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
69
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
repositories {
|
|
74
|
+
mavenCentral()
|
|
75
|
+
google()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
79
|
+
|
|
80
|
+
dependencies {
|
|
81
|
+
// For < 0.71, this will be from the local maven repo
|
|
82
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
83
|
+
//noinspection GradleDynamicVersion
|
|
84
|
+
implementation "com.facebook.react:react-native:+"
|
|
85
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
86
|
+
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.12.0"))
|
|
87
|
+
implementation("com.squareup.okhttp3:okhttp")
|
|
88
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
package com.cloudstorage
|
|
2
|
+
|
|
3
|
+
sealed class CloudStorageError(
|
|
4
|
+
val code: String,
|
|
5
|
+
override val message: String
|
|
6
|
+
) : Exception(message) {
|
|
7
|
+
data class InvalidScope(val scope: String) : CloudStorageError(
|
|
8
|
+
code = "ERR_INVALID_SCOPE",
|
|
9
|
+
message = "Invalid scope $scope provided"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
data class FileNotFound(val path: String) : CloudStorageError(
|
|
13
|
+
code = "ERR_FILE_NOT_FOUND",
|
|
14
|
+
message = "File not found at path $path"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
data class PathIsDirectory(val path: String) : CloudStorageError(
|
|
18
|
+
code = "ERR_PATH_IS_DIRECTORY",
|
|
19
|
+
message = "Path is a directory at path $path"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
data class PathIsFile(val path: String) : CloudStorageError(
|
|
23
|
+
code = "ERR_PATH_IS_FILE",
|
|
24
|
+
message = "Path is a file at path $path"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
data class DirectoryNotFound(val path: String) : CloudStorageError(
|
|
28
|
+
code = "ERR_DIRECTORY_NOT_FOUND",
|
|
29
|
+
message = "Directory not found at path $path"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
data class DirectoryNotEmpty(val path: String) : CloudStorageError(
|
|
33
|
+
code = "ERR_DIRECTORY_NOT_EMPTY",
|
|
34
|
+
message = "Directory not empty at path $path"
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
data class FileAlreadyExists(val path: String) : CloudStorageError(
|
|
38
|
+
code = "ERR_FILE_EXISTS",
|
|
39
|
+
message = "File already exists at path $path"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
object AuthenticationFailed : CloudStorageError(
|
|
43
|
+
code = "ERR_AUTHENTICATION_FAILED",
|
|
44
|
+
message = "Authentication failed"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
data class WriteError(val path: String) : CloudStorageError(
|
|
48
|
+
code = "ERR_WRITE_ERROR",
|
|
49
|
+
message = "Write error for path $path"
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
data class ReadError(val path: String) : CloudStorageError(
|
|
53
|
+
code = "ERR_READ_ERROR",
|
|
54
|
+
message = "Read error for path $path"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
data class DeleteError(val path: String) : CloudStorageError(
|
|
58
|
+
code = "ERR_DELETE_ERROR",
|
|
59
|
+
message = "Delete error for path $path"
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
data class StatError(val path: String) : CloudStorageError(
|
|
63
|
+
code = "ERR_STAT_ERROR",
|
|
64
|
+
message = "Stat error for path $path"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
data class FileNotDownloadable(val path: String) : CloudStorageError(
|
|
68
|
+
code = "ERR_FILE_NOT_DOWNLOADABLE",
|
|
69
|
+
message = "File not downloadable at path $path"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
data class InvalidUrl(val url: String) : CloudStorageError(
|
|
73
|
+
code = "ERR_INVALID_URL",
|
|
74
|
+
message = "Invalid URL provided: $url"
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
data class NetworkError(val errorMessage: String) : CloudStorageError(
|
|
78
|
+
code = "ERR_NETWORK_ERROR",
|
|
79
|
+
message = errorMessage
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
data class Unknown(val errorMessage: String = "An unknown error occurred") : CloudStorageError(
|
|
83
|
+
code = "ERR_UNKNOWN",
|
|
84
|
+
message = errorMessage
|
|
85
|
+
)
|
|
86
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
package com.cloudstorage
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Promise
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.ReadableMap
|
|
6
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
7
|
+
import okhttp3.Call
|
|
8
|
+
import okhttp3.Callback
|
|
9
|
+
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
|
10
|
+
import okhttp3.MultipartBody
|
|
11
|
+
import okhttp3.OkHttpClient
|
|
12
|
+
import okhttp3.Request
|
|
13
|
+
import okhttp3.RequestBody.Companion.asRequestBody
|
|
14
|
+
import okhttp3.Response
|
|
15
|
+
import okio.buffer
|
|
16
|
+
import okio.sink
|
|
17
|
+
import java.io.File
|
|
18
|
+
import java.io.IOException
|
|
19
|
+
import java.net.URLConnection
|
|
20
|
+
|
|
21
|
+
@ReactModule(name = CloudStorageLocalFileSystemModule.NAME)
|
|
22
|
+
class CloudStorageLocalFileSystemModule(reactContext: ReactApplicationContext) :
|
|
23
|
+
NativeCloudStorageLocalFileSystemSpec(reactContext) {
|
|
24
|
+
|
|
25
|
+
override fun getTypedExportedConstants(): Map<String, Any> {
|
|
26
|
+
return mapOf("temporaryDirectory" to FileUtils.getTemporaryDirectory(reactApplicationContext).path)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
override fun createFile(path: String, data: String, promise: Promise) {
|
|
30
|
+
try {
|
|
31
|
+
val sanitizedPath = FileUtils.sanitizePath(path)
|
|
32
|
+
val file = File(sanitizedPath)
|
|
33
|
+
val parentDir = file.parentFile
|
|
34
|
+
if (parentDir != null && !parentDir.exists()) {
|
|
35
|
+
val error = CloudStorageError.DirectoryNotFound(parentDir.path)
|
|
36
|
+
promise.reject(error.code, error.message, error)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
FileUtils.writeFile(file, data)
|
|
40
|
+
promise.resolve(file.path)
|
|
41
|
+
} catch (e: CloudStorageError) {
|
|
42
|
+
promise.reject(e.code, e.message, e)
|
|
43
|
+
} catch (e: Exception) {
|
|
44
|
+
val unknownError = CloudStorageError.Unknown(e.message ?: "An unknown error occurred")
|
|
45
|
+
promise.reject(unknownError.code, unknownError.message, e)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override fun readFile(path: String, promise: Promise) {
|
|
50
|
+
try {
|
|
51
|
+
val sanitizedPath = FileUtils.sanitizePath(path)
|
|
52
|
+
val file = File(sanitizedPath)
|
|
53
|
+
val content = FileUtils.readFile(file)
|
|
54
|
+
promise.resolve(content)
|
|
55
|
+
} catch (e: CloudStorageError) {
|
|
56
|
+
promise.reject(e.code, e.message, e)
|
|
57
|
+
} catch (e: Exception) {
|
|
58
|
+
val unknownError = CloudStorageError.Unknown(e.message ?: "An unknown error occurred")
|
|
59
|
+
promise.reject(unknownError.code, unknownError.message, e)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
override fun downloadFile(remoteUri: String, localPath: String, options: ReadableMap?, promise: Promise) {
|
|
64
|
+
val client = OkHttpClient()
|
|
65
|
+
val requestBuilder = Request.Builder()
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
requestBuilder.url(remoteUri)
|
|
69
|
+
} catch (e: IllegalArgumentException) {
|
|
70
|
+
val error = CloudStorageError.InvalidUrl(remoteUri)
|
|
71
|
+
promise.reject(error.code, error.message, e)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (options?.hasKey("headers") == true) {
|
|
76
|
+
val headers = options.getMap("headers")
|
|
77
|
+
val iterator = headers?.keySetIterator()
|
|
78
|
+
while (iterator?.hasNextKey() == true) {
|
|
79
|
+
val key = iterator.nextKey()
|
|
80
|
+
requestBuilder.addHeader(key, headers.getString(key)!!)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
val request = requestBuilder.build()
|
|
85
|
+
|
|
86
|
+
client.newCall(request).enqueue(object : Callback {
|
|
87
|
+
override fun onFailure(call: Call, e: IOException) {
|
|
88
|
+
val errorMessage = "Download error for path $remoteUri: ${e.message ?: "Unknown download error"}"
|
|
89
|
+
val error = CloudStorageError.NetworkError(errorMessage)
|
|
90
|
+
promise.reject(error.code, error.message, e)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
override fun onResponse(call: Call, response: Response) {
|
|
94
|
+
if (!response.isSuccessful) {
|
|
95
|
+
val errorMessage = "Download error for path $remoteUri: HTTP ${response.code}: ${response.message}"
|
|
96
|
+
val error = CloudStorageError.NetworkError(errorMessage)
|
|
97
|
+
promise.reject(error.code, error.message)
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
val sanitizedPath = FileUtils.sanitizePath(localPath)
|
|
103
|
+
val localFile = File(sanitizedPath)
|
|
104
|
+
val parentDir = localFile.parentFile
|
|
105
|
+
if (parentDir != null && !parentDir.exists()) {
|
|
106
|
+
parentDir.mkdirs()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
val sink = localFile.sink().buffer()
|
|
110
|
+
sink.writeAll(response.body!!.source())
|
|
111
|
+
sink.close()
|
|
112
|
+
promise.resolve(null)
|
|
113
|
+
} catch (e: Exception) {
|
|
114
|
+
val sanitizedPath = FileUtils.sanitizePath(localPath)
|
|
115
|
+
val error = CloudStorageError.WriteError(sanitizedPath)
|
|
116
|
+
promise.reject(error.code, error.message, e)
|
|
117
|
+
} finally {
|
|
118
|
+
response.body?.close()
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
override fun uploadFile(localPath: String, remoteUri: String, options: ReadableMap, promise: Promise) {
|
|
125
|
+
val sanitizedPath = try {
|
|
126
|
+
FileUtils.sanitizePath(localPath)
|
|
127
|
+
} catch (e: CloudStorageError) {
|
|
128
|
+
promise.reject(e.code, e.message, e)
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
val localFile = File(sanitizedPath)
|
|
132
|
+
if (!localFile.exists()) {
|
|
133
|
+
promise.reject(CloudStorageError.FileNotFound(sanitizedPath).code, CloudStorageError.FileNotFound(sanitizedPath).message)
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
val uploadTypeString = options.getString("uploadType")
|
|
138
|
+
if (uploadTypeString == null) {
|
|
139
|
+
promise.reject(CloudStorageError.Unknown("uploadType is required").code, CloudStorageError.Unknown("uploadType is required").message)
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
val uploadType = try {
|
|
144
|
+
UploadType.valueOf(uploadTypeString.uppercase())
|
|
145
|
+
} catch (e: IllegalArgumentException) {
|
|
146
|
+
promise.reject(CloudStorageError.Unknown("Invalid uploadType: $uploadTypeString").code, CloudStorageError.Unknown("Invalid uploadType: $uploadTypeString").message)
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
val client = OkHttpClient()
|
|
151
|
+
val requestBuilder = Request.Builder()
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
requestBuilder.url(remoteUri)
|
|
155
|
+
} catch (e: IllegalArgumentException) {
|
|
156
|
+
val error = CloudStorageError.InvalidUrl(remoteUri)
|
|
157
|
+
promise.reject(error.code, error.message, e)
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (options.hasKey("headers")) {
|
|
162
|
+
options.getMap("headers")?.let { headers ->
|
|
163
|
+
val iterator = headers.keySetIterator()
|
|
164
|
+
while (iterator.hasNextKey()) {
|
|
165
|
+
val key = iterator.nextKey()
|
|
166
|
+
requestBuilder.addHeader(key, headers.getString(key)!!)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
val httpMethod = options.getString("method")?.uppercase() ?: "POST"
|
|
172
|
+
|
|
173
|
+
val requestBody = when (uploadType) {
|
|
174
|
+
UploadType.BINARY -> {
|
|
175
|
+
val mediaType = URLConnection.guessContentTypeFromName(localFile.name)?.toMediaTypeOrNull()
|
|
176
|
+
?: "application/octet-stream".toMediaTypeOrNull()
|
|
177
|
+
localFile.asRequestBody(mediaType)
|
|
178
|
+
}
|
|
179
|
+
UploadType.MULTIPART -> {
|
|
180
|
+
val fieldName = options.getString("fieldName")
|
|
181
|
+
if (fieldName == null) {
|
|
182
|
+
promise.reject(CloudStorageError.Unknown("fieldName is required for multipart uploads").code, CloudStorageError.Unknown("fieldName is required for multipart uploads").message)
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
val mediaType = URLConnection.guessContentTypeFromName(localFile.name)?.toMediaTypeOrNull()
|
|
187
|
+
?: "application/octet-stream".toMediaTypeOrNull()
|
|
188
|
+
|
|
189
|
+
val multipartBodyBuilder = MultipartBody.Builder()
|
|
190
|
+
.setType(MultipartBody.FORM)
|
|
191
|
+
.addFormDataPart(fieldName, localFile.name, localFile.asRequestBody(mediaType))
|
|
192
|
+
|
|
193
|
+
if (options.hasKey("parameters")) {
|
|
194
|
+
options.getMap("parameters")?.let { parameters ->
|
|
195
|
+
val paramIterator = parameters.keySetIterator()
|
|
196
|
+
while (paramIterator.hasNextKey()) {
|
|
197
|
+
val key = paramIterator.nextKey()
|
|
198
|
+
multipartBodyBuilder.addFormDataPart(key, parameters.getString(key)!!)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
multipartBodyBuilder.build()
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
requestBuilder.method(httpMethod, requestBody)
|
|
207
|
+
val request = requestBuilder.build()
|
|
208
|
+
|
|
209
|
+
client.newCall(request).enqueue(object : Callback {
|
|
210
|
+
override fun onFailure(call: Call, e: IOException) {
|
|
211
|
+
val errorMessage = "Upload error for path $sanitizedPath: ${e.message ?: "Unknown upload error"}"
|
|
212
|
+
val error = CloudStorageError.NetworkError(errorMessage)
|
|
213
|
+
promise.reject(error.code, error.message, e)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
override fun onResponse(call: Call, response: Response) {
|
|
217
|
+
if (!response.isSuccessful) {
|
|
218
|
+
val errorMessage = "Upload error for path $sanitizedPath: HTTP ${response.code}: ${response.message}"
|
|
219
|
+
val error = CloudStorageError.NetworkError(errorMessage)
|
|
220
|
+
promise.reject(error.code, error.message)
|
|
221
|
+
} else {
|
|
222
|
+
promise.resolve(null)
|
|
223
|
+
}
|
|
224
|
+
response.body?.close()
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
companion object {
|
|
230
|
+
const val NAME = NativeCloudStorageLocalFileSystemSpec.NAME
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
package com.cloudstorage
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
|
|
9
|
+
class CloudStoragePackage : BaseReactPackage() {
|
|
10
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
11
|
+
return when (name) {
|
|
12
|
+
CloudStorageLocalFileSystemModule.NAME -> CloudStorageLocalFileSystemModule(reactContext)
|
|
13
|
+
else -> null
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
18
|
+
return ReactModuleInfoProvider {
|
|
19
|
+
mapOf(
|
|
20
|
+
CloudStorageLocalFileSystemModule.NAME to
|
|
21
|
+
ReactModuleInfo(
|
|
22
|
+
CloudStorageLocalFileSystemModule.NAME,
|
|
23
|
+
CloudStorageLocalFileSystemModule::class.java.name,
|
|
24
|
+
false,
|
|
25
|
+
false,
|
|
26
|
+
false,
|
|
27
|
+
ReactModuleInfo.classIsTurboModule(CloudStorageLocalFileSystemModule::class.java)
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package com.cloudstorage
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import java.io.File
|
|
5
|
+
import java.io.IOException
|
|
6
|
+
|
|
7
|
+
object FileUtils {
|
|
8
|
+
fun getTemporaryDirectory(context: Context): File {
|
|
9
|
+
return context.cacheDir
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
fun writeFile(file: File, content: String) {
|
|
13
|
+
try {
|
|
14
|
+
file.writeText(content, Charsets.UTF_8)
|
|
15
|
+
} catch (e: IOException) {
|
|
16
|
+
throw CloudStorageError.WriteError(file.path)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fun readFile(file: File): String {
|
|
21
|
+
if (!file.exists()) {
|
|
22
|
+
throw CloudStorageError.FileNotFound(file.path)
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return file.readText(Charsets.UTF_8)
|
|
26
|
+
} catch (e: IOException) {
|
|
27
|
+
throw CloudStorageError.ReadError(file.path)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fun sanitizePath(path: String): String {
|
|
32
|
+
// Remove the "file://" prefix
|
|
33
|
+
val sanitizedPath = path.removePrefix("file://")
|
|
34
|
+
|
|
35
|
+
return try {
|
|
36
|
+
File(sanitizedPath).canonicalPath
|
|
37
|
+
} catch (e: IOException) {
|
|
38
|
+
throw CloudStorageError.InvalidUrl(path)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
package/app.plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./
|
|
1
|
+
module.exports = require('./dist/commonjs/expo-plugin/index.js');
|