feat: リモートのメディアを保存するように

This commit is contained in:
usbharu 2023-11-02 18:25:50 +09:00
parent 3c1b262d6f
commit 82974b5abe
2 changed files with 21 additions and 3 deletions

View File

@ -13,6 +13,8 @@ import dev.usbharu.hideout.core.domain.model.post.Post
import dev.usbharu.hideout.core.domain.model.post.PostRepository import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.post.Visibility import dev.usbharu.hideout.core.domain.model.post.Visibility
import dev.usbharu.hideout.core.query.PostQueryService import dev.usbharu.hideout.core.query.PostQueryService
import dev.usbharu.hideout.core.service.media.MediaService
import dev.usbharu.hideout.core.service.media.RemoteMedia
import dev.usbharu.hideout.core.service.post.PostService import dev.usbharu.hideout.core.service.post.PostService
import io.ktor.client.plugins.* import io.ktor.client.plugins.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -52,7 +54,8 @@ class APNoteServiceImpl(
private val postService: PostService, private val postService: PostService,
private val apResourceResolveService: APResourceResolveService, private val apResourceResolveService: APResourceResolveService,
private val postBuilder: Post.PostBuilder, private val postBuilder: Post.PostBuilder,
private val noteQueryService: NoteQueryService private val noteQueryService: NoteQueryService,
private val mediaService: MediaService
) : APNoteService { ) : APNoteService {
@ -123,6 +126,19 @@ class APNoteServiceImpl(
postQueryService.findByUrl(it) postQueryService.findByUrl(it)
} }
val mediaList = note.attachment
.filter { it.url != null }
.map {
mediaService.uploadRemoteMedia(
RemoteMedia(
(it.name ?: it.url)!!,
it.url!!, it.mediaType ?: "application/octet-stream"
)
)
}
.map { it.id }
// TODO: リモートのメディア処理を追加 // TODO: リモートのメディア処理を追加
postService.createRemote( postService.createRemote(
postBuilder.of( postBuilder.of(
@ -135,6 +151,7 @@ class APNoteServiceImpl(
replyId = reply?.id, replyId = reply?.id,
sensitive = note.sensitive, sensitive = note.sensitive,
apId = note.id ?: url, apId = note.id ?: url,
mediaIds = mediaList
) )
) )
return note return note

View File

@ -1,8 +1,9 @@
package dev.usbharu.hideout.core.service.media package dev.usbharu.hideout.core.service.media
import dev.usbharu.hideout.core.domain.model.media.Media
import dev.usbharu.hideout.mastodon.interfaces.api.media.MediaRequest import dev.usbharu.hideout.mastodon.interfaces.api.media.MediaRequest
interface MediaService { interface MediaService {
suspend fun uploadLocalMedia(mediaRequest: MediaRequest): dev.usbharu.hideout.core.domain.model.media.Media suspend fun uploadLocalMedia(mediaRequest: MediaRequest): Media
suspend fun uploadRemoteMedia(remoteMedia: RemoteMedia) suspend fun uploadRemoteMedia(remoteMedia: RemoteMedia): Media
} }