Minor refactoring: uploaders can do image and videos.

This commit is contained in:
Vitor Pamplona 2025-01-05 11:22:40 -05:00
parent d0a9c1ccd0
commit 1ca0abf30d
5 changed files with 14 additions and 14 deletions

View File

@ -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",

View File

@ -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,

View File

@ -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,

View File

@ -52,7 +52,7 @@ val charPool: List<Char> = ('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?,

View File

@ -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,