Merge pull request #536 from usbharu/ssr-front

OGPとnoscript時の簡易表示に対応
This commit is contained in:
usbharu 2024-08-13 15:48:33 +09:00 committed by GitHub
commit 17bf2aade6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
73 changed files with 911 additions and 272 deletions

View File

@ -22,7 +22,7 @@ import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationS
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import dev.usbharu.hideout.core.domain.service.actor.local.AccountMigrationCheck.*
import dev.usbharu.hideout.core.domain.service.actor.local.LocalActorMigrationCheckDomainService
@ -37,7 +37,7 @@ class MigrationLocalActorApplicationService(
private val userDetailRepository: UserDetailRepository,
) : LocalUserAbstractApplicationService<MigrationLocalActor, Unit>(transaction, logger) {
override suspend fun internalExecute(command: MigrationLocalActor, principal: FromApi) {
override suspend fun internalExecute(command: MigrationLocalActor, principal: LocalUser) {
if (command.from != principal.actorId.id) {
throw PermissionDeniedException()
}

View File

@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.application.exception.PermissionDeniedException
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -30,7 +30,7 @@ class StartDeleteLocalActorApplicationService(
transaction: Transaction,
private val actorRepository: ActorRepository,
) : LocalUserAbstractApplicationService<DeleteLocalActor, Unit>(transaction, logger) {
override suspend fun internalExecute(command: DeleteLocalActor, principal: FromApi) {
override suspend fun internalExecute(command: DeleteLocalActor, principal: LocalUser) {
if (command.actorId != principal.actorId) {
throw PermissionDeniedException()
}

View File

@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationS
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.filter.FilterId
import dev.usbharu.hideout.core.domain.model.filter.FilterRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -31,7 +31,7 @@ class UserDeleteFilterApplicationService(private val filterRepository: FilterRep
transaction,
logger
) {
override suspend fun internalExecute(command: DeleteFilter, principal: FromApi) {
override suspend fun internalExecute(command: DeleteFilter, principal: LocalUser) {
val filter =
filterRepository.findByFilterId(FilterId(command.filterId)) ?: throw IllegalArgumentException("not found")
if (filter.userDetailId != principal.userDetailId) {

View File

@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationS
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.filter.FilterId
import dev.usbharu.hideout.core.domain.model.filter.FilterRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -31,7 +31,7 @@ class UserGetFilterApplicationService(private val filterRepository: FilterReposi
transaction,
logger
) {
override suspend fun internalExecute(command: GetFilter, principal: FromApi): Filter {
override suspend fun internalExecute(command: GetFilter, principal: LocalUser): Filter {
val filter =
filterRepository.findByFilterId(FilterId(command.filterId)) ?: throw IllegalArgumentException("Not Found")
if (filter.userDetailId != principal.userDetailId) {

View File

@ -20,7 +20,7 @@ import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationS
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.filter.*
import dev.usbharu.hideout.core.domain.model.filter.FilterKeyword
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -36,7 +36,7 @@ class UserRegisterFilterApplicationService(
logger
) {
override suspend fun internalExecute(command: RegisterFilter, principal: FromApi): Filter {
override suspend fun internalExecute(command: RegisterFilter, principal: LocalUser): Filter {
val filter = dev.usbharu.hideout.core.domain.model.filter.Filter.create(
id = FilterId(idGenerateService.generateId()),

View File

@ -0,0 +1,39 @@
package dev.usbharu.hideout.core.application.instance
import dev.usbharu.hideout.core.application.exception.InternalServerException
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.config.ApplicationConfig
import dev.usbharu.hideout.core.domain.model.instance.InstanceRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@Service
class GetLocalInstanceApplicationService(
private val applicationConfig: ApplicationConfig,
private val instanceRepository: InstanceRepository,
transaction: Transaction
) :
AbstractApplicationService<Unit, Instance>(
transaction, logger
) {
var cachedInstance: Instance? = null
override suspend fun internalExecute(command: Unit, principal: Principal): Instance {
if (cachedInstance != null) {
return cachedInstance!!
}
val instance = (instanceRepository.findByUrl(applicationConfig.url.toURI())
?: throw InternalServerException("Local instance not found."))
cachedInstance = Instance.of(instance)
return cachedInstance!!
}
companion object {
private val logger = LoggerFactory.getLogger(GetLocalInstanceApplicationService::class.java)
}
}

View File

@ -0,0 +1,14 @@
package dev.usbharu.hideout.core.application.instance
import dev.usbharu.hideout.core.domain.model.instance.Instance
import java.net.URI
data class Instance(val id: Long, val name: String, val url: URI, val description: String) {
companion object {
fun of(instance: Instance): dev.usbharu.hideout.core.application.instance.Instance {
return Instance(
instance.id.instanceId, instance.name.name, instance.url, instance.description.description
)
}
}
}

View File

@ -19,7 +19,7 @@ package dev.usbharu.hideout.core.application.media
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.media.*
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService
import dev.usbharu.hideout.core.external.media.MediaProcessor
import dev.usbharu.hideout.core.external.mediastore.MediaStore
@ -39,7 +39,7 @@ class UploadMediaApplicationService(
transaction,
logger
) {
override suspend fun internalExecute(command: UploadMedia, principal: FromApi): Media {
override suspend fun internalExecute(command: UploadMedia, principal: LocalUser): Media {
val process = mediaProcessor.process(command.path, command.name, null)
val id = idGenerateService.generateId()
val thumbnailUri = if (process.thumbnailPath != null) {

View File

@ -0,0 +1,35 @@
package dev.usbharu.hideout.core.application.post
import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.instance.Instance
import dev.usbharu.hideout.core.domain.model.media.Media
import java.net.URI
data class ActorDetail(
val actorId: Long,
val instanceId: Long,
val instanceName: String,
val name: String,
val domain: String,
val screenName: String,
val url: URI,
val locked: Boolean,
val icon: URI?,
) {
companion object {
fun of(actor: Actor, instance: Instance, iconMedia: Media?): ActorDetail {
return ActorDetail(
actor.id.id,
actor.instance.instanceId,
instance.name.name,
actor.name.name,
actor.domain.domain,
actor.screenName.screenName,
actor.url,
actor.locked,
iconMedia?.url
)
}
}
}

View File

@ -22,7 +22,7 @@ import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -32,7 +32,7 @@ class DeleteLocalPostApplicationService(
private val actorRepository: ActorRepository, transaction: Transaction,
) : LocalUserAbstractApplicationService<DeleteLocalPost, Unit>(transaction, logger) {
override suspend fun internalExecute(command: DeleteLocalPost, principal: FromApi) {
override suspend fun internalExecute(command: DeleteLocalPost, principal: LocalUser) {
val findById = postRepository.findById(PostId(command.postId))!!
if (findById.actorId != principal.actorId) {
throw PermissionDeniedException()

View File

@ -0,0 +1,3 @@
package dev.usbharu.hideout.core.application.post
data class GetPostDetail(val postId: Long)

View File

@ -0,0 +1,90 @@
package dev.usbharu.hideout.core.application.post
import dev.usbharu.hideout.core.application.exception.InternalServerException
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.instance.Instance
import dev.usbharu.hideout.core.domain.model.instance.InstanceRepository
import dev.usbharu.hideout.core.domain.model.media.Media
import dev.usbharu.hideout.core.domain.model.media.MediaRepository
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.service.post.IPostReadAccessControl
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@Service
class GetPostDetailApplicationService(
transaction: Transaction,
private val postRepository: PostRepository,
private val actorRepository: ActorRepository,
private val instanceRepository: InstanceRepository,
private val mediaRepository: MediaRepository,
private val iPostReadAccessControl: IPostReadAccessControl
) : AbstractApplicationService<GetPostDetail, PostDetail>(
transaction, logger
) {
override suspend fun internalExecute(command: GetPostDetail, principal: Principal): PostDetail {
val post = postRepository.findById(PostId(command.postId))
?: throw IllegalArgumentException("Post ${command.postId} not found.")
if (iPostReadAccessControl.isAllow(post, principal).not()) {
throw IllegalArgumentException("Post ${command.postId} not found.")
}
val actor =
actorRepository.findById(post.actorId) ?: throw InternalServerException("Actor ${post.actorId} not found.")
val instance = instanceRepository.findById(post.instanceId)
?: throw InternalServerException("Instance ${post.instanceId} not found.")
val iconMedia = actor.icon?.let { mediaRepository.findById(it) }
val mediaList = mediaRepository.findByIds(post.mediaIds)
return PostDetail.of(
post,
actor,
instance,
iconMedia,
mediaList,
post.replyId?.let { fetchChild(it, actor, instance, iconMedia, principal) },
post.repostId?.let { fetchChild(it, actor, instance, iconMedia, principal) },
post.moveTo?.let { fetchChild(it, actor, instance, iconMedia, principal) },
)
}
private suspend fun fetchChild(
postId: PostId,
actor: Actor,
instance: Instance,
iconMedia: Media?,
principal: Principal
): PostDetail? {
val post = postRepository.findById(postId) ?: return null
if (iPostReadAccessControl.isAllow(post, principal).not()) {
return null
}
val (first, second: Instance, third) = if (actor.id != post.actorId) {
Triple(
actorRepository.findById(post.actorId) ?: return null,
instanceRepository.findById(actor.instance) ?: return null,
actor.icon?.let { mediaRepository.findById(it) }
)
} else {
Triple(actor, instance, iconMedia)
}
val mediaList = mediaRepository.findByIds(post.mediaIds)
return PostDetail.of(
post, first, second, third, mediaList
)
}
companion object {
private val logger = LoggerFactory.getLogger(GetPostDetailApplicationService::class.java)
}
}

View File

@ -0,0 +1,28 @@
package dev.usbharu.hideout.core.application.post
import dev.usbharu.hideout.core.domain.model.media.Media
import java.net.URI
data class MediaDetail(
val mediaId: Long,
val type: String,
val url: URI,
val thumbnailUrl: URI?,
val sensitive: Boolean,
val description: String,
val blurhash: String
) {
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()
)
}
}
}

View File

@ -0,0 +1,60 @@
package dev.usbharu.hideout.core.application.post
import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.instance.Instance
import dev.usbharu.hideout.core.domain.model.media.Media
import dev.usbharu.hideout.core.domain.model.post.Post
import dev.usbharu.hideout.core.domain.model.post.Visibility
import java.net.URI
import java.time.Instant
data class PostDetail(
val id: Long,
val actor: ActorDetail,
val overview: String?,
val text: String,
val content: String,
val createdAt: Instant,
val visibility: Visibility,
val pureRepost: Boolean,
val url: URI,
val apId: URI,
val repost: PostDetail?,
val reply: PostDetail?,
val sensitive: Boolean,
val deleted: Boolean,
val mediaDetailList: List<MediaDetail>,
val moveTo: PostDetail?
) {
companion object {
fun of(
post: Post,
actor: Actor,
instance: Instance,
iconMedia: Media?,
mediaList: List<Media>,
reply: PostDetail? = null,
repost: PostDetail? = null,
moveTo: PostDetail? = null,
): PostDetail {
return PostDetail(
id = post.id.id,
actor = ActorDetail.of(actor, instance, iconMedia),
overview = post.overview?.overview,
text = post.text,
content = post.content.content,
createdAt = post.createdAt,
visibility = post.visibility,
pureRepost = post.isPureRepost,
url = post.url,
apId = post.apId,
repost = repost,
reply = reply,
sensitive = post.sensitive,
deleted = false,
mediaDetailList = mediaList.map { MediaDetail.of(it) },
moveTo = moveTo
)
}
}
}

View File

@ -24,7 +24,7 @@ import dev.usbharu.hideout.core.domain.model.media.MediaId
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostOverview
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -38,7 +38,7 @@ class RegisterLocalPostApplicationService(
transaction: Transaction,
) : LocalUserAbstractApplicationService<RegisterLocalPost, Long>(transaction, Companion.logger) {
override suspend fun internalExecute(command: RegisterLocalPost, principal: FromApi): Long {
override suspend fun internalExecute(command: RegisterLocalPost, principal: LocalUser): Long {
val actorId = principal.actorId
val actor = actorRepository.findById(actorId) ?: throw InternalServerException("Actor $actorId not found.")

View File

@ -25,7 +25,7 @@ import dev.usbharu.hideout.core.domain.model.media.MediaId
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostOverview
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import dev.usbharu.hideout.core.infrastructure.factory.PostContentFactoryImpl
import org.slf4j.LoggerFactory
@ -40,7 +40,7 @@ class UpdateLocalNoteApplicationService(
private val actorRepository: ActorRepository,
) : LocalUserAbstractApplicationService<UpdateLocalNote, Unit>(transaction, logger) {
override suspend fun internalExecute(command: UpdateLocalNote, principal: FromApi) {
override suspend fun internalExecute(command: UpdateLocalNote, principal: LocalUser) {
val post = postRepository.findById(PostId(command.postId))
?: throw IllegalArgumentException("Post ${command.postId} not found.")
if (post.actorId != principal.actorId) {

View File

@ -23,7 +23,7 @@ import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -34,7 +34,7 @@ class UserAcceptFollowRequestApplicationService(
private val actorRepository: ActorRepository,
) :
LocalUserAbstractApplicationService<AcceptFollowRequest, Unit>(transaction, logger) {
override suspend fun internalExecute(command: AcceptFollowRequest, principal: FromApi) {
override suspend fun internalExecute(command: AcceptFollowRequest, principal: LocalUser) {
val actor = actorRepository.findById(principal.actorId)
?: throw InternalServerException("Actor ${principal.actorId} not found")

View File

@ -22,7 +22,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.service.relationship.RelationshipDomainService
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,7 +35,7 @@ class UserBlockApplicationService(
private val relationshipDomainService: RelationshipDomainService,
) :
LocalUserAbstractApplicationService<Block, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Block, principal: FromApi) {
override suspend fun internalExecute(command: Block, principal: LocalUser) {
val actor = actorRepository.findById(principal.actorId)

View File

@ -23,7 +23,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -37,7 +37,7 @@ class UserFollowRequestApplicationService(
logger
) {
override suspend fun internalExecute(command: FollowRequest, principal: FromApi) {
override suspend fun internalExecute(command: FollowRequest, principal: LocalUser) {
val actor = actorRepository.findById(principal.actorId)
?: throw InternalServerException("Actor ${principal.actorId} not found.")

View File

@ -24,7 +24,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInstanceRelationship
import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInstanceRelationshipRepository
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -39,7 +39,7 @@ class GetRelationshipApplicationService(
transaction,
logger
) {
override suspend fun internalExecute(command: GetRelationship, principal: FromApi): Relationship {
override suspend fun internalExecute(command: GetRelationship, principal: LocalUser): Relationship {
val actor = actorRepository.findById(principal.actorId)
?: throw InternalServerException("Actor ${principal.actorId} not found.")
val targetId = ActorId(command.targetActorId)

View File

@ -24,7 +24,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,7 +35,7 @@ class UserMuteApplicationService(
private val actorRepository: ActorRepository,
) :
LocalUserAbstractApplicationService<Mute, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Mute, principal: FromApi) {
override suspend fun internalExecute(command: Mute, principal: LocalUser) {
val actor = actorRepository.findById(principal.actorId)
?: throw InternalServerException("Actor ${principal.actorId} not found.")

View File

@ -23,7 +23,7 @@ import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -34,7 +34,7 @@ class UserRejectFollowRequestApplicationService(
private val actorRepository: ActorRepository,
) :
LocalUserAbstractApplicationService<RejectFollowRequest, Unit>(transaction, logger) {
override suspend fun internalExecute(command: RejectFollowRequest, principal: FromApi) {
override suspend fun internalExecute(command: RejectFollowRequest, principal: LocalUser) {
val actor = actorRepository.findById(principal.actorId)
?: throw InternalServerException("Actor ${principal.actorId} not found.")

View File

@ -24,7 +24,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,7 +35,7 @@ class UserRemoveFromFollowersApplicationService(
private val actorRepository: ActorRepository,
) :
LocalUserAbstractApplicationService<RemoveFromFollowers, Unit>(transaction, logger) {
override suspend fun internalExecute(command: RemoveFromFollowers, principal: FromApi) {
override suspend fun internalExecute(command: RemoveFromFollowers, principal: LocalUser) {
val actor = actorRepository.findById(principal.actorId)
?: throw InternalServerException("Actor ${principal.actorId} not found.")

View File

@ -24,7 +24,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,7 +35,7 @@ class UserUnblockApplicationService(
private val actorRepository: ActorRepository,
) :
LocalUserAbstractApplicationService<Unblock, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Unblock, principal: FromApi) {
override suspend fun internalExecute(command: Unblock, principal: LocalUser) {
val actor = actorRepository.findById(principal.actorId)
?: throw InternalServerException("Actor ${principal.actorId} not found.")

View File

@ -24,7 +24,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,7 +35,7 @@ class UserUnfollowApplicationService(
private val actorRepository: ActorRepository,
) :
LocalUserAbstractApplicationService<Unfollow, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Unfollow, principal: FromApi) {
override suspend fun internalExecute(command: Unfollow, principal: LocalUser) {
val actor = actorRepository.findById(principal.actorId)
?: throw InternalServerException("Actor ${principal.actorId} not found.")

View File

@ -24,7 +24,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -39,7 +39,7 @@ class UserUnmuteApplicationService(
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
override suspend fun internalExecute(command: Unmute, principal: FromApi) {
override suspend fun internalExecute(command: Unmute, principal: LocalUser) {
val actor = actorRepository.findById(principal.actorId)
?: throw InternalServerException("Actor ${principal.actorId} not found.")

View File

@ -1,18 +1,18 @@
package dev.usbharu.hideout.core.application.shared
import dev.usbharu.hideout.core.application.exception.PermissionDeniedException
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import org.slf4j.Logger
abstract class LocalUserAbstractApplicationService<T : Any, R>(transaction: Transaction, logger: Logger) :
AbstractApplicationService<T, R>(transaction, logger) {
override suspend fun internalExecute(command: T, principal: Principal): R {
if (principal !is FromApi) {
if (principal !is LocalUser) {
throw PermissionDeniedException()
}
return internalExecute(command, principal)
}
protected abstract suspend fun internalExecute(command: T, principal: FromApi): R
protected abstract suspend fun internalExecute(command: T, principal: LocalUser): R
}

View File

@ -2,7 +2,7 @@ package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationshipRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -15,7 +15,7 @@ class UserAddTimelineRelationshipApplicationService(
LocalUserAbstractApplicationService<AddTimelineRelationship, Unit>(
transaction, logger
) {
override suspend fun internalExecute(command: AddTimelineRelationship, principal: FromApi) {
override suspend fun internalExecute(command: AddTimelineRelationship, principal: LocalUser) {
timelineRelationshipRepository.save(command.timelineRelationship)
}

View File

@ -81,6 +81,10 @@ class SecurityConfig {
authorize(GET, "/auth/sign_up", hasRole("ANONYMOUS"))
authorize(POST, "/auth/sign_up", permitAll)
authorize(GET, "/users/{username}/posts/{postId}", permitAll)
authorize(GET, "/files/*", permitAll)
authorize(POST, "/publish", authenticated)
authorize(GET, "/publish", authenticated)
authorize(anyRequest, authenticated)
}

View File

@ -19,5 +19,6 @@ package dev.usbharu.hideout.core.domain.model.media
interface MediaRepository {
suspend fun save(media: Media): Media
suspend fun findById(id: MediaId): Media?
suspend fun findByIds(ids: List<MediaId>): List<Media>
suspend fun delete(media: Media)
}

View File

@ -83,6 +83,8 @@ class Post(
}
}
val isPureRepost = content == PostContent.empty && overview == null && replyId == null && repostId != null
var content = content
get() {
if (hide) {

View File

@ -4,7 +4,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
class FromApi(
class LocalUser(
actorId: ActorId,
override val userDetailId: UserDetailId,
override val acct: Acct

View File

@ -16,6 +16,12 @@ interface IPostReadAccessControl {
class DefaultPostReadAccessControl(private val relationshipRepository: RelationshipRepository) :
IPostReadAccessControl {
override suspend fun isAllow(post: Post, principal: Principal): Boolean {
//ポスト主は無条件で見れる
if (post.actorId == principal.actorId) {
return true
}
val relationship = (relationshipRepository.findByActorIdAndTargetId(post.actorId, principal.actorId)
?: Relationship.default(post.actorId, principal.actorId))

View File

@ -38,14 +38,14 @@ class PostQueryMapper(private val postResultRowMapper: ResultRowMapper<Post>) :
it
.first()
.let(postResultRowMapper::map)
.apply {
buildPost(it)
.run {
buildPost(this, it)
}
}
}
private fun Post.buildPost(it: List<ResultRow>) {
reconstructWith(
private fun buildPost(post: Post, it: List<ResultRow>): Post {
return post.reconstructWith(
mediaIds = it.mapNotNull { resultRow: ResultRow ->
resultRow
.getOrNull(PostsMedia.mediaId)

View File

@ -157,6 +157,7 @@ class ExposedPostRepository(
override suspend fun findById(id: PostId): Post? = query {
Posts
.leftJoin(PostsMedia)
.selectAll()
.where {
Posts.id eq id.id

View File

@ -39,6 +39,15 @@ class MediaRepositoryImpl : MediaRepository, AbstractRepository() {
}
}
override suspend fun findByIds(ids: List<MediaId>): List<dev.usbharu.hideout.core.domain.model.media.Media> {
return query {
return@query Media
.selectAll()
.where { Media.id inList ids.map { it.id } }
.map { it.toMedia() }
}
}
override suspend fun delete(media: dev.usbharu.hideout.core.domain.model.media.Media): Unit = query {
Media.deleteWhere {
id eq id

View File

@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.stereotype.Component
import java.net.URI
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.copyTo
@ -19,9 +20,16 @@ class LocalFileSystemMediaStore(
MediaStore {
private val publicUrl = localStorageConfig.publicUrl ?: "${applicationConfig.url}/files/"
private val savePath = Path.of(localStorageConfig.path)
init {
Files.createDirectories(savePath)
}
override suspend fun upload(path: Path, id: String): URI {
logger.info("START Media upload. {}", id)
val fileSavePath = buildSavePath(path, id)
val fileSavePath = buildSavePath(savePath, id)
val fileSavePathString = fileSavePath.toAbsolutePath().toString()
logger.info("MEDIA save. path: {}", fileSavePathString)

View File

@ -0,0 +1,35 @@
package dev.usbharu.hideout.core.infrastructure.springframework
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.HideoutUserDetails
import dev.usbharu.hideout.core.query.principal.PrincipalQueryService
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.stereotype.Component
@Component("formLogin")
class SpringSecurityFormLoginPrincipalContextHolder(
private val transaction: Transaction,
private val principalQueryService: PrincipalQueryService
) : PrincipalContextHolder {
override suspend fun getPrincipal(): Principal {
val hideoutUserDetails =
SecurityContextHolder.getContext().authentication?.principal as? HideoutUserDetails ?: return Anonymous
return transaction.transaction {
val userDetail = principalQueryService.findByUserDetailId(UserDetailId(hideoutUserDetails.userDetailsId))
LocalUser(
userDetail.actorId,
userDetail.userDetailId,
Acct(userDetail.username, userDetail.host)
)
}
}
}

View File

@ -3,7 +3,7 @@ package dev.usbharu.hideout.core.infrastructure.springframework.oauth2
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
@ -12,7 +12,7 @@ import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.oauth2.jwt.Jwt
import org.springframework.stereotype.Component
@Component
@Component("oauth2")
class SpringSecurityOauth2PrincipalContextHolder(
private val principalQueryService: PrincipalQueryService,
private val transaction: Transaction
@ -26,7 +26,7 @@ class SpringSecurityOauth2PrincipalContextHolder(
val id = principal.getClaim<String>("uid").toLong()
val userDetail = principalQueryService.findByUserDetailId(UserDetailId(id))
return@transaction FromApi(
return@transaction LocalUser(
userDetail.actorId,
userDetail.userDetailId,
Acct(userDetail.username, userDetail.host)

View File

@ -16,21 +16,44 @@
package dev.usbharu.hideout.core.interfaces.api.media
import dev.usbharu.hideout.core.config.LocalStorageConfig
import dev.usbharu.hideout.core.external.media.FileTypeDeterminer
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.core.io.ClassPathResource
import org.springframework.core.io.PathResource
import org.springframework.core.io.Resource
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import java.nio.file.Path
import kotlin.io.path.name
@Controller
@ConditionalOnProperty("hideout.storage.type", havingValue = "local", matchIfMissing = true)
interface LocalFileController {
class LocalFileController(
localStorageConfig: LocalStorageConfig,
private val fileTypeDeterminationService: FileTypeDeterminer
) {
private val savePath = Path.of(localStorageConfig.path).toAbsolutePath()
@GetMapping("/files/{id}")
fun files(@PathVariable("id") id: String): ResponseEntity<Resource>
fun files(@PathVariable("id") id: String): ResponseEntity<Resource> {
val name = Path.of(id).name
val path = savePath.resolve(name)
val mimeType = fileTypeDeterminationService.fileType(path, name)
val pathResource = PathResource(path)
return ResponseEntity
.ok()
.contentType(MediaType(mimeType.type, mimeType.subtype))
.contentLength(pathResource.contentLength())
.body(pathResource)
}
@GetMapping("/users/{user}/icon.jpg", "/users/{user}/header.jpg")
fun icons(): ResponseEntity<Resource> {

View File

@ -0,0 +1,34 @@
package dev.usbharu.hideout.core.interfaces.web.posts
import dev.usbharu.hideout.core.application.exception.PermissionDeniedException
import dev.usbharu.hideout.core.application.instance.GetLocalInstanceApplicationService
import dev.usbharu.hideout.core.application.post.GetPostDetail
import dev.usbharu.hideout.core.application.post.GetPostDetailApplicationService
import dev.usbharu.hideout.core.infrastructure.springframework.SpringSecurityFormLoginPrincipalContextHolder
import org.springframework.security.access.AccessDeniedException
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
@Controller
class PostsController(
private val getPostDetailApplicationService: GetPostDetailApplicationService,
private val springSecurityFormLoginPrincipalContextHolder: SpringSecurityFormLoginPrincipalContextHolder,
private val getLocalInstanceApplicationService: GetLocalInstanceApplicationService
) {
@GetMapping("/users/{name}/posts/{id}")
suspend fun postById(@PathVariable id: Long, model: Model): String {
val principal = springSecurityFormLoginPrincipalContextHolder.getPrincipal()
try {
val post = getPostDetailApplicationService.execute(GetPostDetail(id), principal)
val instance = getLocalInstanceApplicationService.execute(Unit, principal)
model.addAttribute("post", post)
model.addAttribute("instance", instance)
} catch (e: PermissionDeniedException) {
throw AccessDeniedException("403 Forbidden", e)
}
return "postById"
}
}

View File

@ -0,0 +1,60 @@
package dev.usbharu.hideout.core.interfaces.web.posts
import dev.usbharu.hideout.core.application.actor.GetUserDetail
import dev.usbharu.hideout.core.application.actor.GetUserDetailApplicationService
import dev.usbharu.hideout.core.application.instance.GetLocalInstanceApplicationService
import dev.usbharu.hideout.core.application.post.RegisterLocalPost
import dev.usbharu.hideout.core.application.post.RegisterLocalPostApplicationService
import dev.usbharu.hideout.core.domain.model.post.Visibility
import dev.usbharu.hideout.core.infrastructure.springframework.SpringSecurityFormLoginPrincipalContextHolder
import org.springframework.security.access.AccessDeniedException
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ModelAttribute
import org.springframework.web.bind.annotation.PostMapping
@Controller
class PublishController(
private val getLocalInstanceApplicationService: GetLocalInstanceApplicationService,
private val springSecurityFormLoginPrincipalContextHolder: SpringSecurityFormLoginPrincipalContextHolder,
private val getUserDetailApplicationService: GetUserDetailApplicationService,
private val userRegisterLocalPostApplicationService: RegisterLocalPostApplicationService
) {
@GetMapping("/publish")
suspend fun publish(model: Model): String {
val principal = springSecurityFormLoginPrincipalContextHolder.getPrincipal()
if (principal.userDetailId == null) {
throw AccessDeniedException("403 Forbidden")
}
val instance = getLocalInstanceApplicationService.execute(Unit, principal)
val userDetail = getUserDetailApplicationService.execute(GetUserDetail(principal.userDetailId!!.id), principal)
model.addAttribute("instance", instance)
model.addAttribute("user", userDetail)
model.addAttribute("form", PublishPost())
return "post-postForm"
}
@PostMapping("/publish")
suspend fun publishForm(@ModelAttribute publishPost: PublishPost): String {
val principal = springSecurityFormLoginPrincipalContextHolder.getPrincipal()
if (principal.userDetailId == null) {
throw AccessDeniedException("403 Forbidden")
}
val command = RegisterLocalPost(
content = publishPost.status.orEmpty(),
overview = publishPost.overview,
visibility = Visibility.valueOf(publishPost.visibility.uppercase()),
repostId = null,
replyId = null,
sensitive = false,
mediaIds = emptyList()
)
val id = userRegisterLocalPostApplicationService.execute(command, principal)
return "redirect:/users/${principal.acct?.userpart}/posts/${id}"
}
}

View File

@ -0,0 +1,3 @@
package dev.usbharu.hideout.core.interfaces.web.posts
data class PublishPost(var status: String? = null, var overview: String? = null, var visibility: String = "PUBLIC")

View File

@ -47,6 +47,8 @@ spring:
threads:
virtual:
enabled: true
messages:
basename: messages.hideout-web-messages
server:
tomcat:
basedir: tomcat

View File

@ -0,0 +1,19 @@
common.audio=\u30AA\u30FC\u30C7\u30A3\u30AA
common.audio-download-link=\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9
common.media-original-link=\u30AA\u30EA\u30B8\u30CA\u30EB
common.thumbnail=\u30B5\u30E0\u30CD\u30A4\u30EB
common.unknwon-file-type=\u4E0D\u660E\u306A\u30D5\u30A1\u30A4\u30EB\u5F62\u5F0F
common.video=\u52D5\u753B
common.video-download-link=\u52D5\u753B\u30D5\u30A1\u30A4\u30EB\u307E\u305F\u306F\u30B5\u30E0\u30CD\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9
common.visibility=\u516C\u958B\u7BC4\u56F2
common.visibility-followers=\u30D5\u30A9\u30ED\u30EF\u30FC\u306E\u307F
common.visibility-public=\u30D1\u30D6\u30EA\u30C3\u30AF
common.visibility-unlisted=\u672A\u53CE\u8F09
post-by-id.title={0} \u3055\u3093\u306E\u6295\u7A3F - {1}
post-form.new-posts=\u65B0\u3057\u3044\u6295\u7A3F!
post-form.new-posts-cw=CW
post-form.new-posts-cw-title=\u30B3\u30F3\u30C6\u30F3\u30C4\u306B\u95B2\u89A7\u6CE8\u610F\u3092\u3064\u3051\u308B
post-form.new-posts-form-label=\u4ECA\u306A\u306B\u3057\u3066\u308B?
post-form.new-posts-submit=\u6295\u7A3F\u3059\u308B
post.repost=\u30EA\u30DD\u30B9\u30C8
post.repost-by={0}\u304C\u30EA\u30DD\u30B9\u30C8

View File

@ -0,0 +1,18 @@
common.audio=Audio
common.audio-download-link=Download the audio.
common.media-original-link=original
common.thumbnail=thumbnail
common.unknwon-file-type=Unknown filetype
common.video=Video
common.video-download-link=Download the Video or thumbnail.
common.visibility=Visibility
common.visibility-followers=Followers only
common.visibility-public=Public
common.visibility-unlisted=Unlisted
post-form.new-posts=New Posts!
post-form.new-posts-cw=CW
post-form.new-posts-cw-title=Add content warning
post-form.new-posts-form-label=What's on your mind?
post-form.new-posts-submit=Submit!
post.repost=Repost
post.repost-by=Repost by {0}

View File

@ -0,0 +1,19 @@
common.audio=\u30AA\u30FC\u30C7\u30A3\u30AA
common.audio-download-link=\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9
common.media-original-link=\u30AA\u30EA\u30B8\u30CA\u30EB
common.thumbnail=\u30B5\u30E0\u30CD\u30A4\u30EB
common.unknwon-file-type=\u4E0D\u660E\u306A\u30D5\u30A1\u30A4\u30EB\u5F62\u5F0F
common.video=\u52D5\u753B
common.video-download-link=\u52D5\u753B\u30D5\u30A1\u30A4\u30EB\u307E\u305F\u306F\u30B5\u30E0\u30CD\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9
common.visibility=\u516C\u958B\u7BC4\u56F2
common.visibility-followers=\u30D5\u30A9\u30ED\u30EF\u30FC\u306E\u307F
common.visibility-public=\u30D1\u30D6\u30EA\u30C3\u30AF
common.visibility-unlisted=\u672A\u53CE\u8F09
post-by-id.title={0} \u3055\u3093\u306E\u6295\u7A3F - {1}
post-form.new-posts=\u65B0\u3057\u3044\u6295\u7A3F!
post-form.new-posts-cw=CW
post-form.new-posts-cw-title=\u30B3\u30F3\u30C6\u30F3\u30C4\u306B\u95B2\u89A7\u6CE8\u610F\u3092\u3064\u3051\u308B
post-form.new-posts-form-label=\u4ECA\u306A\u306B\u3057\u3066\u308B?
post-form.new-posts-submit=\u6295\u7A3F\u3059\u308B
post.repost=\u30EA\u30DD\u30B9\u30C8
post.repost-by={0}\u304C\u30EA\u30DD\u30B9\u30C8

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,53 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<article class="post" th:fragment="single-simple-post(post)">
<!--/*@thymesVar id="post" type="dev.usbharu.hideout.core.application.post.PostDetail"*/-->
<img alt="" height="80px" src="" th:src="${post.actor.icon}" width="80px">
<div style="display: inline-block">
<p th:text="${post.actor.screenName}+'('+${post.actor.name}+'@'+${post.actor.domain}+')'"></p>
</div>
<div th:utext="${post.content}">
</div>
<div th:each=" media : ${post.mediaDetailList} ">
<th:block th:switch="${media.type}">
<picture th:case="Image">
<source media="(min-width: 600px)" th:srcset="${media.url}">
<img alt="" src="" th:alt="${media.description}" th:src="${media.thumbnailUrl}" width="260">
</picture>
<video controls loop preload="metadata" th:case="Video" th:poster="${media.thumbnailUrl}" th:src="${media.url}"
th:text="#{common.video-download-link}"
width="260">
<a th:href="${media.url}" th:text="#{common.video}">Video</a>
<a th:href="${media.thumbnailUrl}" th:text="#{common.thumbnail}">Thumbnail</a>
</video>
<audio controls preload="metadata" th:case="Audio" th:src="${media.url}"
th:text="#{common.audio-download-link}">
<a th:href="${media.url}" th:text="#{common.audio}">Audio</a>
</audio>
<th:block th:case="*">
<p th:text="#{common.unknwon-file-type}">Unknown filetype</p>
</th:block>
</th:block>
<a href="" th:href="${media.url}" th:text="#{common.media-original-link}"></a>
</div>
</article>
<div class="post-controller" th:fragment="single-post-controller(post)">
<!--/*@thymesVar id="post" type="dev.usbharu.hideout.core.application.post.PostDetail"*/-->
<a th:href="${post.apId}">
<time th:datetime="${post.createdAt}" th:text="${#temporals.format(post.createdAt, 'yyyy-MM-dd HH:mm')}"></time>
</a>
</div>
</body>
</html>

View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
<head prefix="og: http://ogp.me/ns#">
<meta charset="UTF-8">
<title th:text="#{post-form.new-posts}">New Posts!</title>
<meta property="og:url" th:content="${instance.url + '/publish'}">
<meta property="og:title" th:content="#{post-form.new-posts}">
</head>
<body>
<noscript>
<div>
<img alt="" height="80px" src="" th:src="${user.iconUrl}" width="80px">
<div style="display: inline-block">
<p th:text="${user.screenName}+'('+${user.name}+'@'+${user.domain}+')'"></p>
</div>
</div>
<form action="/publish" method="post" th:action="@{/publish}" th:object="${form}">
<div>
<label for="stats-form-overview" th:text="#{post-form.new-posts-cw}"
th:title="#{post-form.new-posts-cw-title}"
title="Add content warning">CW</label>
<input id="stats-form-overview" name="overview" type="text">
</div>
<div>
<label for="status-form" th:text="#{post-form.new-posts-form-label}">What's on your mind?</label>
<br>
<textarea cols="33" id="status-form" name="status" rows="5"></textarea>
</div>
<div>
<fieldset>
<legend th:text="#{common.visibility}">Visibility</legend>
<label for="status-form-visibility-public" th:text="#{common.visibility-public}">Public</label>
<input id="status-form-visibility-public" name="visibility" th:checked="${form.visibility == 'PUBLIC'}" type="radio"
value="PUBLIC">
<label for="status-form-visibility-unlisted" th:text="#{common.visibility-unlisted}">Unlisted</label>
<input id="status-form-visibility-unlisted" name="visibility" th:checked="${form.visibility == 'UNLISTED'}" type="radio"
value="UNLISTED">
<label for="status-form-visibility-followers" th:text="#{common.visibility-followers}">Followers</label>
<input id="status-form-visibility-followers" name="visibility" th:checked="${form.visibility == 'FOLLOWERS'}" type="radio"
value="FOLLOWERS">
</fieldset>
</div>
<div>
<input th:value="#{post-form.new-posts-submit}" type="submit" value="Publish!">
</div>
</form>
</noscript>
</body>
</html>

View File

@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
<head prefix="og: http://ogp.me/ns#">
<meta charset="UTF-8">
<title th:text="#{post-by-id.title(${post.actor.screenName},${instance.name})}">Posts - hideout</title>
<meta property="og:url" th:content="${post.url}">
<meta property="og:title" th:content="#{post-by-id.title(${post.actor.screenName},${instance.name})}">
<meta property="og:description" th:content="${post.text}">
<th:block
th:if="${post.mediaDetailList.isEmpty() || (post.mediaDetailList.get(0).thumbnailUrl == null && (post.mediaDetailList.get(0).type != 'Image' || post.mediaDetailList.get(0).type != 'Video'))}">
<meta property="og:image" th:content="${post.actor.icon}">
</th:block>
<th:block
th:unless="${post.mediaDetailList.isEmpty() || (post.mediaDetailList.get(0).thumbnailUrl == null && (post.mediaDetailList.get(0).type != 'Image' || post.mediaDetailList.get(0).type != 'Video'))}">
<meta property="og:image" th:content="${post.mediaDetailList.get(0).thumbnailUrl}">
</th:block>
</head>
<body>
<noscript>
<th:block th:if=" ${post.reply != null}">
<th:block th:replace="fragments-post :: single-simple-post(${post.reply})"></th:block>
<hr>
</th:block>
<main>
<p th:if="${post.pureRepost}" th:text="#{post.repost-by(${post.actor.name})}">Repost by user</p>
<th:block th:unless="${post.pureRepost}">
<th:block th:replace="fragments-post :: single-simple-post(${post})"></th:block>
<th:block th:replace="fragments-post :: single-post-controller(${post})"></th:block>
</th:block>
<th:block th:if="${post.pureRepost}">
<th:block th:replace="fragments-post :: single-simple-post(${post.repost})"></th:block>
<th:block th:replace="fragments-post :: single-post-controller(${post.repost})"></th:block>
</th:block>
</main>
<th:block th:if="${post.repost != null && !post.pureRepost}">
<hr>
<th:block th:replace="fragments-post :: single-simple-post(${post.repost})"></th:block>
<cite th:text="${post.repost.apId}"></cite>
</th:block>
</noscript>
</body>
</html>

View File

@ -1,131 +0,0 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu.hideout
import com.fasterxml.jackson.module.kotlin.isKotlinClass
import com.jparams.verifier.tostring.ToStringVerifier
import com.jparams.verifier.tostring.preset.Presets
import nl.jqno.equalsverifier.EqualsVerifier
import nl.jqno.equalsverifier.Warning
import nl.jqno.equalsverifier.internal.reflection.PackageScanner
import org.junit.jupiter.api.DynamicTest
import org.junit.jupiter.api.DynamicTest.dynamicTest
import org.junit.jupiter.api.TestFactory
import org.springframework.context.annotation.Configuration
import org.springframework.stereotype.Component
import org.springframework.stereotype.Controller
import org.springframework.stereotype.Repository
import org.springframework.stereotype.Service
import org.springframework.web.bind.annotation.RestController
import java.lang.reflect.Modifier
class EqualsAndToStringTest {
@TestFactory
fun equalsTest(): List<DynamicTest> {
val classes = PackageScanner.getClassesIn("dev.usbharu.hideout", null, true)
return classes
.asSequence()
.filter {
it.getAnnotation(Service::class.java) == null
}
.filter {
it.getAnnotation(Repository::class.java) == null
}
.filter {
it.getAnnotation(Component::class.java) == null
}
.filter {
it.getAnnotation(Controller::class.java) == null
}
.filter {
it.getAnnotation(RestController::class.java) == null
}
.filter {
it.getAnnotation(Configuration::class.java) == null
}
.filterNot {
it.packageName.startsWith("dev.usbharu.hideout.domain.mastodon.model.generated")
}
.filterNot {
Throwable::class.java.isAssignableFrom(it)
}
.filterNot {
Modifier.isAbstract(it.modifiers)
}
.filter {
try {
it.kotlin.objectInstance == null
} catch (_: Exception) {
true
}
}
.filter {
it.superclass == Any::class.java || it.superclass?.packageName?.startsWith("dev.usbharu") ?: true
}
.map {
dynamicTest(it.name) {
if (it.isKotlinClass()) {
println(" at ${it.name}.toString(${it.simpleName}.kt:1)")
}
try {
EqualsVerifier.simple()
.suppress(Warning.INHERITED_DIRECTLY_FROM_OBJECT, Warning.TRANSIENT_FIELDS)
.forClass(it)
.verify()
} catch (e: AssertionError) {
e.printStackTrace()
}
}
}
.toList()
}
@TestFactory
fun toStringTest(): List<DynamicTest> {
return PackageScanner.getClassesIn("dev.usbharu.hideout", null, true)
.filter {
it != null && !it.isEnum && !it.isInterface && !Modifier.isAbstract(it.modifiers)
}
.filter {
val clazz = it.getMethod(it::toString.name).declaringClass
clazz != Any::class.java && clazz != Throwable::class.java
}
.filter {
it.superclass == Any::class.java || it.superclass?.packageName?.startsWith("dev.usbharu") ?: true
}
.filterNot {
it.superclass.isSealed
}
.map {
dynamicTest(it.name) {
if (it.isKotlinClass()) {
println(" at ${it.name}.toString(${it.simpleName}.kt:1)")
}
try {
ToStringVerifier.forClass(it).withPreset(Presets.INTELLI_J).verify()
} catch (e: Throwable) {
e.printStackTrace()
}
}
}
}
}

View File

@ -7,7 +7,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.actor.TestActorFactory
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailHashedPassword
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
@ -48,7 +48,7 @@ class MigrationLocalActorApplicationServiceTest {
assertThrows<PermissionDeniedException> {
service.execute(
MigrationLocalActor(1, 2),
FromApi(ActorId(3), UserDetailId(3), Acct("test", "example.com"))
LocalUser(ActorId(3), UserDetailId(3), Acct("test", "example.com"))
)
}
}
@ -64,7 +64,7 @@ class MigrationLocalActorApplicationServiceTest {
assertThrows<IllegalArgumentException> {
service.execute(
MigrationLocalActor(1, 2),
FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com"))
LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com"))
)
}
}
@ -81,7 +81,7 @@ class MigrationLocalActorApplicationServiceTest {
assertThrows<IllegalArgumentException> {
service.execute(
MigrationLocalActor(1, 2),
FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com"))
LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com"))
)
}
}
@ -91,7 +91,7 @@ class MigrationLocalActorApplicationServiceTest {
assertThrows<InternalServerException> {
service.execute(
MigrationLocalActor(1, 2),
FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com"))
LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com"))
)
}
}
@ -119,7 +119,7 @@ class MigrationLocalActorApplicationServiceTest {
service.execute(
MigrationLocalActor(1, 2),
FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com"))
LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com"))
)
argumentCaptor<Actor> {
@ -161,7 +161,7 @@ class MigrationLocalActorApplicationServiceTest {
assertThrows<IllegalArgumentException> {
service.execute(
MigrationLocalActor(1, 2),
FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com"))
LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com"))
)
}
}

View File

@ -6,7 +6,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.actor.TestActorFactory
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
@ -38,7 +38,7 @@ class StartDeleteLocalActorApplicationServiceTest {
service.execute(
DeleteLocalActor(ActorId(1)),
FromApi(ActorId(1), UserDetailId((1)), Acct("test", "example.com"))
LocalUser(ActorId(1), UserDetailId((1)), Acct("test", "example.com"))
)
}
@ -47,7 +47,7 @@ class StartDeleteLocalActorApplicationServiceTest {
assertThrows<PermissionDeniedException> {
service.execute(
DeleteLocalActor(ActorId(2)),
FromApi(ActorId(1), UserDetailId((1)), Acct("test", "example.com"))
LocalUser(ActorId(1), UserDetailId((1)), Acct("test", "example.com"))
)
}
}
@ -57,7 +57,7 @@ class StartDeleteLocalActorApplicationServiceTest {
assertThrows<InternalServerException> {
service.execute(
DeleteLocalActor(ActorId(1)),
FromApi(ActorId(1), UserDetailId((1)), Acct("test", "example.com"))
LocalUser(ActorId(1), UserDetailId((1)), Acct("test", "example.com"))
)
}
}

View File

@ -6,7 +6,7 @@ import dev.usbharu.hideout.core.domain.model.filter.*
import dev.usbharu.hideout.core.domain.model.filter.Filter
import dev.usbharu.hideout.core.domain.model.filter.FilterKeyword
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
@ -43,7 +43,7 @@ class UserDeleteFilterApplicationServiceTest {
whenever(filterRepository.findByFilterId(FilterId(1))).doReturn(filter)
service.execute(
DeleteFilter(1), FromApi(
DeleteFilter(1), LocalUser(
ActorId(1), UserDetailId(1),
Acct("test", "example.com")
)
@ -56,7 +56,7 @@ class UserDeleteFilterApplicationServiceTest {
fun フィルターが見つからない場合失敗() = runTest {
assertThrows<IllegalArgumentException> {
service.execute(
DeleteFilter(1), FromApi(
DeleteFilter(1), LocalUser(
ActorId(1), UserDetailId(1),
Acct("test", "example.com")
)
@ -77,7 +77,7 @@ class UserDeleteFilterApplicationServiceTest {
assertThrows<PermissionDeniedException> {
service.execute(
DeleteFilter(1), FromApi(
DeleteFilter(1), LocalUser(
ActorId(3), UserDetailId(3),
Acct("test", "example.com")
)

View File

@ -6,7 +6,7 @@ import dev.usbharu.hideout.core.domain.model.filter.*
import dev.usbharu.hideout.core.domain.model.filter.Filter
import dev.usbharu.hideout.core.domain.model.filter.FilterKeyword
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
@ -43,7 +43,7 @@ class UserGetFilterApplicationServiceTest {
whenever(filterRepository.findByFilterId(FilterId(1))).doReturn(filter)
service.execute(
GetFilter(1), FromApi(
GetFilter(1), LocalUser(
ActorId(1), UserDetailId(1),
Acct("test", "example.com")
)
@ -64,7 +64,7 @@ class UserGetFilterApplicationServiceTest {
assertThrows<PermissionDeniedException> {
service.execute(
GetFilter(1), FromApi(
GetFilter(1), LocalUser(
ActorId(3), UserDetailId(3),
Acct("test", "example.com")
)
@ -76,7 +76,7 @@ class UserGetFilterApplicationServiceTest {
fun フィルターが見つからない場合失敗() = runTest {
assertThrows<IllegalArgumentException> {
service.execute(
GetFilter(1), FromApi(
GetFilter(1), LocalUser(
ActorId(3), UserDetailId(3),
Acct("test", "example.com")
)

View File

@ -8,7 +8,7 @@ import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.post.TestPostFactory
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
@ -41,7 +41,7 @@ class DeleteLocalPostApplicationServiceTest {
whenever(postRepository.findById(PostId(1))).doReturn(TestPostFactory.create(actorId = 2))
whenever(actorRepository.findById(ActorId(2))).doReturn(TestActorFactory.create(id = 2))
service.execute(DeleteLocalPost(1), FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com")))
service.execute(DeleteLocalPost(1), LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com")))
}
@Test
@ -49,7 +49,7 @@ class DeleteLocalPostApplicationServiceTest {
whenever(postRepository.findById(PostId(1))).doReturn(TestPostFactory.create(actorId = 2))
assertThrows<PermissionDeniedException> {
service.execute(DeleteLocalPost(1), FromApi(ActorId(3), UserDetailId(3), Acct("test", "example.com")))
service.execute(DeleteLocalPost(1), LocalUser(ActorId(3), UserDetailId(3), Acct("test", "example.com")))
}
}
}

View File

@ -8,7 +8,7 @@ import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.post.TestPostFactory
import dev.usbharu.hideout.core.domain.model.post.Visibility
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl
import kotlinx.coroutines.test.runTest
@ -59,7 +59,7 @@ class RegisterLocalPostApplicationServiceTest {
).doReturn(post)
service.execute(
RegisterLocalPost("content test", null, Visibility.PUBLIC, null, null, false, emptyList()), FromApi(
RegisterLocalPost("content test", null, Visibility.PUBLIC, null, null, false, emptyList()), LocalUser(
ActorId(1), UserDetailId(1), Acct("test", "example.com")
)
)
@ -71,7 +71,7 @@ class RegisterLocalPostApplicationServiceTest {
fun actorが見つからないと失敗() = runTest {
assertThrows<InternalServerException> {
service.execute(
RegisterLocalPost("content test", null, Visibility.PUBLIC, null, null, false, emptyList()), FromApi(
RegisterLocalPost("content test", null, Visibility.PUBLIC, null, null, false, emptyList()), LocalUser(
ActorId(1), UserDetailId(1), Acct("test", "example.com")
)
)

View File

@ -8,7 +8,7 @@ import dev.usbharu.hideout.core.domain.model.actor.TestActorFactory
import dev.usbharu.hideout.core.domain.model.post.*
import dev.usbharu.hideout.core.domain.model.post.Post
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailHashedPassword
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
@ -63,7 +63,7 @@ class UpdateLocalNoteApplicationServiceTest {
whenever(postContentFactoryImpl.create(eq("test"))).doReturn(content)
service.execute(
UpdateLocalNote(post.id.id, null, "test", false, emptyList()), FromApi(
UpdateLocalNote(post.id.id, null, "test", false, emptyList()), LocalUser(
post.actorId,
UserDetailId(1),
Acct("test", "example.com")
@ -84,7 +84,7 @@ class UpdateLocalNoteApplicationServiceTest {
fun postが見つからない場合失敗() = runTest {
assertThrows<IllegalArgumentException> {
service.execute(
UpdateLocalNote(1, null, "test", false, emptyList()), FromApi(
UpdateLocalNote(1, null, "test", false, emptyList()), LocalUser(
ActorId(1),
UserDetailId(1), Acct("test", "example.com")
)
@ -98,7 +98,7 @@ class UpdateLocalNoteApplicationServiceTest {
assertThrows<PermissionDeniedException> {
service.execute(
UpdateLocalNote(1, null, "test", false, emptyList()), FromApi(
UpdateLocalNote(1, null, "test", false, emptyList()), LocalUser(
ActorId(1),
UserDetailId(1), Acct("test", "example.com")
)
@ -112,7 +112,7 @@ class UpdateLocalNoteApplicationServiceTest {
assertThrows<InternalServerException> {
service.execute(
UpdateLocalNote(1, null, "test", false, emptyList()), FromApi(
UpdateLocalNote(1, null, "test", false, emptyList()), LocalUser(
ActorId(1),
UserDetailId(1), Acct("test", "example.com")
)
@ -138,7 +138,7 @@ class UpdateLocalNoteApplicationServiceTest {
assertThrows<InternalServerException> {
service.execute(
UpdateLocalNote(post.id.id, null, "test", false, emptyList()), FromApi(
UpdateLocalNote(post.id.id, null, "test", false, emptyList()), LocalUser(
post.actorId,
UserDetailId(1),
Acct("test", "example.com")

View File

@ -7,7 +7,7 @@ import dev.usbharu.hideout.core.domain.model.actor.TestActorFactory
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertFalse
@ -42,7 +42,7 @@ class UserAcceptFollowRequestApplicationServiceTest {
@Test
fun actorが見つからない場合失敗() = runTest {
assertThrows<InternalServerException> {
service.execute(AcceptFollowRequest(1), FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com")))
service.execute(AcceptFollowRequest(1), LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com")))
}
}
@ -51,7 +51,7 @@ class UserAcceptFollowRequestApplicationServiceTest {
whenever(actorRepository.findById(ActorId(2))).doReturn(TestActorFactory.create(id = 2))
assertThrows<InternalServerException> {
service.execute(AcceptFollowRequest(1), FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com")))
service.execute(AcceptFollowRequest(1), LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com")))
}
}
@ -68,7 +68,7 @@ class UserAcceptFollowRequestApplicationServiceTest {
followRequesting = true, mutingFollowRequest = false
)
)
service.execute(AcceptFollowRequest(1), FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com")))
service.execute(AcceptFollowRequest(1), LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com")))
argumentCaptor<Relationship> {
verify(relationshipRepository).save(capture())

View File

@ -2,7 +2,7 @@ package dev.usbharu.hideout.core.application.shared
import dev.usbharu.hideout.core.application.exception.PermissionDeniedException
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import org.slf4j.LoggerFactory
@ -13,7 +13,7 @@ class LocalUserAbstractApplicationServiceTest {
fun requireFromAPI() = runTest {
val logger = LoggerFactory.getLogger(javaClass)
val value = object : LocalUserAbstractApplicationService<Unit, Unit>(TestTransaction, logger) {
override suspend fun internalExecute(command: Unit, principal: FromApi) {
override suspend fun internalExecute(command: Unit, principal: LocalUser) {
}
}

View File

@ -7,7 +7,7 @@ import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertFalse
@ -44,7 +44,7 @@ class DefaultPostReadAccessControlTest {
val actual = service.isAllow(
TestPostFactory.create(actorId = 1),
FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
)
assertFalse(actual)
@ -72,7 +72,7 @@ class DefaultPostReadAccessControlTest {
fun DirectでvisibleActorsに含まれていたら見れる() = runTest {
val actual = service.isAllow(
TestPostFactory.create(actorId = 1, visibility = Visibility.DIRECT, visibleActors = listOf(2)),
FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
)
assertTrue(actual)
@ -82,7 +82,7 @@ class DefaultPostReadAccessControlTest {
fun DirectでvisibleActorsに含まれていなかったら見れない() = runTest {
val actual = service.isAllow(
TestPostFactory.create(actorId = 1, visibility = Visibility.DIRECT, visibleActors = listOf(3)),
FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
)
assertFalse(actual)
@ -111,7 +111,7 @@ class DefaultPostReadAccessControlTest {
val actual = service.isAllow(
TestPostFactory.create(actorId = 1, visibility = Visibility.FOLLOWERS),
FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
)
assertTrue(actual)
@ -121,7 +121,7 @@ class DefaultPostReadAccessControlTest {
fun relationshipが見つからない場合見れない() = runTest {
val actual = service.isAllow(
TestPostFactory.create(actorId = 1, visibility = Visibility.FOLLOWERS),
FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
)
assertFalse(actual)
@ -150,7 +150,7 @@ class DefaultPostReadAccessControlTest {
val actual = service.isAllow(
TestPostFactory.create(actorId = 1, visibility = Visibility.FOLLOWERS),
FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com"))
)
assertFalse(actual)

View File

@ -97,6 +97,10 @@ tasks {
importMappings.put("org.springframework.core.io.Resource", "org.springframework.web.multipart.MultipartFile")
typeMappings.put("org.springframework.core.io.Resource", "org.springframework.web.multipart.MultipartFile")
schemaMappings.put(
"StatusesRequest",
"dev.usbharu.hideout.mastodon.interfaces.api.StatusesRequest"
)
templateDir.set("$rootDir/templates")
}
}

View File

@ -18,7 +18,7 @@ package dev.usbharu.hideout.mastodon.application.accounts
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.Account
import dev.usbharu.hideout.mastodon.query.AccountQueryService
import org.slf4j.LoggerFactory
@ -30,7 +30,7 @@ class GetAccountApplicationService(private val accountQueryService: AccountQuery
transaction,
logger
) {
override suspend fun internalExecute(command: GetAccount, principal: FromApi): Account {
override suspend fun internalExecute(command: GetAccount, principal: LocalUser): Account {
return accountQueryService.findById(command.accountId.toLong()) ?: throw Exception("Account not found")
}

View File

@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationS
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.filter.FilterKeywordId
import dev.usbharu.hideout.core.domain.model.filter.FilterRepository
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -30,7 +30,7 @@ class DeleteFilterV1ApplicationService(private val filterRepository: FilterRepos
LocalUserAbstractApplicationService<DeleteFilterV1, Unit>(
transaction, logger
) {
override suspend fun internalExecute(command: DeleteFilterV1, principal: FromApi) {
override suspend fun internalExecute(command: DeleteFilterV1, principal: LocalUser) {
val filter = filterRepository.findByFilterKeywordId(FilterKeywordId(command.filterKeywordId))
?: throw IllegalArgumentException("Filter ${command.filterKeywordId} not found")
if (principal.userDetailId != filter.userDetailId) {

View File

@ -16,9 +16,9 @@
package dev.usbharu.hideout.mastodon.application.status
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.Status
import dev.usbharu.hideout.mastodon.query.StatusQueryService
import org.slf4j.LoggerFactory
@ -28,7 +28,7 @@ import org.springframework.stereotype.Service
class GetStatusApplicationService(
private val statusQueryService: StatusQueryService,
transaction: Transaction,
) : LocalUserAbstractApplicationService<GetStatus, Status>(
) : AbstractApplicationService<GetStatus, Status>(
transaction,
logger
) {
@ -36,7 +36,7 @@ class GetStatusApplicationService(
val logger = LoggerFactory.getLogger(GetStatusApplicationService::class.java)!!
}
override suspend fun internalExecute(command: GetStatus, principal: FromApi): Status {
override suspend fun internalExecute(command: GetStatus, principal: Principal): Status {
return statusQueryService.findByPostId(command.id.toLong(), principal)
?: throw IllegalArgumentException("Post ${command.id} not found.")

View File

@ -79,11 +79,11 @@ class StatusQueryServiceImpl : StatusQueryService {
emojiIdSet.addAll(statusQueries.flatMap { it.emojiIds })
val qa = authorizedQuery()
val postMap = Posts
val replyToAlias = Posts.alias("reply_to")
val postMap = qa
.leftJoin(Actors)
.selectAll().where { Posts.id inList postIdSet }
.associate { it[Posts.id] to toStatus(it, qa) }
.associate { it[Posts.id] to toStatus(it, qa, replyToAlias) }
val mediaMap = Media.selectAll().where { Media.id inList mediaIdSet }
.associate {
it[Media.id] to it.toMedia().toMediaAttachments()
@ -112,6 +112,7 @@ class StatusQueryServiceImpl : StatusQueryService {
tagged: String?,
includeFollowers: Boolean,
): List<Status> {
val inReplyToAlias = Posts.alias("reply_to")
val qa = authorizedQuery()
val query = qa
.leftJoin(PostsMedia)
@ -138,7 +139,7 @@ class StatusQueryServiceImpl : StatusQueryService {
.groupBy { it[Posts.id] }
.map { it.value }
.map {
toStatus(it.first(), qa).copy(
toStatus(it.first(), qa, inReplyToAlias).copy(
mediaAttachments = it.mapNotNull { resultRow ->
resultRow.toMediaOrNull()?.toMediaAttachments()
}
@ -151,16 +152,18 @@ class StatusQueryServiceImpl : StatusQueryService {
override suspend fun findByPostId(id: Long, principal: Principal?): Status? {
val aq = authorizedQuery(principal)
val inReplyTo = Posts.alias("reply_to")
val map = aq
.leftJoin(PostsMedia, { aq[Posts.id] }, { PostsMedia.postId })
.leftJoin(Actors, { aq[Posts.actorId] }, { Actors.id })
.leftJoin(Media, { PostsMedia.mediaId }, { Media.id })
.leftJoin(inReplyTo, { aq[Posts.replyId] }, { inReplyTo[Posts.id] })
.selectAll()
.where { aq[Posts.id] eq id }
.groupBy { it[aq[Posts.id]] }
.map { it.value }
.map {
toStatus(it.first(), aq).copy(
toStatus(it.first(), aq, inReplyTo).copy(
mediaAttachments = it.mapNotNull { resultRow ->
resultRow.toMediaOrNull()?.toMediaAttachments()
},
@ -180,18 +183,10 @@ class StatusQueryServiceImpl : StatusQueryService {
it.first
}
}
.map {
if (it.inReplyToId != null) {
println("statuses trace: $statuses")
println("inReplyToId trace: ${it.inReplyToId}")
it.copy(inReplyToAccountId = statuses.find { (id) -> id == it.inReplyToId }?.account?.id)
} else {
it
}
}
}
private suspend fun findByPostIdsWithMedia(ids: List<Long>): List<Status> {
val inReplyToAlias = Posts.alias("reply_to")
val qa = authorizedQuery()
val pairs = Posts
.leftJoin(PostsMedia)
@ -203,7 +198,7 @@ class StatusQueryServiceImpl : StatusQueryService {
.groupBy { it[Posts.id] }
.map { it.value }
.map {
toStatus(it.first(), qa).copy(
toStatus(it.first(), qa, inReplyToAlias).copy(
mediaAttachments = it.mapNotNull { resultRow ->
resultRow.toMediaOrNull()?.toMediaAttachments()
},
@ -222,7 +217,7 @@ private fun CustomEmoji.toMastodonEmoji(): MastodonEmoji = MastodonEmoji(
category = this.category.orEmpty()
)
private fun toStatus(it: ResultRow, queryAlias: QueryAlias) = Status(
private fun toStatus(it: ResultRow, queryAlias: QueryAlias, inReplyToAlias: Alias<Posts>) = Status(
id = it[queryAlias[Posts.id]].toString(),
uri = it[queryAlias[Posts.apId]],
createdAt = it[queryAlias[Posts.createdAt]].toString(),
@ -271,7 +266,7 @@ private fun toStatus(it: ResultRow, queryAlias: QueryAlias) = Status(
repliesCount = 0,
url = it[queryAlias[Posts.apId]],
inReplyToId = it[queryAlias[Posts.replyId]]?.toString(),
inReplyToAccountId = null,
inReplyToAccountId = it.getOrNull(inReplyToAlias[Posts.actorId])?.toString(),
language = null,
text = it[queryAlias[Posts.text]],
editedAt = null
@ -305,12 +300,12 @@ 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 = MediaDescription(this[Media.description] ?: return null)
description = this[Media.description]?.let { MediaDescription(it) }
)
}
fun EntityMedia.toMediaAttachments(): MediaAttachment = MediaAttachment(
id = id.toString(),
id = id.id.toString(),
type = when (type) {
FileType.Image -> MediaAttachment.Type.image
FileType.Video -> MediaAttachment.Type.video

View File

@ -20,7 +20,7 @@ import dev.usbharu.hideout.core.application.filter.*
import dev.usbharu.hideout.core.domain.model.filter.FilterAction
import dev.usbharu.hideout.core.domain.model.filter.FilterContext
import dev.usbharu.hideout.core.domain.model.filter.FilterMode
import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder
import dev.usbharu.hideout.mastodon.application.filter.DeleteFilterV1
import dev.usbharu.hideout.mastodon.application.filter.DeleteFilterV1ApplicationService
import dev.usbharu.hideout.mastodon.application.filter.GetFilterV1
@ -41,7 +41,7 @@ class SpringFilterApi(
private val deleteFilterV1ApplicationService: DeleteFilterV1ApplicationService,
private val userDeleteFilterApplicationService: UserDeleteFilterApplicationService,
private val userGetFilterApplicationService: UserGetFilterApplicationService,
private val principalContextHolder: PrincipalContextHolder
private val principalContextHolder: SpringSecurityOauth2PrincipalContextHolder
) : FilterApi {
override suspend fun apiV1FiltersIdDelete(id: String): ResponseEntity<Any> {

View File

@ -19,7 +19,7 @@ package dev.usbharu.hideout.mastodon.interfaces.api
import dev.usbharu.hideout.core.application.media.UploadMedia
import dev.usbharu.hideout.core.application.media.UploadMediaApplicationService
import dev.usbharu.hideout.core.domain.model.media.FileType.*
import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder
import dev.usbharu.hideout.mastodon.interfaces.api.generated.MediaApi
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.MediaAttachment
import org.springframework.http.ResponseEntity
@ -30,7 +30,7 @@ import java.nio.file.Files
@Controller
class SpringMediaApi(
private val uploadMediaApplicationService: UploadMediaApplicationService,
private val principalContextHolder: PrincipalContextHolder
private val principalContextHolder: SpringSecurityOauth2PrincipalContextHolder
) : MediaApi {
override suspend fun apiV1MediaPost(
file: MultipartFile,

View File

@ -19,13 +19,12 @@ package dev.usbharu.hideout.mastodon.interfaces.api
import dev.usbharu.hideout.core.application.post.RegisterLocalPost
import dev.usbharu.hideout.core.application.post.RegisterLocalPostApplicationService
import dev.usbharu.hideout.core.domain.model.post.Visibility
import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder
import dev.usbharu.hideout.mastodon.application.status.GetStatus
import dev.usbharu.hideout.mastodon.application.status.GetStatusApplicationService
import dev.usbharu.hideout.mastodon.interfaces.api.StatusesRequest.Visibility.*
import dev.usbharu.hideout.mastodon.interfaces.api.generated.StatusApi
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.Status
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.StatusesRequest
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.StatusesRequest.Visibility.*
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
@ -33,7 +32,7 @@ import org.springframework.stereotype.Controller
class SpringStatusApi(
private val registerLocalPostApplicationService: RegisterLocalPostApplicationService,
private val getStatusApplicationService: GetStatusApplicationService,
private val principalContextHolder: PrincipalContextHolder
private val principalContextHolder: SpringSecurityOauth2PrincipalContextHolder
) : StatusApi {
override suspend fun apiV1StatusesIdEmojiReactionsEmojiDelete(id: String, emoji: String): ResponseEntity<Status> {
return super.apiV1StatusesIdEmojiReactionsEmojiDelete(id, emoji)
@ -52,13 +51,13 @@ class SpringStatusApi(
)
}
override suspend fun apiV1StatusesPost(statusesRequest: StatusesRequest): ResponseEntity<Status> {
override suspend fun apiV1StatusesPost(statusesRequest: dev.usbharu.hideout.mastodon.interfaces.api.StatusesRequest): ResponseEntity<Status> {
val principal = principalContextHolder.getPrincipal()
val execute = registerLocalPostApplicationService.execute(
RegisterLocalPost(
content = statusesRequest.status.orEmpty(),
overview = statusesRequest.spoilerText,
overview = statusesRequest.spoiler_text,
visibility = when (statusesRequest.visibility) {
public -> Visibility.PUBLIC
unlisted -> Visibility.UNLISTED
@ -67,9 +66,9 @@ class SpringStatusApi(
null -> Visibility.PUBLIC
},
repostId = null,
replyId = statusesRequest.inReplyToId?.toLong(),
replyId = statusesRequest.in_reply_to_id?.toLong(),
sensitive = statusesRequest.sensitive == true,
mediaIds = statusesRequest.mediaIds.orEmpty().map { it.toLong() }
mediaIds = statusesRequest.media_ids.map { it.toLong() }
), principal
)

View File

@ -0,0 +1,100 @@
package dev.usbharu.hideout.mastodon.interfaces.api
import com.fasterxml.jackson.annotation.JsonProperty
import dev.usbharu.hideout.core.domain.model.post.Visibility
import dev.usbharu.hideout.mastodon.interfaces.api.StatusesRequest.Visibility.*
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.Status
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.StatusesRequestPoll
@Suppress("VariableNaming", "EnumEntryName")
class StatusesRequest {
@JsonProperty("status")
var status: String? = null
@JsonProperty("media_ids")
var media_ids: List<String> = emptyList()
@JsonProperty("poll")
var poll: StatusesRequestPoll? = null
@JsonProperty("in_reply_to_id")
var in_reply_to_id: String? = null
@JsonProperty("sensitive")
var sensitive: Boolean? = null
@JsonProperty("spoiler_text")
var spoiler_text: String? = null
@JsonProperty("visibility")
var visibility: Visibility? = null
@JsonProperty("language")
var language: String? = null
@JsonProperty("scheduled_at")
var scheduled_at: String? = null
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is StatusesRequest) return false
if (status != other.status) return false
if (media_ids != other.media_ids) return false
if (poll != other.poll) return false
if (in_reply_to_id != other.in_reply_to_id) return false
if (sensitive != other.sensitive) return false
if (spoiler_text != other.spoiler_text) return false
if (visibility != other.visibility) return false
if (language != other.language) return false
if (scheduled_at != other.scheduled_at) return false
return true
}
override fun hashCode(): Int {
var result = status?.hashCode() ?: 0
result = 31 * result + media_ids.hashCode()
result = 31 * result + (poll?.hashCode() ?: 0)
result = 31 * result + (in_reply_to_id?.hashCode() ?: 0)
result = 31 * result + (sensitive?.hashCode() ?: 0)
result = 31 * result + (spoiler_text?.hashCode() ?: 0)
result = 31 * result + (visibility?.hashCode() ?: 0)
result = 31 * result + (language?.hashCode() ?: 0)
result = 31 * result + (scheduled_at?.hashCode() ?: 0)
return result
}
override fun toString(): String {
return "StatusesRequest(status=$status, mediaIds=$media_ids, poll=$poll, inReplyToId=$in_reply_to_id, " +
"sensitive=$sensitive, spoilerText=$spoiler_text, visibility=$visibility, language=$language," +
" scheduledAt=$scheduled_at)"
}
@Suppress("EnumNaming", "EnumEntryNameCase")
enum class Visibility {
`public`,
unlisted,
private,
direct
}
}
fun StatusesRequest.Visibility?.toPostVisibility(): Visibility {
return when (this) {
public -> Visibility.PUBLIC
unlisted -> Visibility.UNLISTED
private -> Visibility.FOLLOWERS
direct -> Visibility.DIRECT
null -> Visibility.PUBLIC
}
}
fun StatusesRequest.Visibility?.toStatusVisibility(): Status.Visibility {
return when (this) {
public -> Status.Visibility.public
unlisted -> Status.Visibility.unlisted
private -> Status.Visibility.private
direct -> Status.Visibility.direct
null -> Status.Visibility.public
}
}

View File

@ -3,7 +3,7 @@ package dev.usbharu.hideout.mastodon.infrastructure.exposedquery
import dev.usbharu.hideout.SpringApplication
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertNull
@ -26,7 +26,7 @@ class StatusQueryServiceImplTest {
@Test
fun フォロワー限定をフォロワー以外は見れない() = runTest {
val status =
statusQueryServiceImpl.findByPostId(4, FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com")))
statusQueryServiceImpl.findByPostId(4, LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com")))
assertNull(status)
}