From 82974b5abeb827b78906a7fafc8a10a9b5ba10c7 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:25:50 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=AA=E3=83=A2=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=81=AE=E3=83=A1=E3=83=87=E3=82=A3=E3=82=A2=E3=82=92=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/objects/note/APNoteService.kt | 19 ++++++++++++++++++- .../core/service/media/MediaService.kt | 5 +++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt index c221e9fb..dd2ec6ae 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt @@ -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.Visibility 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 io.ktor.client.plugins.* import kotlinx.coroutines.CoroutineScope @@ -52,7 +54,8 @@ class APNoteServiceImpl( private val postService: PostService, private val apResourceResolveService: APResourceResolveService, private val postBuilder: Post.PostBuilder, - private val noteQueryService: NoteQueryService + private val noteQueryService: NoteQueryService, + private val mediaService: MediaService ) : APNoteService { @@ -123,6 +126,19 @@ class APNoteServiceImpl( 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: リモートのメディア処理を追加 postService.createRemote( postBuilder.of( @@ -135,6 +151,7 @@ class APNoteServiceImpl( replyId = reply?.id, sensitive = note.sensitive, apId = note.id ?: url, + mediaIds = mediaList ) ) return note diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaService.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaService.kt index 75d928e8..b85c497a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaService.kt @@ -1,8 +1,9 @@ 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 interface MediaService { - suspend fun uploadLocalMedia(mediaRequest: MediaRequest): dev.usbharu.hideout.core.domain.model.media.Media - suspend fun uploadRemoteMedia(remoteMedia: RemoteMedia) + suspend fun uploadLocalMedia(mediaRequest: MediaRequest): Media + suspend fun uploadRemoteMedia(remoteMedia: RemoteMedia): Media }