use POST api/v2/media to upload media (#2327)

This commit is contained in:
Konrad Pozniak 2022-02-25 18:57:18 +01:00 committed by GitHub
parent 8dbf255617
commit eea81d7106
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 7 deletions

View File

@ -185,7 +185,7 @@ class ComposeViewModel @Inject constructor(
is UploadEvent.ProgressEvent ->
item.copy(uploadPercent = event.percentage)
is UploadEvent.FinishedEvent ->
item.copy(id = event.attachment.id, uploadPercent = -1)
item.copy(id = event.mediaId, uploadPercent = -1)
}
synchronized(media) {
val mediaValue = media.value!!

View File

@ -25,7 +25,6 @@ import androidx.core.net.toUri
import com.keylesspalace.tusky.BuildConfig
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.components.compose.ComposeActivity.QueuedMedia
import com.keylesspalace.tusky.entity.Attachment
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.network.ProgressRequestBody
import com.keylesspalace.tusky.util.MEDIA_SIZE_UNKNOWN
@ -45,7 +44,7 @@ import javax.inject.Inject
sealed class UploadEvent {
data class ProgressEvent(val percentage: Int) : UploadEvent()
data class FinishedEvent(val attachment: Attachment) : UploadEvent()
data class FinishedEvent(val mediaId: String) : UploadEvent()
}
fun createNewImageFile(context: Context): File {
@ -183,8 +182,8 @@ class MediaUploader @Inject constructor(
val uploadDisposable = mastodonApi.uploadMedia(body, description)
.subscribe(
{ attachment ->
emitter.onNext(UploadEvent.FinishedEvent(attachment))
{ result ->
emitter.onNext(UploadEvent.FinishedEvent(result.id))
emitter.onComplete()
},
{ e ->

View File

@ -0,0 +1,9 @@
package com.keylesspalace.tusky.entity
/**
* The same as Attachment, except the url is null - see https://docs.joinmastodon.org/methods/statuses/media/
* We are only interested in the id, so other attributes are omitted
*/
data class MediaUploadResult(
val id: String
)

View File

@ -28,6 +28,7 @@ import com.keylesspalace.tusky.entity.IdentityProof
import com.keylesspalace.tusky.entity.Instance
import com.keylesspalace.tusky.entity.Marker
import com.keylesspalace.tusky.entity.MastoList
import com.keylesspalace.tusky.entity.MediaUploadResult
import com.keylesspalace.tusky.entity.NewStatus
import com.keylesspalace.tusky.entity.Notification
import com.keylesspalace.tusky.entity.Poll
@ -142,11 +143,11 @@ interface MastodonApi {
fun clearNotifications(): Single<ResponseBody>
@Multipart
@POST("api/v1/media")
@POST("api/v2/media")
fun uploadMedia(
@Part file: MultipartBody.Part,
@Part description: MultipartBody.Part? = null
): Single<Attachment>
): Single<MediaUploadResult>
@FormUrlEncoded
@PUT("api/v1/media/{mediaId}")