From aa07fbfc94e93cfd04a61363398b8f62724f5276 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sun, 7 May 2023 18:47:39 -0400 Subject: [PATCH] Adjusting NostrFilesDev to the latest API --- .../amethyst/ImageUploadTesting.kt | 26 ++++++++++++++++++- .../amethyst/ui/actions/ImageUploader.kt | 8 ++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt b/app/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt index bdcbca26d..bb25fe513 100644 --- a/app/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt +++ b/app/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt @@ -4,6 +4,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import com.vitorpamplona.amethyst.ui.actions.ImageUploader import com.vitorpamplona.amethyst.ui.actions.ImgurServer import com.vitorpamplona.amethyst.ui.actions.NostrBuildServer +import com.vitorpamplona.amethyst.ui.actions.NostrFilesDevServer import com.vitorpamplona.amethyst.ui.actions.NostrImgServer import junit.framework.TestCase.assertNotNull import junit.framework.TestCase.fail @@ -38,7 +39,7 @@ class ImageUploadTesting { } ) - delay(1000) + delay(5000) } @Test() @@ -86,4 +87,27 @@ class ImageUploadTesting { delay(1000) } + + @Test() + fun testNostrFilesDevUpload() = runBlocking { + val bytes = Base64.getDecoder().decode(image) + val inputStream = bytes.inputStream() + + ImageUploader.uploadImage( + inputStream, + bytes.size.toLong(), + "image/gif", + NostrFilesDevServer(), + onSuccess = { url, contentType -> + println("Uploaded to $url") + assertNotNull(url) + }, + onError = { + println("Failed to Upload") + fail("${it.message}") + } + ) + + delay(5000) + } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/ImageUploader.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/ImageUploader.kt index 1a9226a46..b85bfaec0 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/ImageUploader.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/ImageUploader.kt @@ -45,7 +45,7 @@ object ImageUploader { } else if (server == ServersAvailable.NOSTR_BUILD) { NostrBuildServer() } else if (server == ServersAvailable.NOSTRFILES_DEV) { - NostrfilesDevServer() + NostrFilesDevServer() } else { ImgurServer() } @@ -179,7 +179,7 @@ class NostrBuildServer : FileServer() { override fun clientID() = null } -class NostrfilesDevServer : FileServer() { +class NostrFilesDevServer : FileServer() { override fun postUrl(contentType: String?) = "https://nostrfiles.dev/upload_image" override fun parseUrlFromSucess(body: String): String? { val tree = jacksonObjectMapper().readTree(body) @@ -187,5 +187,9 @@ class NostrfilesDevServer : FileServer() { return url } + override fun inputParameterName(contentType: String?): String { + return "file" + } + override fun clientID() = null }