Fixes Satellite's blossom upload
This commit is contained in:
@@ -1508,12 +1508,13 @@ class Account(
|
|||||||
|
|
||||||
fun createBlossomUploadAuth(
|
fun createBlossomUploadAuth(
|
||||||
hash: HexKey,
|
hash: HexKey,
|
||||||
|
size: Long,
|
||||||
alt: String,
|
alt: String,
|
||||||
onReady: (BlossomAuthorizationEvent) -> Unit,
|
onReady: (BlossomAuthorizationEvent) -> Unit,
|
||||||
) {
|
) {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
|
|
||||||
BlossomAuthorizationEvent.createUploadAuth(hash, alt, signer, onReady = onReady)
|
BlossomAuthorizationEvent.createUploadAuth(hash, size, alt, signer, onReady = onReady)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createBlossomDeleteAuth(
|
fun createBlossomDeleteAuth(
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class BlossomUploader(
|
|||||||
): MediaUploadResult {
|
): MediaUploadResult {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|
||||||
val fileName = randomChars()
|
val fileName = fileName ?: randomChars()
|
||||||
val extension =
|
val extension =
|
||||||
contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
|
contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
|
||||||
|
|
||||||
@@ -145,6 +145,7 @@ class BlossomUploader(
|
|||||||
|
|
||||||
authUploadHeader(
|
authUploadHeader(
|
||||||
hash,
|
hash,
|
||||||
|
length.toLong(),
|
||||||
alt?.let { "Uploading $it" } ?: "Uploading $fileName",
|
alt?.let { "Uploading $it" } ?: "Uploading $fileName",
|
||||||
)?.let {
|
)?.let {
|
||||||
requestBuilder.addHeader("Authorization", it)
|
requestBuilder.addHeader("Authorization", it)
|
||||||
@@ -226,11 +227,12 @@ class BlossomUploader(
|
|||||||
|
|
||||||
suspend fun authUploadHeader(
|
suspend fun authUploadHeader(
|
||||||
hash: String,
|
hash: String,
|
||||||
|
size: Long,
|
||||||
alt: String,
|
alt: String,
|
||||||
): String? {
|
): String? {
|
||||||
val myAccount = account ?: return null
|
val myAccount = account ?: return null
|
||||||
return tryAndWait { continuation ->
|
return tryAndWait { continuation ->
|
||||||
myAccount.createBlossomUploadAuth(hash, alt) {
|
myAccount.createBlossomUploadAuth(hash, size, alt) {
|
||||||
val encodedNIP98Event = Base64.getEncoder().encodeToString(it.toJson().toByteArray())
|
val encodedNIP98Event = Base64.getEncoder().encodeToString(it.toJson().toByteArray())
|
||||||
continuation.resume("Nostr $encodedNIP98Event")
|
continuation.resume("Nostr $encodedNIP98Event")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,14 +43,14 @@ class BlossomAuthorizationEvent(
|
|||||||
signer: NostrSigner,
|
signer: NostrSigner,
|
||||||
createdAt: Long = TimeUtils.now(),
|
createdAt: Long = TimeUtils.now(),
|
||||||
onReady: (BlossomAuthorizationEvent) -> Unit,
|
onReady: (BlossomAuthorizationEvent) -> Unit,
|
||||||
) = createAuth("get", hash, alt, signer, createdAt, onReady)
|
) = createAuth("get", hash, null, alt, signer, createdAt, onReady)
|
||||||
|
|
||||||
fun createListAuth(
|
fun createListAuth(
|
||||||
signer: NostrSigner,
|
signer: NostrSigner,
|
||||||
alt: String,
|
alt: String,
|
||||||
createdAt: Long = TimeUtils.now(),
|
createdAt: Long = TimeUtils.now(),
|
||||||
onReady: (BlossomAuthorizationEvent) -> Unit,
|
onReady: (BlossomAuthorizationEvent) -> Unit,
|
||||||
) = createAuth("list", null, alt, signer, createdAt, onReady)
|
) = createAuth("list", null, null, alt, signer, createdAt, onReady)
|
||||||
|
|
||||||
fun createDeleteAuth(
|
fun createDeleteAuth(
|
||||||
hash: HexKey,
|
hash: HexKey,
|
||||||
@@ -58,19 +58,21 @@ class BlossomAuthorizationEvent(
|
|||||||
signer: NostrSigner,
|
signer: NostrSigner,
|
||||||
createdAt: Long = TimeUtils.now(),
|
createdAt: Long = TimeUtils.now(),
|
||||||
onReady: (BlossomAuthorizationEvent) -> Unit,
|
onReady: (BlossomAuthorizationEvent) -> Unit,
|
||||||
) = createAuth("delete", hash, alt, signer, createdAt, onReady)
|
) = createAuth("delete", hash, null, alt, signer, createdAt, onReady)
|
||||||
|
|
||||||
fun createUploadAuth(
|
fun createUploadAuth(
|
||||||
hash: HexKey,
|
hash: HexKey,
|
||||||
|
size: Long,
|
||||||
alt: String,
|
alt: String,
|
||||||
signer: NostrSigner,
|
signer: NostrSigner,
|
||||||
createdAt: Long = TimeUtils.now(),
|
createdAt: Long = TimeUtils.now(),
|
||||||
onReady: (BlossomAuthorizationEvent) -> Unit,
|
onReady: (BlossomAuthorizationEvent) -> Unit,
|
||||||
) = createAuth("upload", hash, alt, signer, createdAt, onReady)
|
) = createAuth("upload", hash, size, alt, signer, createdAt, onReady)
|
||||||
|
|
||||||
private fun createAuth(
|
private fun createAuth(
|
||||||
type: String,
|
type: String,
|
||||||
hash: HexKey?,
|
hash: HexKey?,
|
||||||
|
fileSize: Long?,
|
||||||
alt: String,
|
alt: String,
|
||||||
signer: NostrSigner,
|
signer: NostrSigner,
|
||||||
createdAt: Long = TimeUtils.now(),
|
createdAt: Long = TimeUtils.now(),
|
||||||
@@ -80,6 +82,7 @@ class BlossomAuthorizationEvent(
|
|||||||
listOfNotNull(
|
listOfNotNull(
|
||||||
arrayOf("t", type),
|
arrayOf("t", type),
|
||||||
arrayOf("expiration", TimeUtils.oneHourAhead().toString()),
|
arrayOf("expiration", TimeUtils.oneHourAhead().toString()),
|
||||||
|
fileSize?.let { arrayOf("size", it.toString()) },
|
||||||
hash?.let { arrayOf("x", it) },
|
hash?.let { arrayOf("x", it) },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user