From 2a98c1e755d64407bf36a877e0f79514d1b72064 Mon Sep 17 00:00:00 2001 From: kyle Date: Thu, 12 Dec 2024 15:15:35 -0800 Subject: [PATCH 1/2] Add storage instance with custom URL string --- Sources/SkipFirebaseStorage/SkipFirebaseStorage.swift | 8 ++++++++ .../SkipFirebaseStorageTests.swift | 2 ++ 2 files changed, 10 insertions(+) diff --git a/Sources/SkipFirebaseStorage/SkipFirebaseStorage.swift b/Sources/SkipFirebaseStorage/SkipFirebaseStorage.swift index e5671f8..19d2936 100644 --- a/Sources/SkipFirebaseStorage/SkipFirebaseStorage.swift +++ b/Sources/SkipFirebaseStorage/SkipFirebaseStorage.swift @@ -26,6 +26,14 @@ public final class Storage { Storage(com.google.firebase.storage.FirebaseStorage.getInstance(app.app)) } + public static func storage(url: String) -> Storage { + Storage(com.google.firebase.storage.FirebaseStorage.getInstance(url)) + } + + public static func storage(app: FirebaseApp, url: String) -> Storage { + Storage(com.google.firebase.storage.FirebaseStorage.getInstance(app.app, url)) + } + public var app: FirebaseApp { FirebaseApp(app: platformValue.getApp()) } diff --git a/Tests/SkipFirebaseStorageTests/SkipFirebaseStorageTests.swift b/Tests/SkipFirebaseStorageTests/SkipFirebaseStorageTests.swift index d689b2b..de8f8d1 100644 --- a/Tests/SkipFirebaseStorageTests/SkipFirebaseStorageTests.swift +++ b/Tests/SkipFirebaseStorageTests/SkipFirebaseStorageTests.swift @@ -35,6 +35,8 @@ let logger: Logger = Logger(subsystem: "SkipFirebaseStorageTests", category: "Te let fileURL = URL(fileURLWithPath: "/dev/null") // we don't actually connect to the storage here, so we are just checking the API signatures for get/put data + let storageCustomURL = Storage.storage(url: "gs://") + let storage = Storage.storage() let ref: StorageReference = storage.reference() let _: StorageReference = storage.reference(withPath: "test") From 40b3f91bd3c8bfaa1b1d086cffcba0fd2600d0c7 Mon Sep 17 00:00:00 2001 From: kyle Date: Thu, 12 Dec 2024 15:37:13 -0800 Subject: [PATCH 2/2] Fix optional metadata uploading with putFile Passing nil metadata to `putFile` is an error (cf. `putData` impl) --- Sources/SkipFirebaseStorage/SkipFirebaseStorage.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SkipFirebaseStorage/SkipFirebaseStorage.swift b/Sources/SkipFirebaseStorage/SkipFirebaseStorage.swift index 19d2936..284fa47 100644 --- a/Sources/SkipFirebaseStorage/SkipFirebaseStorage.swift +++ b/Sources/SkipFirebaseStorage/SkipFirebaseStorage.swift @@ -246,7 +246,7 @@ public class StorageReference: KotlinConverting Void = { _, _ in }) -> StorageUploadTask { let fileURI: android.net.Uri = android.net.Uri.parse(fileURL.kotlin().toString()) - let uploadTask = platformValue.putFile(fileURI, metadata?.platformValue, nil) + let uploadTask = metadata == nil ? platformValue.putFile(fileURI) : platformValue.putFile(fileURI, metadata!.platformValue, nil) uploadTask.addOnFailureListener { exception in completion(nil, ErrorException(exception)) }.addOnSuccessListener { taskSnapshot in