Skip to content

Commit

Permalink
Minor refactoring: uploaders can do image and videos.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Jan 5, 2025
1 parent d0a9c1c commit 1ca0abf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ImageUploadTesting {
val inputStream = paylod.inputStream()
val result =
BlossomUploader()
.uploadImage(
.upload(
inputStream = inputStream,
hash = initialHash,
length = paylod.size,
Expand Down Expand Up @@ -127,7 +127,7 @@ class ImageUploadTesting {
val inputStream = paylod.inputStream()
val result =
Nip96Uploader()
.uploadImage(
.upload(
inputStream = inputStream,
length = paylod.size.toLong(),
contentType = "image/png",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -186,7 +186,7 @@ class UploadOrchestrator {
return try {
val result =
BlossomUploader()
.uploadImage(
.upload(
uri = fileUri,
contentType = contentType,
size = size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class BlossomUploader {
}
}.getOrNull()

suspend fun uploadImage(
suspend fun upload(
uri: Uri,
contentType: String?,
size: Long?,
Expand Down Expand Up @@ -94,7 +94,7 @@ class BlossomUploader {

checkNotNull(imageInputStream) { "Can't open the image input stream" }

return uploadImage(
return upload(
imageInputStream,
hash,
payload.size,
Expand All @@ -114,7 +114,7 @@ class BlossomUploader {
return "Nostr $encodedNIP98Event"
}

suspend fun uploadImage(
suspend fun upload(
inputStream: InputStream,
hash: HexKey,
length: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand All @@ -63,7 +63,7 @@ class Nip96Uploader {
onProgress: (percentage: Float) -> Unit,
httpAuth: suspend (String, String, ByteArray?) -> HTTPAuthorizationEvent?,
context: Context,
) = uploadImage(
) = upload(
uri,
contentType,
size,
Expand All @@ -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?,
Expand All @@ -107,7 +107,7 @@ class Nip96Uploader {

checkNotNull(imageInputStream) { "Can't open the image input stream" }

return uploadImage(
return upload(
imageInputStream,
length,
myContentType,
Expand All @@ -121,7 +121,7 @@ class Nip96Uploader {
)
}

suspend fun uploadImage(
suspend fun upload(
inputStream: InputStream,
length: Long,
contentType: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -190,7 +190,7 @@ class NewUserMetadataViewModel : ViewModel() {
context = context,
)
} else {
BlossomUploader().uploadImage(
BlossomUploader().upload(
uri = compResult.uri,
contentType = compResult.contentType,
size = compResult.size,
Expand Down

0 comments on commit 1ca0abf

Please sign in to comment.