Minor refactoring: uploaders can do image and videos.
This commit is contained in:
@@ -85,7 +85,7 @@ class ImageUploadTesting {
|
|||||||
val inputStream = paylod.inputStream()
|
val inputStream = paylod.inputStream()
|
||||||
val result =
|
val result =
|
||||||
BlossomUploader()
|
BlossomUploader()
|
||||||
.uploadImage(
|
.upload(
|
||||||
inputStream = inputStream,
|
inputStream = inputStream,
|
||||||
hash = initialHash,
|
hash = initialHash,
|
||||||
length = paylod.size,
|
length = paylod.size,
|
||||||
@@ -127,7 +127,7 @@ class ImageUploadTesting {
|
|||||||
val inputStream = paylod.inputStream()
|
val inputStream = paylod.inputStream()
|
||||||
val result =
|
val result =
|
||||||
Nip96Uploader()
|
Nip96Uploader()
|
||||||
.uploadImage(
|
.upload(
|
||||||
inputStream = inputStream,
|
inputStream = inputStream,
|
||||||
length = paylod.size.toLong(),
|
length = paylod.size.toLong(),
|
||||||
contentType = "image/png",
|
contentType = "image/png",
|
||||||
|
|||||||
+2
-2
@@ -142,7 +142,7 @@ class UploadOrchestrator {
|
|||||||
updateState(0.2, UploadingState.Uploading)
|
updateState(0.2, UploadingState.Uploading)
|
||||||
return try {
|
return try {
|
||||||
val result =
|
val result =
|
||||||
Nip96Uploader().uploadImage(
|
Nip96Uploader().upload(
|
||||||
uri = fileUri,
|
uri = fileUri,
|
||||||
contentType = contentType,
|
contentType = contentType,
|
||||||
size = size,
|
size = size,
|
||||||
@@ -186,7 +186,7 @@ class UploadOrchestrator {
|
|||||||
return try {
|
return try {
|
||||||
val result =
|
val result =
|
||||||
BlossomUploader()
|
BlossomUploader()
|
||||||
.uploadImage(
|
.upload(
|
||||||
uri = fileUri,
|
uri = fileUri,
|
||||||
contentType = contentType,
|
contentType = contentType,
|
||||||
size = size,
|
size = size,
|
||||||
|
|||||||
+3
-3
@@ -63,7 +63,7 @@ class BlossomUploader {
|
|||||||
}
|
}
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
|
|
||||||
suspend fun uploadImage(
|
suspend fun upload(
|
||||||
uri: Uri,
|
uri: Uri,
|
||||||
contentType: String?,
|
contentType: String?,
|
||||||
size: Long?,
|
size: Long?,
|
||||||
@@ -94,7 +94,7 @@ class BlossomUploader {
|
|||||||
|
|
||||||
checkNotNull(imageInputStream) { "Can't open the image input stream" }
|
checkNotNull(imageInputStream) { "Can't open the image input stream" }
|
||||||
|
|
||||||
return uploadImage(
|
return upload(
|
||||||
imageInputStream,
|
imageInputStream,
|
||||||
hash,
|
hash,
|
||||||
payload.size,
|
payload.size,
|
||||||
@@ -114,7 +114,7 @@ class BlossomUploader {
|
|||||||
return "Nostr $encodedNIP98Event"
|
return "Nostr $encodedNIP98Event"
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun uploadImage(
|
suspend fun upload(
|
||||||
inputStream: InputStream,
|
inputStream: InputStream,
|
||||||
hash: HexKey,
|
hash: HexKey,
|
||||||
length: Int,
|
length: Int,
|
||||||
|
|||||||
+5
-5
@@ -52,7 +52,7 @@ val charPool: List<Char> = ('a'..'z') + ('A'..'Z') + ('0'..'9')
|
|||||||
fun randomChars() = List(16) { charPool.random() }.joinToString("")
|
fun randomChars() = List(16) { charPool.random() }.joinToString("")
|
||||||
|
|
||||||
class Nip96Uploader {
|
class Nip96Uploader {
|
||||||
suspend fun uploadImage(
|
suspend fun upload(
|
||||||
uri: Uri,
|
uri: Uri,
|
||||||
contentType: String?,
|
contentType: String?,
|
||||||
size: Long?,
|
size: Long?,
|
||||||
@@ -63,7 +63,7 @@ class Nip96Uploader {
|
|||||||
onProgress: (percentage: Float) -> Unit,
|
onProgress: (percentage: Float) -> Unit,
|
||||||
httpAuth: suspend (String, String, ByteArray?) -> HTTPAuthorizationEvent?,
|
httpAuth: suspend (String, String, ByteArray?) -> HTTPAuthorizationEvent?,
|
||||||
context: Context,
|
context: Context,
|
||||||
) = uploadImage(
|
) = upload(
|
||||||
uri,
|
uri,
|
||||||
contentType,
|
contentType,
|
||||||
size,
|
size,
|
||||||
@@ -85,7 +85,7 @@ class Nip96Uploader {
|
|||||||
|
|
||||||
fun fileSize(uri: Uri) = runCatching { uri.toFile().length() }.getOrNull()
|
fun fileSize(uri: Uri) = runCatching { uri.toFile().length() }.getOrNull()
|
||||||
|
|
||||||
suspend fun uploadImage(
|
suspend fun upload(
|
||||||
uri: Uri,
|
uri: Uri,
|
||||||
contentType: String?,
|
contentType: String?,
|
||||||
size: Long?,
|
size: Long?,
|
||||||
@@ -107,7 +107,7 @@ class Nip96Uploader {
|
|||||||
|
|
||||||
checkNotNull(imageInputStream) { "Can't open the image input stream" }
|
checkNotNull(imageInputStream) { "Can't open the image input stream" }
|
||||||
|
|
||||||
return uploadImage(
|
return upload(
|
||||||
imageInputStream,
|
imageInputStream,
|
||||||
length,
|
length,
|
||||||
myContentType,
|
myContentType,
|
||||||
@@ -121,7 +121,7 @@ class Nip96Uploader {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun uploadImage(
|
suspend fun upload(
|
||||||
inputStream: InputStream,
|
inputStream: InputStream,
|
||||||
length: Long,
|
length: Long,
|
||||||
contentType: String?,
|
contentType: String?,
|
||||||
|
|||||||
+2
-2
@@ -177,7 +177,7 @@ class NewUserMetadataViewModel : ViewModel() {
|
|||||||
try {
|
try {
|
||||||
val result =
|
val result =
|
||||||
if (account.settings.defaultFileServer.type == ServerType.NIP96) {
|
if (account.settings.defaultFileServer.type == ServerType.NIP96) {
|
||||||
Nip96Uploader().uploadImage(
|
Nip96Uploader().upload(
|
||||||
uri = compResult.uri,
|
uri = compResult.uri,
|
||||||
contentType = compResult.contentType,
|
contentType = compResult.contentType,
|
||||||
size = compResult.size,
|
size = compResult.size,
|
||||||
@@ -190,7 +190,7 @@ class NewUserMetadataViewModel : ViewModel() {
|
|||||||
context = context,
|
context = context,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
BlossomUploader().uploadImage(
|
BlossomUploader().upload(
|
||||||
uri = compResult.uri,
|
uri = compResult.uri,
|
||||||
contentType = compResult.contentType,
|
contentType = compResult.contentType,
|
||||||
size = compResult.size,
|
size = compResult.size,
|
||||||
|
|||||||
Reference in New Issue
Block a user