Adjusting NostrFilesDev to the latest API
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user