Adjusting NostrFilesDev to the latest API

This commit is contained in:
Vitor Pamplona
2023-05-07 18:47:39 -04:00
parent 59d7f7cc70
commit aa07fbfc94
2 changed files with 31 additions and 3 deletions
@@ -4,6 +4,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.amethyst.ui.actions.ImageUploader import com.vitorpamplona.amethyst.ui.actions.ImageUploader
import com.vitorpamplona.amethyst.ui.actions.ImgurServer import com.vitorpamplona.amethyst.ui.actions.ImgurServer
import com.vitorpamplona.amethyst.ui.actions.NostrBuildServer import com.vitorpamplona.amethyst.ui.actions.NostrBuildServer
import com.vitorpamplona.amethyst.ui.actions.NostrFilesDevServer
import com.vitorpamplona.amethyst.ui.actions.NostrImgServer import com.vitorpamplona.amethyst.ui.actions.NostrImgServer
import junit.framework.TestCase.assertNotNull import junit.framework.TestCase.assertNotNull
import junit.framework.TestCase.fail import junit.framework.TestCase.fail
@@ -38,7 +39,7 @@ class ImageUploadTesting {
} }
) )
delay(1000) delay(5000)
} }
@Test() @Test()
@@ -86,4 +87,27 @@ class ImageUploadTesting {
delay(1000) 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)
}
} }
@@ -45,7 +45,7 @@ object ImageUploader {
} else if (server == ServersAvailable.NOSTR_BUILD) { } else if (server == ServersAvailable.NOSTR_BUILD) {
NostrBuildServer() NostrBuildServer()
} else if (server == ServersAvailable.NOSTRFILES_DEV) { } else if (server == ServersAvailable.NOSTRFILES_DEV) {
NostrfilesDevServer() NostrFilesDevServer()
} else { } else {
ImgurServer() ImgurServer()
} }
@@ -179,7 +179,7 @@ class NostrBuildServer : FileServer() {
override fun clientID() = null override fun clientID() = null
} }
class NostrfilesDevServer : FileServer() { class NostrFilesDevServer : FileServer() {
override fun postUrl(contentType: String?) = "https://nostrfiles.dev/upload_image" override fun postUrl(contentType: String?) = "https://nostrfiles.dev/upload_image"
override fun parseUrlFromSucess(body: String): String? { override fun parseUrlFromSucess(body: String): String? {
val tree = jacksonObjectMapper().readTree(body) val tree = jacksonObjectMapper().readTree(body)
@@ -187,5 +187,9 @@ class NostrfilesDevServer : FileServer() {
return url return url
} }
override fun inputParameterName(contentType: String?): String {
return "file"
}
override fun clientID() = null override fun clientID() = null
} }