From 12b0d74999bf4ba0b1ec5dd0ef45f3df9e2bc8c1 Mon Sep 17 00:00:00 2001 From: Bas Buijsen Date: Thu, 20 Jun 2024 15:06:12 +0200 Subject: [PATCH] add storage with custom url --- .../kotlin/dev/gitlive/firebase/storage/storage.kt | 10 ++++++---- .../kotlin/dev/gitlive/firebase/storage/storage.kt | 6 ++++++ .../kotlin/dev/gitlive/firebase/storage/storage.kt | 8 ++++++++ .../dev/gitlive/firebase/storage/externals/storage.kt | 2 ++ .../kotlin/dev/gitlive/firebase/storage/storage.kt | 7 +++++-- .../kotlin/dev/gitlive/firebase/storage/storage.jvm.kt | 8 +++++--- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/firebase-storage/src/androidMain/kotlin/dev/gitlive/firebase/storage/storage.kt b/firebase-storage/src/androidMain/kotlin/dev/gitlive/firebase/storage/storage.kt index a4cd20c6c..6df20f6c3 100644 --- a/firebase-storage/src/androidMain/kotlin/dev/gitlive/firebase/storage/storage.kt +++ b/firebase-storage/src/androidMain/kotlin/dev/gitlive/firebase/storage/storage.kt @@ -26,11 +26,13 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import kotlinx.coroutines.tasks.await -actual val Firebase.storage get() = - FirebaseStorage(com.google.firebase.storage.FirebaseStorage.getInstance()) +actual val Firebase.storage get() = FirebaseStorage(com.google.firebase.storage.FirebaseStorage.getInstance()) -actual fun Firebase.storage(app: FirebaseApp) = - FirebaseStorage(com.google.firebase.storage.FirebaseStorage.getInstance(app.android)) +actual fun Firebase.storage(url: String): FirebaseStorage = FirebaseStorage(com.google.firebase.storage.FirebaseStorage.getInstance(url)) + +actual fun Firebase.storage(app: FirebaseApp) = FirebaseStorage(com.google.firebase.storage.FirebaseStorage.getInstance(app.android)) + +actual fun Firebase.storage(app: FirebaseApp, url: String) = FirebaseStorage(com.google.firebase.storage.FirebaseStorage.getInstance(app.android, url)) actual class FirebaseStorage(val android: com.google.firebase.storage.FirebaseStorage) { actual val maxOperationRetryTimeMillis = android.maxOperationRetryTimeMillis diff --git a/firebase-storage/src/commonMain/kotlin/dev/gitlive/firebase/storage/storage.kt b/firebase-storage/src/commonMain/kotlin/dev/gitlive/firebase/storage/storage.kt index 613c7a214..a928a25b1 100644 --- a/firebase-storage/src/commonMain/kotlin/dev/gitlive/firebase/storage/storage.kt +++ b/firebase-storage/src/commonMain/kotlin/dev/gitlive/firebase/storage/storage.kt @@ -11,9 +11,15 @@ import kotlinx.coroutines.launch /** Returns the [FirebaseStorage] instance of the default [FirebaseApp]. */ expect val Firebase.storage: FirebaseStorage +/** Returns the [FirebaseStorage] instance of the default [FirebaseApp]. */ +expect fun Firebase.storage(url: String): FirebaseStorage + /** Returns the [FirebaseStorage] instance of a given [FirebaseApp]. */ expect fun Firebase.storage(app: FirebaseApp): FirebaseStorage +/** Returns the [FirebaseStorage] instance of a given [FirebaseApp]. */ +expect fun Firebase.storage(app: FirebaseApp, url: String): FirebaseStorage + /** * FirebaseStorage is a service that supports uploading and downloading large objects to Google * Cloud Storage. Pass a custom instance of [FirebaseApp] to [Firebase.storage] diff --git a/firebase-storage/src/iosMain/kotlin/dev/gitlive/firebase/storage/storage.kt b/firebase-storage/src/iosMain/kotlin/dev/gitlive/firebase/storage/storage.kt index 08aa883e5..c30387c40 100644 --- a/firebase-storage/src/iosMain/kotlin/dev/gitlive/firebase/storage/storage.kt +++ b/firebase-storage/src/iosMain/kotlin/dev/gitlive/firebase/storage/storage.kt @@ -31,10 +31,18 @@ import platform.Foundation.NSURL actual val Firebase.storage get() = FirebaseStorage(FIRStorage.storage()) +actual fun Firebase.storage(url: String): FirebaseStorage = FirebaseStorage( + FIRStorage.storageWithURL(url) +) + actual fun Firebase.storage(app: FirebaseApp): FirebaseStorage = FirebaseStorage( FIRStorage.storageForApp(app.ios as objcnames.classes.FIRApp) ) +actual fun Firebase.storage(app: FirebaseApp, url: String) = FirebaseStorage( + FIRStorage.storageForApp(app.ios as objcnames.classes.FIRApp, url) +) + actual class FirebaseStorage(val ios: FIRStorage) { actual val maxOperationRetryTimeMillis = ios.maxOperationRetryTime().toLong() actual val maxUploadRetryTimeMillis = ios.maxUploadRetryTime().toLong() diff --git a/firebase-storage/src/jsMain/kotlin/dev/gitlive/firebase/storage/externals/storage.kt b/firebase-storage/src/jsMain/kotlin/dev/gitlive/firebase/storage/externals/storage.kt index 52fca0864..13c23ce61 100644 --- a/firebase-storage/src/jsMain/kotlin/dev/gitlive/firebase/storage/externals/storage.kt +++ b/firebase-storage/src/jsMain/kotlin/dev/gitlive/firebase/storage/externals/storage.kt @@ -6,6 +6,8 @@ package dev.gitlive.firebase.storage.externals import dev.gitlive.firebase.externals.FirebaseApp import kotlin.js.Promise +external fun getStorage(app: FirebaseApp? = definedExternally, url: String): FirebaseStorage + external fun getStorage(app: FirebaseApp? = definedExternally): FirebaseStorage external fun ref(storage: FirebaseStorage, url: String? = definedExternally): StorageReference diff --git a/firebase-storage/src/jsMain/kotlin/dev/gitlive/firebase/storage/storage.kt b/firebase-storage/src/jsMain/kotlin/dev/gitlive/firebase/storage/storage.kt index 492a88919..6cb2b34a6 100644 --- a/firebase-storage/src/jsMain/kotlin/dev/gitlive/firebase/storage/storage.kt +++ b/firebase-storage/src/jsMain/kotlin/dev/gitlive/firebase/storage/storage.kt @@ -18,8 +18,11 @@ import kotlinx.coroutines.flow.emitAll actual val Firebase.storage get() = FirebaseStorage(getStorage()) -actual fun Firebase.storage(app: FirebaseApp) = - FirebaseStorage(getStorage(app.js)) +actual fun Firebase.storage(url: String): FirebaseStorage = FirebaseStorage(getStorage(null, url), ) + +actual fun Firebase.storage(app: FirebaseApp) = FirebaseStorage(getStorage(app.js)) + +actual fun Firebase.storage(app: FirebaseApp, url: String) = FirebaseStorage(getStorage(app.js, url)) actual class FirebaseStorage(val js: dev.gitlive.firebase.storage.externals.FirebaseStorage) { actual val maxOperationRetryTimeMillis = js.maxOperationRetryTime.toLong() diff --git a/firebase-storage/src/jvmMain/kotlin/dev/gitlive/firebase/storage/storage.jvm.kt b/firebase-storage/src/jvmMain/kotlin/dev/gitlive/firebase/storage/storage.jvm.kt index ef187c0d2..0c3829529 100644 --- a/firebase-storage/src/jvmMain/kotlin/dev/gitlive/firebase/storage/storage.jvm.kt +++ b/firebase-storage/src/jvmMain/kotlin/dev/gitlive/firebase/storage/storage.jvm.kt @@ -8,10 +8,12 @@ import dev.gitlive.firebase.FirebaseException actual val Firebase.storage: FirebaseStorage get() = TODO("Not yet implemented") +actual fun Firebase.storage(url: String): FirebaseStorage = TODO("Not yet implemented") + /** Returns the [FirebaseStorage] instance of a given [FirebaseApp]. */ -actual fun Firebase.storage(app: FirebaseApp): FirebaseStorage { - TODO("Not yet implemented") -} +actual fun Firebase.storage(app: FirebaseApp): FirebaseStorage = TODO("Not yet implemented") + +actual fun Firebase.storage(app: FirebaseApp, url: String): FirebaseStorage = TODO("Not yet implemented") actual class FirebaseStorage { actual val maxOperationRetryTimeMillis: Long