From 7e8d0661447355dff29bb7189e3ed01e5c85e052 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 23 Aug 2024 22:22:16 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20Actor=E3=81=AEurl=E3=81=8Coutbox?= =?UTF-8?q?=E3=81=AEurl=E3=81=A8=E3=81=AA=E3=81=A3=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=9F=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/exposedrepository/ExposedActorRepository.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt index 0eb7047c..8de778e1 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt @@ -32,7 +32,7 @@ class ExposedActorRepository( it[description] = actor.description.description it[inbox] = actor.inbox.toString() it[outbox] = actor.outbox.toString() - it[url] = actor.outbox.toString() + it[url] = actor.url.toString() it[publicKey] = actor.publicKey.publicKey it[privateKey] = actor.privateKey?.privateKey it[createdAt] = actor.createdAt From e15380c96cc68e7b4e865cb7055b7ea815081b01 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 23 Aug 2024 22:43:11 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20Media=E3=81=AB=E3=82=AA=E3=83=BC?= =?UTF-8?q?=E3=83=8A=E3=83=BC=E3=81=AEActorId=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../media/UploadMediaApplicationService.kt | 3 +- .../core/application/post/MediaDetail.kt | 18 +++++---- .../hideout/core/domain/model/media/Media.kt | 40 ++++++++++++++----- .../exposedrepository/MediaRepositoryImpl.kt | 7 +++- .../exposedquery/ExposedStatusQueryService.kt | 7 +++- 5 files changed, 53 insertions(+), 22 deletions(-) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt index c3b3379a..8f796c7f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt @@ -58,7 +58,8 @@ class UploadMediaApplicationService( type = process.fileType, mimeType = process.mimeType, blurHash = process.blurHash?.let { MediaBlurHash(it) }, - description = command.description?.let { MediaDescription(it) } + description = command.description?.let { MediaDescription(it) }, + actorId = principal.actorId ) mediaRepository.save(media) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/MediaDetail.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/MediaDetail.kt index 3b99d0d7..e29dac77 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/MediaDetail.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/MediaDetail.kt @@ -10,18 +10,20 @@ data class MediaDetail( val thumbnailUrl: URI?, val sensitive: Boolean, val description: String, - val blurhash: String + val blurhash: String, + val actorId: Long ) { companion object { fun of(media: Media): MediaDetail { return MediaDetail( - media.id.id, - media.type.name, - media.url, - media.thumbnailUrl, - false, - media.description?.description.orEmpty(), - media.blurHash?.hash.orEmpty() + mediaId = media.id.id, + type = media.type.name, + url = media.url, + thumbnailUrl = media.thumbnailUrl, + sensitive = false, + description = media.description?.description.orEmpty(), + blurhash = media.blurHash?.hash.orEmpty(), + actorId = media.actorId.id ) } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt index 44c75088..c2d76b56 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt @@ -16,6 +16,7 @@ package dev.usbharu.hideout.core.domain.model.media +import dev.usbharu.hideout.core.domain.model.actor.ActorId import java.net.URI class Media( @@ -28,6 +29,7 @@ class Media( val mimeType: MimeType, val blurHash: MediaBlurHash?, val description: MediaDescription? = null, + val actorId: ActorId, ) { var url = url private set @@ -35,17 +37,35 @@ class Media( fun setUrl(url: URI) { this.url = url } + + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Media + + return id == other.id + } + + override fun hashCode(): Int { + return id.hashCode() + } + override fun toString(): String { return "Media(" + - "id=$id, " + - "name=$name, " + - "url=$url, " + - "remoteUrl=$remoteUrl, " + - "thumbnailUrl=$thumbnailUrl, " + - "type=$type, " + - "mimeType=$mimeType, " + - "blurHash=$blurHash, " + - "description=$description" + - ")" + "id=$id, " + + "name=$name, " + + "remoteUrl=$remoteUrl, " + + "thumbnailUrl=$thumbnailUrl, " + + "type=$type, " + + "mimeType=$mimeType, " + + "blurHash=$blurHash, " + + "description=$description, " + + "actorId=$actorId, " + + "url=$url" + + ")" } + + } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt index a6ac6b26..d5bd5f2a 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt @@ -16,6 +16,7 @@ package dev.usbharu.hideout.core.infrastructure.exposedrepository +import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.media.* import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq @@ -66,6 +67,7 @@ class MediaRepositoryImpl : MediaRepository, AbstractRepository() { it[blurhash] = media.blurHash?.hash it[mimeType] = media.mimeType.type + "/" + media.mimeType.subtype it[description] = media.description?.description + it[actorId] = media.actorId.id } } else { Media.insert { @@ -78,6 +80,7 @@ class MediaRepositoryImpl : MediaRepository, AbstractRepository() { it[blurhash] = media.blurHash?.hash it[mimeType] = media.mimeType.type + "/" + media.mimeType.subtype it[description] = media.description?.description + it[actorId] = media.actorId.id } } return@query media @@ -100,7 +103,8 @@ fun ResultRow.toMedia(): EntityMedia { type = fileType, blurHash = this[Media.blurhash]?.let { MediaBlurHash(it) }, mimeType = MimeType(mimeType.substringBefore("/"), mimeType.substringAfter("/"), fileType), - description = this[Media.description]?.let { MediaDescription(it) } + description = this[Media.description]?.let { MediaDescription(it) }, + actorId = ActorId(this[Media.actorId]) ) } @@ -114,5 +118,6 @@ object Media : Table("media") { val blurhash = varchar("blurhash", 255).nullable() val mimeType = varchar("mime_type", 255) val description = varchar("description", 4000).nullable() + val actorId = long("actor_id").references(Actors.id) override val primaryKey = PrimaryKey(id) } diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedStatusQueryService.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedStatusQueryService.kt index 8208256d..f22a0ae0 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedStatusQueryService.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedStatusQueryService.kt @@ -16,6 +16,7 @@ package dev.usbharu.hideout.mastodon.infrastructure.exposedquery +import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.emoji.CustomEmoji import dev.usbharu.hideout.core.domain.model.media.* import dev.usbharu.hideout.core.domain.model.post.Visibility @@ -284,7 +285,8 @@ fun ResultRow.toMedia(): EntityMedia { type = fileType, blurHash = this[Media.blurhash]?.let { MediaBlurHash(it) }, mimeType = MimeType(mimeType.substringBefore("/"), mimeType.substringAfter("/"), fileType), - description = this[Media.description]?.let { MediaDescription(it) } + description = this[Media.description]?.let { MediaDescription(it) }, + actorId = ActorId(this[Media.actorId]) ) } @@ -300,7 +302,8 @@ fun ResultRow.toMediaOrNull(): EntityMedia? { type = FileType.valueOf(this[Media.type]), blurHash = this[Media.blurhash]?.let { MediaBlurHash(it) }, mimeType = MimeType(mimeType.substringBefore("/"), mimeType.substringAfter("/"), fileType), - description = this[Media.description]?.let { MediaDescription(it) } + description = this[Media.description]?.let { MediaDescription(it) }, + actorId = ActorId(this[Media.actorId]) ) } From 76abc69c6c2e24eafa2766f0e1d2d66ddce771b3 Mon Sep 17 00:00:00 2001 From: usbharu Date: Fri, 23 Aug 2024 13:49:15 +0000 Subject: [PATCH 3/3] style: fix lint (CI) --- .../hideout/core/domain/model/media/Media.kt | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt index c2d76b56..45487174 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt @@ -38,7 +38,6 @@ class Media( this.url = url } - override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false @@ -54,18 +53,16 @@ class Media( override fun toString(): String { return "Media(" + - "id=$id, " + - "name=$name, " + - "remoteUrl=$remoteUrl, " + - "thumbnailUrl=$thumbnailUrl, " + - "type=$type, " + - "mimeType=$mimeType, " + - "blurHash=$blurHash, " + - "description=$description, " + - "actorId=$actorId, " + - "url=$url" + - ")" + "id=$id, " + + "name=$name, " + + "remoteUrl=$remoteUrl, " + + "thumbnailUrl=$thumbnailUrl, " + + "type=$type, " + + "mimeType=$mimeType, " + + "blurHash=$blurHash, " + + "description=$description, " + + "actorId=$actorId, " + + "url=$url" + + ")" } - - }