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