mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 18:06:53 +01:00
Add blurhash and dim to Nip96Uploader.kt
This commit is contained in:
@@ -30,6 +30,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
|||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.service.HttpStatusMessages
|
import com.vitorpamplona.amethyst.service.HttpStatusMessages
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
|
import com.vitorpamplona.amethyst.service.uploads.BlurhashMetadataCalculator
|
||||||
import com.vitorpamplona.amethyst.service.uploads.MediaUploadResult
|
import com.vitorpamplona.amethyst.service.uploads.MediaUploadResult
|
||||||
import com.vitorpamplona.amethyst.ui.stringRes
|
import com.vitorpamplona.amethyst.ui.stringRes
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.JsonMapper
|
import com.vitorpamplona.quartz.nip01Core.core.JsonMapper
|
||||||
@@ -106,11 +107,13 @@ class Nip96Uploader {
|
|||||||
val myContentType = contentType ?: contentResolver.getType(uri)
|
val myContentType = contentType ?: contentResolver.getType(uri)
|
||||||
val length = size ?: contentResolver.querySize(uri) ?: fileSize(uri) ?: 0
|
val length = size ?: contentResolver.querySize(uri) ?: fileSize(uri) ?: 0
|
||||||
|
|
||||||
|
val localMetadata = BlurhashMetadataCalculator.computeFromUri(context, uri, myContentType)
|
||||||
val imageInputStream = contentResolver.openInputStream(uri)
|
val imageInputStream = contentResolver.openInputStream(uri)
|
||||||
|
|
||||||
checkNotNull(imageInputStream) { "Can't open the image input stream" }
|
checkNotNull(imageInputStream) { "Can't open the image input stream" }
|
||||||
|
|
||||||
return imageInputStream.use { stream ->
|
val serverResult =
|
||||||
|
imageInputStream.use { stream ->
|
||||||
upload(
|
upload(
|
||||||
stream,
|
stream,
|
||||||
length,
|
length,
|
||||||
@@ -124,6 +127,16 @@ class Nip96Uploader {
|
|||||||
context,
|
context,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val merged =
|
||||||
|
localMetadata?.let { (blur, dim) ->
|
||||||
|
serverResult.copy(
|
||||||
|
dimension = dim ?: serverResult.dimension,
|
||||||
|
blurHash = blur ?: serverResult.blurHash,
|
||||||
|
)
|
||||||
|
} ?: serverResult
|
||||||
|
|
||||||
|
return merged
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun upload(
|
suspend fun upload(
|
||||||
|
|||||||
Reference in New Issue
Block a user