From 1ca0abf30dc71e512507acfb8f27f8c3d7807cb6 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sun, 5 Jan 2025 11:22:40 -0500 Subject: [PATCH] Minor refactoring: uploaders can do image and videos. --- .../com/vitorpamplona/amethyst/ImageUploadTesting.kt | 4 ++-- .../amethyst/service/uploads/UploadOrchestrator.kt | 4 ++-- .../service/uploads/blossom/BlossomUploader.kt | 6 +++--- .../amethyst/service/uploads/nip96/Nip96Uploader.kt | 10 +++++----- .../amethyst/ui/actions/NewUserMetadataViewModel.kt | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt index 495c1ed7a..ec8ca4da5 100644 --- a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt +++ b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt @@ -85,7 +85,7 @@ class ImageUploadTesting { val inputStream = paylod.inputStream() val result = BlossomUploader() - .uploadImage( + .upload( inputStream = inputStream, hash = initialHash, length = paylod.size, @@ -127,7 +127,7 @@ class ImageUploadTesting { val inputStream = paylod.inputStream() val result = Nip96Uploader() - .uploadImage( + .upload( inputStream = inputStream, length = paylod.size.toLong(), contentType = "image/png", diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/UploadOrchestrator.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/UploadOrchestrator.kt index b8766d932..958e75f13 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/UploadOrchestrator.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/UploadOrchestrator.kt @@ -142,7 +142,7 @@ class UploadOrchestrator { updateState(0.2, UploadingState.Uploading) return try { val result = - Nip96Uploader().uploadImage( + Nip96Uploader().upload( uri = fileUri, contentType = contentType, size = size, @@ -186,7 +186,7 @@ class UploadOrchestrator { return try { val result = BlossomUploader() - .uploadImage( + .upload( uri = fileUri, contentType = contentType, size = size, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/blossom/BlossomUploader.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/blossom/BlossomUploader.kt index e19502ff3..abc6fc888 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/blossom/BlossomUploader.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/blossom/BlossomUploader.kt @@ -63,7 +63,7 @@ class BlossomUploader { } }.getOrNull() - suspend fun uploadImage( + suspend fun upload( uri: Uri, contentType: String?, size: Long?, @@ -94,7 +94,7 @@ class BlossomUploader { checkNotNull(imageInputStream) { "Can't open the image input stream" } - return uploadImage( + return upload( imageInputStream, hash, payload.size, @@ -114,7 +114,7 @@ class BlossomUploader { return "Nostr $encodedNIP98Event" } - suspend fun uploadImage( + suspend fun upload( inputStream: InputStream, hash: HexKey, length: Int, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/nip96/Nip96Uploader.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/nip96/Nip96Uploader.kt index 7ff2eae37..cb7f76b61 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/nip96/Nip96Uploader.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/nip96/Nip96Uploader.kt @@ -52,7 +52,7 @@ val charPool: List = ('a'..'z') + ('A'..'Z') + ('0'..'9') fun randomChars() = List(16) { charPool.random() }.joinToString("") class Nip96Uploader { - suspend fun uploadImage( + suspend fun upload( uri: Uri, contentType: String?, size: Long?, @@ -63,7 +63,7 @@ class Nip96Uploader { onProgress: (percentage: Float) -> Unit, httpAuth: suspend (String, String, ByteArray?) -> HTTPAuthorizationEvent?, context: Context, - ) = uploadImage( + ) = upload( uri, contentType, size, @@ -85,7 +85,7 @@ class Nip96Uploader { fun fileSize(uri: Uri) = runCatching { uri.toFile().length() }.getOrNull() - suspend fun uploadImage( + suspend fun upload( uri: Uri, contentType: String?, size: Long?, @@ -107,7 +107,7 @@ class Nip96Uploader { checkNotNull(imageInputStream) { "Can't open the image input stream" } - return uploadImage( + return upload( imageInputStream, length, myContentType, @@ -121,7 +121,7 @@ class Nip96Uploader { ) } - suspend fun uploadImage( + suspend fun upload( inputStream: InputStream, length: Long, contentType: String?, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewUserMetadataViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewUserMetadataViewModel.kt index 3f38cd28d..14cf48702 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewUserMetadataViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewUserMetadataViewModel.kt @@ -177,7 +177,7 @@ class NewUserMetadataViewModel : ViewModel() { try { val result = if (account.settings.defaultFileServer.type == ServerType.NIP96) { - Nip96Uploader().uploadImage( + Nip96Uploader().upload( uri = compResult.uri, contentType = compResult.contentType, size = compResult.size, @@ -190,7 +190,7 @@ class NewUserMetadataViewModel : ViewModel() { context = context, ) } else { - BlossomUploader().uploadImage( + BlossomUploader().upload( uri = compResult.uri, contentType = compResult.contentType, size = compResult.size,