diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt index 31c4b47e..144759d3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.activitypub.domain.exception +import java.io.Serial + class FailedProcessException : RuntimeException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ class FailedProcessException : RuntimeException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -1305337651143409144L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedToGetActivityPubResourceException.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedToGetActivityPubResourceException.kt index e050e716..ed967555 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedToGetActivityPubResourceException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedToGetActivityPubResourceException.kt @@ -1,10 +1,16 @@ package dev.usbharu.hideout.activitypub.domain.exception import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException +import java.io.Serial class FailedToGetActivityPubResourceException : FailedToGetResourcesException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = 6420233106776818052L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/HttpSignatureUnauthorizedException.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/HttpSignatureUnauthorizedException.kt index 9abccec6..3bba00ef 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/HttpSignatureUnauthorizedException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/HttpSignatureUnauthorizedException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.activitypub.domain.exception +import java.io.Serial + class HttpSignatureUnauthorizedException : RuntimeException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ class HttpSignatureUnauthorizedException : RuntimeException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -6449793151674654501L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt index a9b3e8c9..d8b7ff7e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt @@ -28,8 +28,8 @@ open class Document( override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (mediaType?.hashCode() ?: 0) - result = 31 * result + (url?.hashCode() ?: 0) + result = 31 * result + mediaType.hashCode() + result = 31 * result + url.hashCode() result = 31 * result + name.hashCode() return result } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt index d46edc8a..37ebb879 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt @@ -25,8 +25,8 @@ open class Emoji( override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (updated?.hashCode() ?: 0) - result = 31 * result + (icon?.hashCode() ?: 0) + result = 31 * result + updated.hashCode() + result = 31 * result + icon.hashCode() return result } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt index 2689ccb5..d4ef2c95 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt @@ -26,7 +26,7 @@ open class Follow( override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (`object`?.hashCode() ?: 0) + result = 31 * result + `object`.hashCode() result = 31 * result + actor.hashCode() return result } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt index 6353692b..5b63ef5e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt @@ -25,8 +25,8 @@ open class Image( override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (mediaType?.hashCode() ?: 0) - result = 31 * result + (url?.hashCode() ?: 0) + result = 31 * result + mediaType.hashCode() + result = 31 * result + url.hashCode() return result } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt index 4a13ba56..7e22097c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt @@ -28,8 +28,8 @@ open class Key( override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (owner?.hashCode() ?: 0) - result = 31 * result + (publicKeyPem?.hashCode() ?: 0) + result = 31 * result + owner.hashCode() + result = 31 * result + publicKeyPem.hashCode() result = 31 * result + id.hashCode() return result } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt index 889c8776..91bf8a86 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt @@ -54,6 +54,18 @@ constructor( return result } - override fun toString(): String = - "Note(id='$id', attributedTo='$attributedTo', content='$content', published='$published', to=$to, cc=$cc, sensitive=$sensitive, inReplyTo=$inReplyTo, attachment=$attachment) ${super.toString()}" + override fun toString(): String { + return "Note(" + + "id='$id', " + + "attributedTo='$attributedTo', " + + "content='$content', " + + "published='$published', " + + "to=$to, " + + "cc=$cc, " + + "sensitive=$sensitive, " + + "inReplyTo=$inReplyTo, " + + "attachment=$attachment" + + ")" + + " ${super.toString()}" + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt index 58165a81..fe1b2d5f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt @@ -41,9 +41,9 @@ constructor( var result = super.hashCode() result = 31 * result + (preferredUsername?.hashCode() ?: 0) result = 31 * result + (summary?.hashCode() ?: 0) - result = 31 * result + (inbox?.hashCode() ?: 0) - result = 31 * result + (outbox?.hashCode() ?: 0) - result = 31 * result + (url?.hashCode() ?: 0) + result = 31 * result + inbox.hashCode() + result = 31 * result + outbox.hashCode() + result = 31 * result + url.hashCode() result = 31 * result + (icon?.hashCode() ?: 0) result = 31 * result + (publicKey?.hashCode() ?: 0) result = 31 * result + endpoints.hashCode() diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt index 6060531f..0567bf5f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt @@ -12,7 +12,7 @@ import dev.usbharu.hideout.core.query.UserQueryService import dev.usbharu.hideout.core.service.user.UserService class ApAcceptProcessor( - private val transaction: Transaction, + transaction: Transaction, private val userQueryService: UserQueryService, private val followerQueryService: FollowerQueryService, private val userService: UserService @@ -23,14 +23,14 @@ class ApAcceptProcessor( val value = activity.activity.`object` ?: throw IllegalActivityPubObjectException("object is null") if (value.type.contains("Follow").not()) { - logger.warn("FAILED Activity type is not Follow.") + logger.warn("FAILED Activity type isn't Follow.") throw IllegalActivityPubObjectException("Invalid type ${value.type}") } val follow = value as Follow - val userUrl = follow.`object` ?: throw IllegalActivityPubObjectException("object is null") - val followerUrl = follow.actor ?: throw IllegalActivityPubObjectException("actor is null") + val userUrl = follow.`object` + val followerUrl = follow.actor val user = userQueryService.findByUrl(userUrl) val follower = userQueryService.findByUrl(followerUrl) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt index 5d057b3f..2e1b557c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt @@ -11,7 +11,7 @@ import org.springframework.stereotype.Service @Service class CreateActivityProcessor(transaction: Transaction, private val apNoteService: APNoteService) : - AbstractActivityPubProcessor(transaction, false) { + AbstractActivityPubProcessor(transaction) { override suspend fun internalProcess(activity: ActivityPubProcessContext) { apNoteService.fetchNote(activity.activity.`object` as Note) } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt index 92ad3e28..b56cd49f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt @@ -1,7 +1,6 @@ package dev.usbharu.hideout.activitypub.service.activity.follow import com.fasterxml.jackson.databind.ObjectMapper -import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException import dev.usbharu.hideout.activitypub.domain.model.Follow import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext @@ -22,9 +21,9 @@ class APFollowProcessor( // inboxをジョブキューに乗せているので既に不要だが、フォロー承認制アカウントを実装する際に必要なので残す val jobProps = ReceiveFollowJobParam( - activity.activity.actor ?: throw IllegalActivityPubObjectException("actor is null"), + activity.activity.actor, objectMapper.writeValueAsString(activity.activity), - activity.activity.`object` ?: throw IllegalActivityPubObjectException("object is null") + activity.activity.`object` ) jobQueueParentService.scheduleTypeSafe(ReceiveFollowJob, jobProps) } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt index a6aae23b..f8cf8556 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt @@ -33,7 +33,7 @@ class APReceiveFollowJobProcessor( val signer = userQueryService.findByUrl(param.targetActor) - val urlString = person.inbox ?: throw IllegalArgumentException("inbox is not found.") + val urlString = person.inbox apRequestService.apPost( url = urlString, @@ -47,7 +47,7 @@ class APReceiveFollowJobProcessor( val targetEntity = userQueryService.findByUrl(param.targetActor) val followActorEntity = - userQueryService.findByUrl(follow.actor ?: throw IllegalArgumentException("actor is null")) + userQueryService.findByUrl(follow.actor) userService.followRequest(targetEntity.id, followActorEntity.id) logger.info("SUCCESS Follow from: {} to: {}", param.targetActor, param.actor) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt index 470eaee7..9d56fe94 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt @@ -1,7 +1,6 @@ package dev.usbharu.hideout.activitypub.service.activity.like import dev.usbharu.hideout.activitypub.domain.exception.FailedToGetActivityPubResourceException -import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException import dev.usbharu.hideout.activitypub.domain.model.Like import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext @@ -21,10 +20,10 @@ class APLikeProcessor( ) : AbstractActivityPubProcessor(transaction) { override suspend fun internalProcess(activity: ActivityPubProcessContext) { - val actor = activity.activity.actor ?: throw IllegalActivityPubObjectException("actor is null") - val content = activity.activity.content ?: throw IllegalActivityPubObjectException("content is null") + val actor = activity.activity.actor + val content = activity.activity.content - val target = activity.activity.`object` ?: throw IllegalActivityPubObjectException("object is null") + val target = activity.activity.`object` val personWithEntity = apUserService.fetchPersonWithEntity(actor) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt index 8c09b54f..99bd9ba1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt @@ -24,7 +24,7 @@ class APUndoProcessor( } val type = - undo.`object`?.type.orEmpty() + undo.`object`.type.orEmpty() .firstOrNull { it == "Block" || it == "Follow" || it == "Like" || it == "Announce" || it == "Accept" } ?: return @@ -35,9 +35,9 @@ class APUndoProcessor( if (follow.`object` == null) { return } - apUserService.fetchPerson(undo.actor!!, follow.`object`) - val follower = userQueryService.findByUrl(undo.actor!!) - val target = userQueryService.findByUrl(follow.`object`!!) + apUserService.fetchPerson(undo.actor, follow.`object`) + val follower = userQueryService.findByUrl(undo.actor) + val target = userQueryService.findByUrl(follow.`object`) userService.unfollow(target.id, follower.id) return } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImpl.kt index bf13b1ca..511d3e67 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImpl.kt @@ -61,7 +61,7 @@ class APRequestServiceImpl( url: String ): HttpResponse { val headers = headers { - append("Accept", ContentType.Application.Activity) + append("Accept", Activity) append("Date", date) append("Host", u.host) } @@ -87,13 +87,13 @@ class APRequestServiceImpl( remove("Host") } } - contentType(ContentType.Application.Activity) + contentType(Activity) } return httpResponse } private suspend fun apGetNotSign(url: String, date: String?) = httpClient.get(url) { - header("Accept", ContentType.Application.Activity) + header("Accept", Activity) header("Date", date) } @@ -153,12 +153,12 @@ class APRequestServiceImpl( digest: String, requestBody: String? ) = httpClient.post(url) { - accept(ContentType.Application.Activity) + accept(Activity) header("Date", date) header("Digest", "sha-256=$digest") if (requestBody != null) { setBody(requestBody) - contentType(ContentType.Application.Activity) + contentType(Activity) } } @@ -170,7 +170,7 @@ class APRequestServiceImpl( requestBody: String? ): HttpResponse { val headers = headers { - append("Accept", ContentType.Application.Activity) + append("Accept", Activity) append("Date", date) append("Host", u.host) append("Digest", "sha-256=$digest") @@ -196,7 +196,7 @@ class APRequestServiceImpl( remove("Host") } setBody(requestBody) - contentType(ContentType.Application.Activity) + contentType(Activity) } return httpResponse } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt index 329941b2..1bb106e3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt @@ -5,13 +5,14 @@ import dev.usbharu.hideout.activitypub.domain.exception.FailedProcessException import dev.usbharu.hideout.activitypub.domain.exception.HttpSignatureUnauthorizedException import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.application.external.Transaction +import org.slf4j.Logger import org.slf4j.LoggerFactory abstract class AbstractActivityPubProcessor( private val transaction: Transaction, private val allowUnauthorized: Boolean = false ) : ActivityPubProcessor { - protected val logger = LoggerFactory.getLogger(this::class.java) + protected val logger: Logger = LoggerFactory.getLogger(this::class.java) override suspend fun process(activity: ActivityPubProcessContext) { if (activity.isAuthorized.not() && allowUnauthorized.not()) { 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 28bf7c01..0e5b6e14 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 @@ -90,7 +90,7 @@ class APNoteServiceImpl( requireNotNull(note.id) { "id is null" } return try { - noteQueryService.findByApid(note.id!!).first + noteQueryService.findByApid(note.id).first } catch (_: FailedToGetResourcesException) { saveNote(note, targetActor, url) } @@ -127,9 +127,9 @@ class APNoteServiceImpl( .map { mediaService.uploadRemoteMedia( RemoteMedia( - (it.name ?: it.url)!!, - it.url!!, - it.mediaType ?: "application/octet-stream", + it.name, + it.url, + it.mediaType, description = it.name ) ) @@ -144,10 +144,10 @@ class APNoteServiceImpl( text = note.content, createdAt = Instant.parse(note.published).toEpochMilli(), visibility = visibility, - url = note.id ?: url, + url = note.id, replyId = reply?.id, sensitive = note.sensitive, - apId = note.id ?: url, + apId = note.id, mediaIds = mediaList ) ) @@ -155,7 +155,7 @@ class APNoteServiceImpl( } override suspend fun fetchNote(note: Note, targetActor: String?): Note = - saveIfMissing(note, targetActor, note.id ?: throw IllegalArgumentException("note.id is null")) + saveIfMissing(note, targetActor, note.id) companion object { const val public: String = "https://www.w3.org/ns/activitystreams#Public" diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt index 31a2b505..143df20b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt @@ -83,7 +83,7 @@ class APUserServiceImpl( } catch (ignore: FailedToGetResourcesException) { val person = apResourceResolveService.resolve(url, null as Long?) - val id = person.id ?: throw IllegalActivityPubObjectException("id is null") + val id = person.id try { val userEntity = userQueryService.findByUrl(id) return entityToPerson(userEntity, id) to userEntity @@ -94,11 +94,11 @@ class APUserServiceImpl( name = person.preferredUsername ?: throw IllegalActivityPubObjectException("preferredUsername is null"), domain = id.substringAfter("://").substringBefore("/"), - screenName = (person.name ?: person.preferredUsername) + screenName = person.name ?: throw IllegalActivityPubObjectException("preferredUsername is null"), description = person.summary.orEmpty(), - inbox = person.inbox ?: throw IllegalActivityPubObjectException("inbox is null"), - outbox = person.outbox ?: throw IllegalActivityPubObjectException("outbox is null"), + inbox = person.inbox, + outbox = person.outbox, url = id, publicKey = person.publicKey?.publicKeyPem ?: throw IllegalActivityPubObjectException("publicKey is null"), diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaConvertException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaConvertException.kt index d2d9d7c9..cc564619 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaConvertException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaConvertException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + open class MediaConvertException : MediaException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ open class MediaConvertException : MediaException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -6349105549968160551L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt index 538e3c72..221c92e5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + abstract class MediaException : RuntimeException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ abstract class MediaException : RuntimeException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = 5988922562494187852L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeException.kt index f75b74c2..f5153641 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + open class MediaFileSizeException : MediaException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ open class MediaFileSizeException : MediaException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = 8672626879026555064L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeIsZeroException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeIsZeroException.kt index 74261698..1837ce06 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeIsZeroException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeIsZeroException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + class MediaFileSizeIsZeroException : MediaFileSizeException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ class MediaFileSizeIsZeroException : MediaFileSizeException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -2398394583775317875L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaProcessException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaProcessException.kt index 4292d0e8..6751fec1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaProcessException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaProcessException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + class MediaProcessException : MediaException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ class MediaProcessException : MediaException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -5195233013542703735L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/UnsupportedMediaException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/UnsupportedMediaException.kt index 7eea4e38..6c62f904 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/UnsupportedMediaException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/UnsupportedMediaException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + class UnsupportedMediaException : MediaException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ class UnsupportedMediaException : MediaException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -116741513216017134L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt index 427c76a3..f7fc3160 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt @@ -1,15 +1,11 @@ package dev.usbharu.hideout.core.domain.model.instance -class Nodeinfo { +class Nodeinfo private constructor() { var links: List = emptyList() - - private constructor() } -class Links { +class Links private constructor() { var rel: String? = null var href: String? = null - - private constructor() } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt index 53479eee..98247150 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt @@ -3,23 +3,17 @@ package dev.usbharu.hideout.core.domain.model.instance @Suppress("ClassNaming") -class Nodeinfo2_0 { +class Nodeinfo2_0() { var metadata: Metadata? = null var software: Software? = null - - constructor() } -class Metadata { +class Metadata() { var nodeName: String? = null var nodeDescription: String? = null - - constructor() } -class Software { +class Software() { var name: String? = null var version: String? = null - - constructor() } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt index a7d8aa9b..883a5b48 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt @@ -54,7 +54,7 @@ class InstanceRepositoryImpl(private val idGenerateService: IdGenerateService) : } override suspend fun delete(instance: InstanceEntity) { - Instance.deleteWhere { Instance.id eq instance.id } + Instance.deleteWhere { id eq instance.id } } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt index 580c4029..34e72833 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt @@ -62,7 +62,7 @@ class ExposedOAuth2AuthorizationService( it[accessTokenMetadata] = accessToken?.metadata?.let { it1 -> mapToJson(it1) } it[accessTokenType] = accessToken?.token?.tokenType?.value it[accessTokenScopes] = - accessToken?.run { token.scopes.joinToString(",").takeIf { it.isNotEmpty() } } + accessToken?.run { token.scopes.joinToString(",").takeIf { s -> s.isNotEmpty() } } it[refreshTokenValue] = refreshToken?.token?.tokenValue it[refreshTokenIssuedAt] = refreshToken?.token?.issuedAt it[refreshTokenExpiresAt] = refreshToken?.token?.expiresAt diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt index 41459964..2c773ce0 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt @@ -53,7 +53,7 @@ class InstanceServiceImpl( name = nodeinfo20.metadata?.nodeName, description = nodeinfo20.metadata?.nodeDescription, url = resolveInstanceUrl, - iconUrl = resolveInstanceUrl + "/favicon.ico", + iconUrl = "$resolveInstanceUrl/favicon.ico", sharedInbox = sharedInbox, software = nodeinfo20.software?.name, version = nodeinfo20.software?.version @@ -72,7 +72,7 @@ class InstanceServiceImpl( name = nodeinfo20.metadata?.nodeName, description = nodeinfo20.metadata?.nodeDescription, url = resolveInstanceUrl, - iconUrl = resolveInstanceUrl + "/favicon.ico", + iconUrl = "$resolveInstanceUrl/favicon.ico", sharedInbox = sharedInbox, software = nodeinfo20.software?.name, version = nodeinfo20.software?.version diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt index 3529ace9..9fbae73a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt @@ -5,4 +5,29 @@ data class MediaSave( val prefix: String, val fileInputStream: ByteArray, val thumbnailInputStream: ByteArray? -) +) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as MediaSave + + if (name != other.name) return false + if (prefix != other.prefix) return false + if (!fileInputStream.contentEquals(other.fileInputStream)) return false + if (thumbnailInputStream != null) { + if (other.thumbnailInputStream == null) return false + if (!thumbnailInputStream.contentEquals(other.thumbnailInputStream)) return false + } else if (other.thumbnailInputStream != null) return false + + return true + } + + override fun hashCode(): Int { + var result = name.hashCode() + result = 31 * result + prefix.hashCode() + result = 31 * result + fileInputStream.contentHashCode() + result = 31 * result + (thumbnailInputStream?.contentHashCode() ?: 0) + return result + } +} diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt index ff8f1d93..5337e53a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt @@ -15,7 +15,7 @@ import dev.usbharu.hideout.core.domain.model.media.Media as EntityMedia @Service @Suppress("TooGenericExceptionCaught") -open class MediaServiceImpl( +class MediaServiceImpl( private val mediaDataStore: MediaDataStore, private val fileTypeDeterminationService: FileTypeDeterminationService, private val mediaBlurhashService: MediaBlurhashService, diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt index c138ed43..b3589cee 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt @@ -3,4 +3,22 @@ package dev.usbharu.hideout.core.service.media data class ProcessedFile( val byteArray: ByteArray, val extension: String -) +) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as ProcessedFile + + if (!byteArray.contentEquals(other.byteArray)) return false + if (extension != other.extension) return false + + return true + } + + override fun hashCode(): Int { + var result = byteArray.contentHashCode() + result = 31 * result + extension.hashCode() + return result + } +} diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt index 056e5249..1ab87448 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt @@ -6,6 +6,7 @@ import dev.usbharu.hideout.core.domain.model.reaction.Reaction import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository import dev.usbharu.hideout.core.query.ReactionQueryService import org.jetbrains.exposed.exceptions.ExposedSQLException +import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -50,6 +51,6 @@ class ReactionServiceImpl( } companion object { - val LOGGER = LoggerFactory.getLogger(ReactionServiceImpl::class.java) + val LOGGER: Logger = LoggerFactory.getLogger(ReactionServiceImpl::class.java) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt index b48fadd7..587829c9 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt @@ -18,7 +18,7 @@ class InMemoryCacheManager : CacheManager { keyMutex.withLock { cacheKey.filter { Instant.ofEpochMilli(it.value).plusSeconds(300) <= Instant.now() } - val cached = cacheKey.get(key) + val cached = cacheKey[key] if (cached == null) { needRunBlock = true cacheKey[key] = Instant.now().toEpochMilli() diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt index 4bf358b7..fa1c0f97 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt @@ -52,8 +52,7 @@ class UserServiceImpl( createdAt = Instant.now(), following = "$userUrl/following", followers = "$userUrl/followers", - keyId = "$userUrl#pubkey", - instance = null + keyId = "$userUrl#pubkey" ) return userRepository.save(userEntity) } diff --git a/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt index a4222880..f784a4d2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.generate +import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.core.MethodParameter import org.springframework.web.bind.support.WebDataBinderFactory @@ -49,6 +50,6 @@ class JsonOrFormModelMethodProcessor( } companion object { - val logger = LoggerFactory.getLogger(JsonOrFormModelMethodProcessor::class.java) + val logger: Logger = LoggerFactory.getLogger(JsonOrFormModelMethodProcessor::class.java) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt index 5d113667..8010405d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt @@ -11,6 +11,7 @@ import org.jetbrains.exposed.sql.select import org.springframework.stereotype.Repository import java.time.Instant +@Suppress("IncompleteDestructuring") @Repository class StatusQueryServiceImpl : StatusQueryService { override suspend fun findByPostIds(ids: List): List = findByPostIdsWithMedia(ids) diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/media/MediaApiServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/media/MediaApiServiceImpl.kt index 824a6f59..c87b6469 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/media/MediaApiServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/media/MediaApiServiceImpl.kt @@ -25,7 +25,6 @@ class MediaApiServiceImpl(private val mediaService: MediaService, private val tr type = type, url = uploadLocalMedia.url, previewUrl = uploadLocalMedia.thumbnailUrl, - remoteUrl = null, description = mediaRequest.description, blurhash = uploadLocalMedia.blurHash, textUrl = uploadLocalMedia.url diff --git a/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt b/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt index d8e7b246..a0f1a09b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt +++ b/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt @@ -35,7 +35,7 @@ object AcctUtil { } else -> { - throw IllegalArgumentException("Invalid acct.(Too many @)") + throw IllegalArgumentException("Invalid acct. (Too many @)") } } } diff --git a/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt b/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt index 882a211f..66d321fc 100644 --- a/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt +++ b/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt @@ -3,10 +3,10 @@ package dev.usbharu.hideout.util import io.ktor.http.* object HttpUtil { - val ContentType.Application.Activity: ContentType + val Activity: ContentType get() = ContentType("application", "activity+json") - val ContentType.Application.JsonLd: ContentType + val JsonLd: ContentType get() { return ContentType( contentType = "application",