From 922bdb4991e35155b8563aed4d1be623bb933763 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 2 Jun 2024 16:04:30 +0900 Subject: [PATCH] wip --- .../activitypub/webfinger/WebFingerTest.kt | 2 +- .../kotlin/mastodon/status/StatusTest.kt | 2 - .../intTest/kotlin/util/TestTransaction.kt | 2 +- ...WithHttpSignatureSecurityContextFactory.kt | 2 +- .../application/config/SecurityConfig.kt | 2 +- .../application/external/OwlProducerRunner.kt | 1 - .../exposed/ExposedTransaction.kt | 2 +- .../application/service/init/MetaService.kt | 2 - .../service/init/MetaServiceImpl.kt | 5 +- .../init/ServerInitialiseServiceImpl.kt | 80 ------ .../DeleteLocalActorApplicationService.kt | 4 +- .../MigrationLocalActorApplicationService.kt | 4 +- .../actor/RegisterLocalActor.kt | 2 +- .../RegisterLocalActorApplicationService.kt | 4 +- ...AlsoKnownAsLocalActorApplicationService.kt | 2 +- .../SuspendLocalActorApplicationService.kt | 4 +- .../UnsuspendLocalActorApplicationService.kt | 4 +- .../post/DeleteLocalPostApplicationService.kt | 2 +- .../post/RegisterLocalPost.kt | 2 +- .../RegisterLocalPostApplicationService.kt | 2 +- .../post/UpdateLocalNote.kt | 2 +- .../post/UpdateLocalNoteApplicationService.kt | 4 +- .../application/shared}/Transaction.kt | 2 +- .../core/domain/model/emoji/CustomEmoji.kt | 17 +- .../core/domain/model/filter/Filter.kt | 25 -- .../core/domain/model/filter/FilterAction.kt | 23 -- .../domain/model/filter/FilterRepository.kt | 30 --- .../core/domain/model/filter/FilterType.kt | 26 -- .../model/filterkeyword/FilterKeyword.kt | 26 -- .../filterkeyword/FilterKeywordRepository.kt | 26 -- .../core/domain/model/instance/Nodeinfo.kt | 54 ---- .../core/domain/model/instance/Nodeinfo2_0.kt | 87 ------- .../model}/media/FileType.kt | 2 +- .../hideout/core/domain/model/media/Media.kt | 33 +-- .../FilterMode.kt => media/MediaBlurHash.kt} | 9 +- .../model/media/MediaDescription.kt} | 8 +- .../{meta/Meta.kt => media/MediaName.kt} | 5 +- .../model}/media/MimeType.kt | 2 +- .../hideout/core/domain/model/meta/Jwt.kt | 21 -- .../core/domain/model/meta/MetaRepository.kt | 27 -- .../domain/model/notification/Notification.kt | 30 --- .../notification/NotificationRepository.kt | 24 -- .../core/domain/model/reaction/Reaction.kt | 21 -- .../model/reaction/ReactionRepository.kt | 40 --- .../domain/model/relationship/Relationship.kt | 38 --- .../RelationshipRepositoryImpl.kt | 178 -------------- .../model/shared/domainevent/DomainEvent.kt | 37 --- .../shared/domainevent/DomainEventBody.kt | 23 -- .../core/domain/model/timeline/Timeline.kt | 42 ---- .../model/timeline/TimelineRepository.kt | 25 -- .../ExposedTimelineRepository.kt | 2 - .../exposedrepository/MediaRepositoryImpl.kt | 5 +- .../exposedrepository/MetaRepositoryImpl.kt | 2 - .../ReactionRepositoryImpl.kt | 232 ------------------ .../MongoTimelineRepository.kt | 35 --- .../MongoTimelineRepositoryWrapper.kt | 67 ----- .../HttpSignatureUserDetailsService.kt | 2 +- ...xposedOAuth2AuthorizationConsentService.kt | 2 +- .../ExposedOAuth2AuthorizationService.kt | 2 +- .../oauth2/UserDetailsServiceImpl.kt | 2 +- .../interfaces/api/auth/AuthController.kt | 8 +- .../query/model/ExposedFilterQueryService.kt | 76 ------ .../core/query/model/FilterQueryModel.kt | 43 ---- .../core/query/model/FilterQueryService.kt | 26 -- .../core/service/filter/FilterKeyword.kt | 24 -- .../core/service/filter/FilterResult.kt | 24 -- .../core/service/filter/MuteService.kt | 33 --- .../core/service/filter/MuteServiceImpl.kt | 66 ----- .../service/instance/InstanceCreateDto.kt | 27 -- .../core/service/instance/InstanceService.kt | 124 ---------- ...ApatcheTikaFileTypeDeterminationService.kt | 105 -------- .../media/FileTypeDeterminationService.kt | 24 -- .../media/LocalFileSystemMediaDataStore.kt | 131 ---------- .../service/media/MediaBlurhashService.kt | 23 -- .../service/media/MediaBlurhashServiceImpl.kt | 26 -- .../core/service/media/MediaDataStore.kt | 47 ---- .../service/media/MediaFileRenameService.kt | 30 --- .../hideout/core/service/media/MediaSave.kt | 49 ---- .../core/service/media/MediaSaveRequest.kt | 26 -- .../core/service/media/MediaService.kt | 25 -- .../core/service/media/MediaServiceImpl.kt | 218 ---------------- .../core/service/media/ProcessedFile.kt | 40 --- .../core/service/media/ProcessedMedia.kt | 22 -- .../core/service/media/ProcessedMediaPath.kt | 26 -- .../hideout/core/service/media/RemoteMedia.kt | 24 -- .../media/RemoteMediaDownloadService.kt | 23 -- .../media/RemoteMediaDownloadServiceImpl.kt | 61 ----- .../core/service/media/S3MediaDataStore.kt | 139 ----------- .../hideout/core/service/media/SavedMedia.kt | 87 ------- .../service/media/ThumbnailGenerateService.kt | 24 -- .../media/ThumbnailGenerateServiceImpl.kt | 42 ---- .../media/UUIDMediaFileRenameService.kt | 32 --- .../service/media/converter/MediaConverter.kt | 26 -- .../media/converter/MediaConverterRoot.kt | 30 --- .../media/converter/MediaConverterRootImpl.kt | 48 ---- .../media/converter/MediaProcessService.kt | 42 ---- .../converter/MediaProcessServiceImpl.kt | 74 ------ .../image/ImageMediaProcessService.kt | 131 ---------- .../image/ImageMediaProcessorConfiguration.kt | 33 --- .../movie/MovieMediaProcessService.kt | 143 ----------- .../notification/NotificationRequest.kt | 136 ---------- .../notification/NotificationService.kt | 24 -- .../notification/NotificationServiceImpl.kt | 110 --------- ...lationshipNotificationManagementService.kt | 23 -- ...onshipNotificationManagementServiceImpl.kt | 26 -- .../post/DefaultPostContentFormatter.kt | 99 -------- .../core/service/post/PostContentFormatter.kt | 21 -- .../core/service/post/PostCreateDto.kt | 29 --- .../core/service/reaction/ReactionService.kt | 28 --- .../service/reaction/ReactionServiceImpl.kt | 101 -------- .../core/service/resource/CacheManager.kt | 22 -- .../service/resource/InMemoryCacheManager.kt | 71 ------ .../service/resource/KtorResolveResponse.kt | 66 ----- .../resource/KtorResourceResolveService.kt | 53 ---- .../core/service/resource/ResolveResponse.kt | 28 --- .../resource/ResourceResolveService.kt | 21 -- .../ExposedGenerateTimelineService.kt | 68 ----- .../timeline/GenerateTimelineService.kt | 34 --- .../timeline/MongoGenerateTimelineService.kt | 89 ------- .../core/service/user/UserCreateDto.kt | 24 -- .../usbharu/hideout/util/CollectionUtil.kt | 29 --- .../dev/usbharu/hideout/util/HttpUtil.kt | 54 ---- .../usbharu/hideout/util/InstantParseUtil.kt | 34 --- .../dev/usbharu/hideout/util/LruCache.kt | 35 --- .../dev/usbharu/hideout/util/RsaUtil.kt | 5 - .../dev/usbharu/hideout/util/ServerUtil.kt | 22 -- .../dev/usbharu/hideout/util/TempFileUtil.kt | 39 --- .../service/init/MetaServiceImplTest.kt | 3 - .../init/ServerInitialiseServiceImplTest.kt | 73 ------ ...ipNotificationManagementServiceImplTest.kt | 2 +- .../RelationshipServiceImplTest.kt | 2 +- .../service/timeline/TimelineServiceTest.kt | 2 - .../core/service/user/ActorServiceTest.kt | 1 - .../account/AccountApiServiceImplTest.kt | 2 +- .../src/test/kotlin/utils/TestTransaction.kt | 2 +- .../hideout/worker/DeliverAcceptTaskRunner.kt | 2 +- .../hideout/worker/DeliverCreateTaskRunner.kt | 2 +- .../hideout/worker/DeliverRejectTaskRunner.kt | 2 +- .../hideout/worker/DeliverUndoTaskRunner.kt | 2 +- .../usbharu/hideout/worker/InboxTaskRunner.kt | 3 +- .../hideout/worker/ReceiveFollowTaskRunner.kt | 2 +- .../hideout/worker/UpdateActorWorker.kt | 2 +- 142 files changed, 72 insertions(+), 4891 deletions(-) delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/ServerInitialiseServiceImpl.kt rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/actor/DeleteLocalActorApplicationService.kt (91%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/actor/MigrationLocalActorApplicationService.kt (94%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/actor/RegisterLocalActor.kt (93%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/actor/RegisterLocalActorApplicationService.kt (96%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/actor/SetAlsoKnownAsLocalActorApplicationService.kt (77%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/actor/SuspendLocalActorApplicationService.kt (91%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/actor/UnsuspendLocalActorApplicationService.kt (90%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/post/DeleteLocalPostApplicationService.kt (95%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/post/RegisterLocalPost.kt (94%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/post/RegisterLocalPostApplicationService.kt (97%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/post/UpdateLocalNote.kt (93%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{usecase => application}/post/UpdateLocalNoteApplicationService.kt (93%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/{application/external => core/application/shared}/Transaction.kt (94%) delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/Filter.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterAction.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterRepository.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterType.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filterkeyword/FilterKeyword.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filterkeyword/FilterKeywordRepository.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{service => domain/model}/media/FileType.kt (92%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/{filter/FilterMode.kt => media/MediaBlurHash.kt} (83%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{service/post/FormattedPostContent.kt => domain/model/media/MediaDescription.kt} (82%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/{meta/Meta.kt => media/MediaName.kt} (85%) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/{service => domain/model}/media/MimeType.kt (92%) delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/meta/Jwt.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/meta/MetaRepository.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/Notification.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/NotificationRepository.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/Reaction.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEvent.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventBody.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/TimelineRepository.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoTimelineRepository.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoTimelineRepositoryWrapper.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/ExposedFilterQueryService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/FilterQueryModel.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/FilterQueryService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/FilterKeyword.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/FilterResult.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/MuteService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/MuteServiceImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceCreateDto.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ApatcheTikaFileTypeDeterminationService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/FileTypeDeterminationService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/LocalFileSystemMediaDataStore.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaBlurhashService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaBlurhashServiceImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaDataStore.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaFileRenameService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSaveRequest.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedMedia.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedMediaPath.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMedia.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadServiceImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/S3MediaDataStore.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ThumbnailGenerateService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ThumbnailGenerateServiceImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/UUIDMediaFileRenameService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverter.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverterRoot.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverterRootImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaProcessService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaProcessServiceImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessorConfiguration.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/movie/MovieMediaProcessService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationRequest.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationServiceImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementServiceImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostContentFormatter.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostCreateDto.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/CacheManager.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResolveResponse.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResourceResolveService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/ResolveResponse.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/ResourceResolveService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/ExposedGenerateTimelineService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/GenerateTimelineService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/MongoGenerateTimelineService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserCreateDto.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/util/CollectionUtil.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/util/InstantParseUtil.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/util/LruCache.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/util/ServerUtil.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt delete mode 100644 hideout-core/src/test/kotlin/dev/usbharu/hideout/application/service/init/ServerInitialiseServiceImplTest.kt diff --git a/hideout-core/src/intTest/kotlin/activitypub/webfinger/WebFingerTest.kt b/hideout-core/src/intTest/kotlin/activitypub/webfinger/WebFingerTest.kt index a12bbfd4..e7532b18 100644 --- a/hideout-core/src/intTest/kotlin/activitypub/webfinger/WebFingerTest.kt +++ b/hideout-core/src/intTest/kotlin/activitypub/webfinger/WebFingerTest.kt @@ -17,7 +17,7 @@ package activitypub.webfinger import dev.usbharu.hideout.SpringApplication -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.owl.producer.api.OwlProducer import kotlinx.coroutines.runBlocking import org.flywaydb.core.Flyway diff --git a/hideout-core/src/intTest/kotlin/mastodon/status/StatusTest.kt b/hideout-core/src/intTest/kotlin/mastodon/status/StatusTest.kt index 817d5dfc..d3028a0d 100644 --- a/hideout-core/src/intTest/kotlin/mastodon/status/StatusTest.kt +++ b/hideout-core/src/intTest/kotlin/mastodon/status/StatusTest.kt @@ -20,8 +20,6 @@ import dev.usbharu.hideout.SpringApplication import dev.usbharu.hideout.core.domain.model.emoji.CustomEmoji import dev.usbharu.hideout.core.domain.model.emoji.UnicodeEmoji import dev.usbharu.hideout.core.infrastructure.exposedrepository.CustomEmojis -import dev.usbharu.hideout.core.infrastructure.exposedrepository.Reactions -import dev.usbharu.hideout.core.infrastructure.exposedrepository.toReaction import dev.usbharu.owl.producer.api.OwlProducer import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat diff --git a/hideout-core/src/intTest/kotlin/util/TestTransaction.kt b/hideout-core/src/intTest/kotlin/util/TestTransaction.kt index 72c3b42b..0f8b6317 100644 --- a/hideout-core/src/intTest/kotlin/util/TestTransaction.kt +++ b/hideout-core/src/intTest/kotlin/util/TestTransaction.kt @@ -16,7 +16,7 @@ package util -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction object TestTransaction : Transaction { override suspend fun transaction(block: suspend () -> T): T = block() diff --git a/hideout-core/src/intTest/kotlin/util/WithHttpSignatureSecurityContextFactory.kt b/hideout-core/src/intTest/kotlin/util/WithHttpSignatureSecurityContextFactory.kt index f20da72f..ab161ca7 100644 --- a/hideout-core/src/intTest/kotlin/util/WithHttpSignatureSecurityContextFactory.kt +++ b/hideout-core/src/intTest/kotlin/util/WithHttpSignatureSecurityContextFactory.kt @@ -16,7 +16,7 @@ package util -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.exception.resource.UserNotFoundException import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureUser import dev.usbharu.httpsignature.common.HttpHeaders diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt index d51ae754..837a261c 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt @@ -25,7 +25,7 @@ import com.nimbusds.jose.jwk.source.JWKSource import com.nimbusds.jose.proc.SecurityContext import dev.usbharu.hideout.activitypub.domain.model.StringORObjectSerializer import dev.usbharu.hideout.activitypub.domain.model.StringOrObject -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureFilter import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureHeaderChecker import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureUserDetailsService diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/OwlProducerRunner.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/OwlProducerRunner.kt index ca86bce1..5df20246 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/OwlProducerRunner.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/OwlProducerRunner.kt @@ -35,7 +35,6 @@ class OwlProducerRunner(private val owlProducer: OwlProducer, private val taskDe } override fun destroy() { - System.err.println("destroy aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") runBlocking { owlProducer.stop() } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/ExposedTransaction.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/ExposedTransaction.kt index bdc84fba..8e380cb6 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/ExposedTransaction.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/ExposedTransaction.kt @@ -16,7 +16,7 @@ package dev.usbharu.hideout.application.infrastructure.exposed -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import kotlinx.coroutines.runBlocking import kotlinx.coroutines.slf4j.MDCContext import org.jetbrains.exposed.sql.Slf4jSqlDebugLogger diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaService.kt index 6d394617..32615016 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaService.kt @@ -16,8 +16,6 @@ package dev.usbharu.hideout.application.service.init -import dev.usbharu.hideout.core.domain.model.meta.Jwt -import dev.usbharu.hideout.core.domain.model.meta.Meta import org.springframework.stereotype.Service @Service diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaServiceImpl.kt index b801ba1e..3ca63744 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaServiceImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaServiceImpl.kt @@ -16,11 +16,8 @@ package dev.usbharu.hideout.application.service.init -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.exception.NotInitException -import dev.usbharu.hideout.core.domain.model.meta.Jwt -import dev.usbharu.hideout.core.domain.model.meta.Meta -import dev.usbharu.hideout.core.domain.model.meta.MetaRepository import org.springframework.stereotype.Service @Service diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/ServerInitialiseServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/ServerInitialiseServiceImpl.kt deleted file mode 100644 index 323b78d7..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/ServerInitialiseServiceImpl.kt +++ /dev/null @@ -1,80 +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.application.service.init - -import dev.usbharu.hideout.application.external.Transaction -import dev.usbharu.hideout.core.domain.model.meta.Jwt -import dev.usbharu.hideout.core.domain.model.meta.Meta -import dev.usbharu.hideout.core.domain.model.meta.MetaRepository -import dev.usbharu.hideout.util.ServerUtil -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service -import java.security.KeyPairGenerator -import java.util.* - -@Service -class ServerInitialiseServiceImpl( - private val metaRepository: MetaRepository, - private val transaction: Transaction -) : - ServerInitialiseService { - - val logger: Logger = LoggerFactory.getLogger(ServerInitialiseServiceImpl::class.java) - - override suspend fun init() { - transaction.transaction { - val savedMeta = metaRepository.get() - val implementationVersion = ServerUtil.getImplementationVersion() - if (wasInitialised(savedMeta).not()) { - logger.info("Start Initialise") - initialise(implementationVersion) - logger.info("Finish Initialise") - return@transaction - } - - if (isVersionChanged(requireNotNull(savedMeta))) { - logger.info("Version changed!! (${savedMeta.version} -> $implementationVersion)") - updateVersion(savedMeta, implementationVersion) - } - } - } - - private fun wasInitialised(meta: Meta?): Boolean { - logger.debug("Initialise checking...") - return meta != null - } - - private fun isVersionChanged(meta: Meta): Boolean = meta.version != ServerUtil.getImplementationVersion() - - private suspend fun initialise(implementationVersion: String) { - val keyPairGenerator = KeyPairGenerator.getInstance("RSA") - keyPairGenerator.initialize(2048) - val generateKeyPair = keyPairGenerator.generateKeyPair() - val jwt = Jwt( - UUID.randomUUID(), - Base64.getEncoder().encodeToString(generateKeyPair.private.encoded), - Base64.getEncoder().encodeToString(generateKeyPair.public.encoded) - ) - val meta = Meta(implementationVersion, jwt) - metaRepository.save(meta) - } - - private suspend fun updateVersion(meta: Meta, version: String) { - metaRepository.save(meta.copy(version = version)) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/DeleteLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/DeleteLocalActorApplicationService.kt similarity index 91% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/DeleteLocalActorApplicationService.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/DeleteLocalActorApplicationService.kt index be22d34d..cc6300c5 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/DeleteLocalActorApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/DeleteLocalActorApplicationService.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.usecase.actor +package dev.usbharu.hideout.core.application.actor -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.Actor2Repository import dev.usbharu.hideout.core.domain.model.actor.ActorId import org.springframework.stereotype.Service diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/MigrationLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/MigrationLocalActorApplicationService.kt similarity index 94% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/MigrationLocalActorApplicationService.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/MigrationLocalActorApplicationService.kt index a4f38e1c..0ff97802 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/MigrationLocalActorApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/MigrationLocalActorApplicationService.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.usecase.actor +package dev.usbharu.hideout.core.application.actor -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.Actor2Repository import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.service.actor.local.AccountMigrationCheck.* diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/RegisterLocalActor.kt similarity index 93% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActor.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/RegisterLocalActor.kt index 8031a87c..b54f2504 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActor.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/RegisterLocalActor.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.usecase.actor +package dev.usbharu.hideout.core.application.actor data class RegisterLocalActor( val name: String, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/RegisterLocalActorApplicationService.kt similarity index 96% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActorApplicationService.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/RegisterLocalActorApplicationService.kt index d93a7c0a..d0cc63a7 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActorApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/RegisterLocalActorApplicationService.kt @@ -14,11 +14,11 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.usecase.actor +package dev.usbharu.hideout.core.application.actor import dev.usbharu.hideout.application.config.ApplicationConfig -import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.application.service.id.IdGenerateService +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.Actor2Repository import dev.usbharu.hideout.core.domain.model.instance.InstanceRepository import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/SetAlsoKnownAsLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SetAlsoKnownAsLocalActorApplicationService.kt similarity index 77% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/SetAlsoKnownAsLocalActorApplicationService.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SetAlsoKnownAsLocalActorApplicationService.kt index 772385d8..fe69e97d 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/SetAlsoKnownAsLocalActorApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SetAlsoKnownAsLocalActorApplicationService.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.core.usecase.actor +package dev.usbharu.hideout.core.application.actor import org.springframework.stereotype.Service diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/SuspendLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SuspendLocalActorApplicationService.kt similarity index 91% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/SuspendLocalActorApplicationService.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SuspendLocalActorApplicationService.kt index 08c78483..ab07d9ed 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/SuspendLocalActorApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SuspendLocalActorApplicationService.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.usecase.actor +package dev.usbharu.hideout.core.application.actor -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.Actor2Repository import dev.usbharu.hideout.core.domain.model.actor.ActorId import org.springframework.stereotype.Service diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/UnsuspendLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/UnsuspendLocalActorApplicationService.kt similarity index 90% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/UnsuspendLocalActorApplicationService.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/UnsuspendLocalActorApplicationService.kt index 962e9e2b..1948b0ea 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/UnsuspendLocalActorApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/UnsuspendLocalActorApplicationService.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.usecase.actor +package dev.usbharu.hideout.core.application.actor -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.Actor2Repository import dev.usbharu.hideout.core.domain.model.actor.ActorId import org.springframework.stereotype.Service diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/DeleteLocalPostApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationService.kt similarity index 95% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/DeleteLocalPostApplicationService.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationService.kt index 80fd74ca..46388563 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/DeleteLocalPostApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationService.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.usecase.post +package dev.usbharu.hideout.core.application.post import dev.usbharu.hideout.core.domain.model.post.Post2Repository import dev.usbharu.hideout.core.domain.model.post.PostId diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPost.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPost.kt similarity index 94% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPost.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPost.kt index 025991d9..b5a6740b 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPost.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPost.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.usecase.post +package dev.usbharu.hideout.core.application.post import dev.usbharu.hideout.core.domain.model.post.Visibility diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPostApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt similarity index 97% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPostApplicationService.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt index e08bffb2..99049b92 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPostApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.usecase.post +package dev.usbharu.hideout.core.application.post import dev.usbharu.hideout.core.domain.model.actor.Actor2Repository import dev.usbharu.hideout.core.domain.model.actor.ActorId diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNote.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNote.kt similarity index 93% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNote.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNote.kt index 318c010a..a8dcfb1a 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNote.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNote.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.usecase.post +package dev.usbharu.hideout.core.application.post data class UpdateLocalNote( val postId: Long, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNoteApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationService.kt similarity index 93% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNoteApplicationService.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationService.kt index d7aaa905..5df3f5f9 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNoteApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationService.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.usecase.post +package dev.usbharu.hideout.core.application.post -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.media.MediaId import dev.usbharu.hideout.core.domain.model.post.Post2Repository import dev.usbharu.hideout.core.domain.model.post.PostId diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/Transaction.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/Transaction.kt similarity index 94% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/Transaction.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/Transaction.kt index f08e257f..5dc4df1b 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/Transaction.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/Transaction.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package dev.usbharu.hideout.application.external +package dev.usbharu.hideout.core.application.shared import org.springframework.stereotype.Service diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt index b50b29df..34240b2e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt @@ -16,10 +16,13 @@ package dev.usbharu.hideout.core.domain.model.emoji +import dev.usbharu.hideout.core.domain.model.instance.InstanceId +import dev.usbharu.hideout.core.domain.model.shared.Domain +import java.net.URI import java.time.Instant sealed class Emoji { - abstract val domain: String + abstract val domain: Domain abstract val name: String @Suppress("FunctionMinLength") @@ -33,13 +36,13 @@ sealed class Emoji { } data class CustomEmoji( - val id: Long, + val id: EmojiId, override val name: String, - override val domain: String, - val instanceId: Long?, - val url: String, + override val domain: Domain, + val instanceId: InstanceId, + val url: URI, val category: String?, - val createdAt: Instant + val createdAt: Instant, ) : Emoji() { override fun id(): String = id.toString() } @@ -47,6 +50,6 @@ data class CustomEmoji( data class UnicodeEmoji( override val name: String ) : Emoji() { - override val domain: String = "unicode.org" + override val domain: Domain = Domain("unicode.org") override fun id(): String = name } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/Filter.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/Filter.kt deleted file mode 100644 index 10bffd91..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/Filter.kt +++ /dev/null @@ -1,25 +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.core.domain.model.filter - -data class Filter( - val id: Long, - val userId: Long, - val name: String, - val context: List, - val filterAction: FilterAction, -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterAction.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterAction.kt deleted file mode 100644 index 6eca79d8..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterAction.kt +++ /dev/null @@ -1,23 +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.core.domain.model.filter - -@Suppress("EnumEntryNameCase", "EnumNaming") -enum class FilterAction { - warn, - hide -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterRepository.kt deleted file mode 100644 index ef0ba01b..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterRepository.kt +++ /dev/null @@ -1,30 +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.core.domain.model.filter - -interface FilterRepository { - - suspend fun generateId(): Long - suspend fun save(filter: Filter): Filter - suspend fun findById(id: Long): Filter? - - suspend fun findByUserIdAndId(userId: Long, id: Long): Filter? - suspend fun findByUserIdAndType(userId: Long, types: List): List - suspend fun deleteById(id: Long) - - suspend fun deleteByUserIdAndId(userId: Long, id: Long) -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterType.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterType.kt deleted file mode 100644 index be815999..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterType.kt +++ /dev/null @@ -1,26 +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.core.domain.model.filter - -@Suppress("EnumEntryNameCase", "EnumNaming") -enum class FilterType { - home, - notifications, - public, - thread, - account -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filterkeyword/FilterKeyword.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filterkeyword/FilterKeyword.kt deleted file mode 100644 index d6457116..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filterkeyword/FilterKeyword.kt +++ /dev/null @@ -1,26 +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.core.domain.model.filterkeyword - -import dev.usbharu.hideout.core.domain.model.filter.FilterMode - -data class FilterKeyword( - val id: Long, - val filterId: Long, - val keyword: String, - val mode: FilterMode -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filterkeyword/FilterKeywordRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filterkeyword/FilterKeywordRepository.kt deleted file mode 100644 index eae3bdde..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filterkeyword/FilterKeywordRepository.kt +++ /dev/null @@ -1,26 +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.core.domain.model.filterkeyword - -interface FilterKeywordRepository { - suspend fun generateId(): Long - suspend fun save(filterKeyword: FilterKeyword): FilterKeyword - suspend fun saveAll(filterKeywordList: List) - suspend fun findById(id: Long): FilterKeyword? - suspend fun deleteById(id: Long) - suspend fun deleteByFilterId(filterId: Long) -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt deleted file mode 100644 index d1c60cd7..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt +++ /dev/null @@ -1,54 +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.core.domain.model.instance - -class Nodeinfo private constructor() { - - var links: List = emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as Nodeinfo - - return links == other.links - } - - override fun hashCode(): Int = links.hashCode() -} - -class Links private constructor() { - var rel: String? = null - var href: String? = null - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as Links - - if (rel != other.rel) return false - if (href != other.href) return false - - return true - } - - override fun hashCode(): Int { - var result = rel?.hashCode() ?: 0 - result = 31 * result + (href?.hashCode() ?: 0) - return result - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt deleted file mode 100644 index efa0da33..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt +++ /dev/null @@ -1,87 +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. - */ - -@file:Suppress("Filename") - -package dev.usbharu.hideout.core.domain.model.instance - -@Suppress("ClassNaming") -class Nodeinfo2_0 { - var metadata: Metadata? = null - var software: Software? = null - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as Nodeinfo2_0 - - if (metadata != other.metadata) return false - if (software != other.software) return false - - return true - } - - override fun hashCode(): Int { - var result = metadata?.hashCode() ?: 0 - result = 31 * result + (software?.hashCode() ?: 0) - return result - } -} - -class Metadata { - var nodeName: String? = null - var nodeDescription: String? = null - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as Metadata - - if (nodeName != other.nodeName) return false - if (nodeDescription != other.nodeDescription) return false - - return true - } - - override fun hashCode(): Int { - var result = nodeName?.hashCode() ?: 0 - result = 31 * result + (nodeDescription?.hashCode() ?: 0) - return result - } -} - -class Software { - var name: String? = null - var version: String? = null - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as Software - - if (name != other.name) return false - if (version != other.version) return false - - return true - } - - override fun hashCode(): Int { - var result = name?.hashCode() ?: 0 - result = 31 * result + (version?.hashCode() ?: 0) - return result - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/FileType.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/FileType.kt similarity index 92% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/FileType.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/FileType.kt index 111b85a7..9d2b8837 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/FileType.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/FileType.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.service.media +package dev.usbharu.hideout.core.domain.model.media enum class FileType { Image, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt index fe9f2883..06b5c92f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt @@ -16,34 +16,17 @@ package dev.usbharu.hideout.core.domain.model.media -import dev.usbharu.hideout.core.service.media.FileType -import dev.usbharu.hideout.core.service.media.MimeType -import dev.usbharu.hideout.domain.mastodon.model.generated.MediaAttachment +import java.net.URI data class Media( - val id: Long, - val name: String, - val url: String, - val remoteUrl: String?, - val thumbnailUrl: String?, + val id: MediaId, + val name: MediaName, + val url: URI, + val remoteUrl: URI?, + val thumbnailUrl: URI?, val type: FileType, val mimeType: MimeType, - val blurHash: String?, - val description: String? = null + val blurHash: MediaBlurHash?, + val description: MediaDescription? = null, ) -fun Media.toMediaAttachments(): MediaAttachment = MediaAttachment( - id = id.toString(), - type = when (type) { - FileType.Image -> MediaAttachment.Type.image - FileType.Video -> MediaAttachment.Type.video - FileType.Audio -> MediaAttachment.Type.audio - FileType.Unknown -> MediaAttachment.Type.unknown - }, - url = url, - previewUrl = thumbnailUrl, - remoteUrl = remoteUrl, - description = description, - blurhash = blurHash, - textUrl = url -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterMode.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaBlurHash.kt similarity index 83% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterMode.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaBlurHash.kt index 10a20ec5..ceee5d85 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterMode.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaBlurHash.kt @@ -14,10 +14,7 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.domain.model.filter +package dev.usbharu.hideout.core.domain.model.media -enum class FilterMode { - WHOLE_WORD, - REGEX, - NONE -} +@JvmInline +value class MediaBlurHash(val hash: String) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/FormattedPostContent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaDescription.kt similarity index 82% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/FormattedPostContent.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaDescription.kt index 4dd62908..c99345b0 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/FormattedPostContent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaDescription.kt @@ -14,9 +14,7 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.service.post +package dev.usbharu.hideout.core.domain.model.media -data class FormattedPostContent( - val html: String, - val content: String -) +@JvmInline +value class MediaDescription(val description: String) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/meta/Meta.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaName.kt similarity index 85% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/meta/Meta.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaName.kt index e26594ae..58c483ac 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/meta/Meta.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaName.kt @@ -14,6 +14,7 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.domain.model.meta +package dev.usbharu.hideout.core.domain.model.media -data class Meta(val version: String, val jwt: Jwt) +@JvmInline +value class MediaName(val name: String) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MimeType.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MimeType.kt similarity index 92% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MimeType.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MimeType.kt index 0194f3b5..95cdcd99 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MimeType.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MimeType.kt @@ -14,6 +14,6 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.service.media +package dev.usbharu.hideout.core.domain.model.media data class MimeType(val type: String, val subtype: String, val fileType: FileType) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/meta/Jwt.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/meta/Jwt.kt deleted file mode 100644 index 0893efe5..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/meta/Jwt.kt +++ /dev/null @@ -1,21 +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.core.domain.model.meta - -import java.util.* - -data class Jwt(val kid: UUID, val privateKey: String, val publicKey: String) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/meta/MetaRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/meta/MetaRepository.kt deleted file mode 100644 index 31807823..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/meta/MetaRepository.kt +++ /dev/null @@ -1,27 +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.core.domain.model.meta - -import org.springframework.stereotype.Repository - -@Repository -interface MetaRepository { - - suspend fun save(meta: Meta) - - suspend fun get(): Meta? -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/Notification.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/Notification.kt deleted file mode 100644 index d97f9264..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/Notification.kt +++ /dev/null @@ -1,30 +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.core.domain.model.notification - -import java.time.Instant - -data class Notification( - val id: Long, - val type: String, - val userId: Long, - val sourceActorId: Long?, - val postId: Long?, - val text: String?, - val reactionId: Long?, - val createdAt: Instant -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/NotificationRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/NotificationRepository.kt deleted file mode 100644 index 24d557db..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/NotificationRepository.kt +++ /dev/null @@ -1,24 +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.core.domain.model.notification - -interface NotificationRepository { - suspend fun generateId(): Long - suspend fun save(notification: Notification): Notification - suspend fun findById(id: Long): Notification? - suspend fun deleteById(id: Long) -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/Reaction.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/Reaction.kt deleted file mode 100644 index e497788b..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/Reaction.kt +++ /dev/null @@ -1,21 +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.core.domain.model.reaction - -import dev.usbharu.hideout.core.domain.model.emoji.Emoji - -data class Reaction(val id: Long, val emoji: Emoji, val postId: Long, val actorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt deleted file mode 100644 index 493fcdac..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt +++ /dev/null @@ -1,40 +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.core.domain.model.reaction - -import dev.usbharu.hideout.core.domain.model.emoji.Emoji -import org.springframework.stereotype.Repository - -@Repository -@Suppress("FunctionMaxLength", "TooManyFunctions") -interface ReactionRepository { - suspend fun generateId(): Long - suspend fun save(reaction: Reaction): Reaction - suspend fun delete(reaction: Reaction): Reaction - suspend fun deleteByPostId(postId: Long): Int - suspend fun deleteByActorId(actorId: Long): Int - suspend fun deleteByPostIdAndActorId(postId: Long, actorId: Long) - suspend fun deleteByPostIdAndActorIdAndEmoji(postId: Long, actorId: Long, emoji: Emoji) - suspend fun findById(id: Long): Reaction? - suspend fun findByPostId(postId: Long): List - suspend fun findByPostIdAndActorIdAndEmojiId(postId: Long, actorId: Long, emojiId: Long): Reaction? - suspend fun existByPostIdAndActorIdAndEmojiId(postId: Long, actorId: Long, emojiId: Long): Boolean - suspend fun existByPostIdAndActorIdAndUnicodeEmoji(postId: Long, actorId: Long, unicodeEmoji: String): Boolean - suspend fun existByPostIdAndActorIdAndEmoji(postId: Long, actorId: Long, emoji: Emoji): Boolean - suspend fun existByPostIdAndActor(postId: Long, actorId: Long): Boolean - suspend fun findByPostIdAndActorId(postId: Long, actorId: Long): List -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt deleted file mode 100644 index cbdaa3ea..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt +++ /dev/null @@ -1,38 +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.core.domain.model.relationship - -/** - * ユーザーとの関係を表します - * - * @property actorId ユーザー - * @property targetActorId 相手ユーザー - * @property following フォローしているか - * @property blocking ブロックしているか - * @property muting ミュートしているか - * @property followRequest フォローリクエストを送っているか - * @property ignoreFollowRequestToTarget フォローリクエストを無視しているか - */ -data class Relationship( - val actorId: Long, - val targetActorId: Long, - val following: Boolean, - val blocking: Boolean, - val muting: Boolean, - val followRequest: Boolean, - val ignoreFollowRequestToTarget: Boolean -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt deleted file mode 100644 index 5e6b7886..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt +++ /dev/null @@ -1,178 +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.core.domain.model.relationship - -import dev.usbharu.hideout.application.infrastructure.exposed.Page -import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList -import dev.usbharu.hideout.application.infrastructure.exposed.withPagination -import dev.usbharu.hideout.core.infrastructure.exposedrepository.AbstractRepository -import org.jetbrains.exposed.dao.id.LongIdTable -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service - -@Service -class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() { - override val logger: Logger - get() = Companion.logger - - override suspend fun save(relationship: Relationship): Relationship = query { - val singleOrNull = Relationships.selectAll().where { - (Relationships.actorId eq relationship.actorId).and( - Relationships.targetActorId eq relationship.targetActorId - ) - }.forUpdate().singleOrNull() - - if (singleOrNull == null) { - Relationships.insert { - it[actorId] = relationship.actorId - it[targetActorId] = relationship.targetActorId - it[following] = relationship.following - it[blocking] = relationship.blocking - it[muting] = relationship.muting - it[followRequest] = relationship.followRequest - it[ignoreFollowRequestFromTarget] = relationship.ignoreFollowRequestToTarget - } - } else { - Relationships.update({ - (Relationships.actorId eq relationship.actorId).and( - Relationships.targetActorId eq relationship.targetActorId - ) - }) { - it[following] = relationship.following - it[blocking] = relationship.blocking - it[muting] = relationship.muting - it[followRequest] = relationship.followRequest - it[ignoreFollowRequestFromTarget] = relationship.ignoreFollowRequestToTarget - } - } - return@query relationship - } - - override suspend fun delete(relationship: Relationship): Unit = query { - Relationships.deleteWhere { - (actorId eq relationship.actorId).and( - targetActorId eq relationship.targetActorId - ) - } - } - - override suspend fun findByUserIdAndTargetUserId(actorId: Long, targetActorId: Long): Relationship? = query { - return@query Relationships.selectAll() - .where { (Relationships.actorId eq actorId).and(Relationships.targetActorId eq targetActorId) } - .singleOrNull()?.toRelationships() - } - - override suspend fun deleteByActorIdOrTargetActorId(actorId: Long, targetActorId: Long): Unit = query { - Relationships.deleteWhere { - Relationships.actorId.eq(actorId).or(Relationships.targetActorId.eq(targetActorId)) - } - } - - override suspend fun findByTargetIdAndFollowing(targetId: Long, following: Boolean): List = query { - return@query Relationships - .selectAll().where { Relationships.targetActorId eq targetId and (Relationships.following eq following) } - .map { it.toRelationships() } - } - - override suspend fun countByTargetIdAndFollowing(targetId: Long, following: Boolean): Int = query { - return@query Relationships - .selectAll() - .where { - Relationships.targetActorId eq targetId and (Relationships.following eq following) - } - .count() - .toInt() - } - - override suspend fun countByUserIdAndFollowing(userId: Long, following: Boolean): Int = query { - return@query Relationships - .selectAll() - .where { - Relationships.actorId eq userId and (Relationships.following eq following) - } - .count() - .toInt() - } - - override suspend fun findByTargetIdAndFollowRequestAndIgnoreFollowRequest( - targetId: Long, - followRequest: Boolean, - ignoreFollowRequest: Boolean, - page: Page.PageByMaxId, - ): PaginationList = query { - val query = Relationships.selectAll().where { - Relationships.targetActorId.eq(targetId).and(Relationships.followRequest.eq(followRequest)) - .and(Relationships.ignoreFollowRequestFromTarget.eq(ignoreFollowRequest)) - } - - val resultRowList = query.withPagination(page, Relationships.id) - - return@query PaginationList( - resultRowList.map { it.toRelationships() }, - resultRowList.next?.value, - resultRowList.prev?.value - ) - } - - override suspend fun findByActorIdAndMuting( - actorId: Long, - muting: Boolean, - page: Page.PageByMaxId, - ): PaginationList = query { - val query = - Relationships.selectAll().where { Relationships.actorId.eq(actorId).and(Relationships.muting.eq(muting)) } - - val resultRowList = query.withPagination(page, Relationships.id) - - return@query PaginationList( - resultRowList.map { it.toRelationships() }, - resultRowList.next?.value, - resultRowList.prev?.value - ) - } - - companion object { - private val logger = LoggerFactory.getLogger(RelationshipRepositoryImpl::class.java) - } -} - -fun ResultRow.toRelationships(): Relationship = Relationship( - actorId = this[Relationships.actorId], - targetActorId = this[Relationships.targetActorId], - following = this[Relationships.following], - blocking = this[Relationships.blocking], - muting = this[Relationships.muting], - followRequest = this[Relationships.followRequest], - ignoreFollowRequestToTarget = this[Relationships.ignoreFollowRequestFromTarget] -) - -object Relationships : LongIdTable("relationships") { - val actorId = long("actor_id").references(Actors.id) - val targetActorId = long("target_actor_id").references(Actors.id) - val following = bool("following") - val blocking = bool("blocking") - val muting = bool("muting") - val followRequest = bool("follow_request") - val ignoreFollowRequestFromTarget = bool("ignore_follow_request") - - init { - uniqueIndex(actorId, targetActorId) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEvent.kt deleted file mode 100644 index 53c48d86..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEvent.kt +++ /dev/null @@ -1,37 +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.core.domain.model.shared.domainevent - -import java.time.Instant -import java.util.* - -data class DomainEvent( - private val id: String, - private val name: String, - private val occurredOn: Instant, - private val body: DomainEventBody, -) { - companion object { - fun create(name: String, body: DomainEventBody): DomainEvent { - return DomainEvent(UUID.randomUUID().toString(), name, Instant.now(), body) - } - - fun reconstruct(id: String, name: String, occurredOn: Instant, body: DomainEventBody): DomainEvent { - return DomainEvent(id, name, occurredOn, body) - } - } -} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventBody.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventBody.kt deleted file mode 100644 index cb7dd4d9..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventBody.kt +++ /dev/null @@ -1,23 +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.core.domain.model.shared.domainevent - -abstract class DomainEventBody(val map: Map) { - fun toMap(): Map { - return map - } -} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt deleted file mode 100644 index 46e4548a..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt +++ /dev/null @@ -1,42 +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.core.domain.model.timeline - -import dev.usbharu.hideout.core.domain.model.post.Visibility -import org.springframework.data.annotation.Id -import org.springframework.data.mongodb.core.index.CompoundIndex -import org.springframework.data.mongodb.core.mapping.Document - -@Document -@CompoundIndex(def = "{'userId':1,'timelineId':1,'postId':1}", unique = true) -data class Timeline( - @Id - val id: Long, - val userId: Long, - val timelineId: Long, - val postId: Long, - val postActorId: Long, - val createdAt: Long, - val replyId: Long?, - val repostId: Long?, - val visibility: Visibility, - val sensitive: Boolean, - val isLocal: Boolean, - val isPureRepost: Boolean = false, - val mediaIds: List = emptyList(), - val emojiIds: List = emptyList() -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/TimelineRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/TimelineRepository.kt deleted file mode 100644 index 21c8d2ee..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/TimelineRepository.kt +++ /dev/null @@ -1,25 +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.core.domain.model.timeline - -interface TimelineRepository { - suspend fun generateId(): Long - suspend fun save(timeline: Timeline): Timeline - suspend fun saveAll(timelines: List): List - suspend fun findByUserId(id: Long): List - suspend fun findByUserIdAndTimelineId(userId: Long, timelineId: Long): List -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt index eb17a1ef..79733294 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt @@ -18,8 +18,6 @@ package dev.usbharu.hideout.core.infrastructure.exposedrepository import dev.usbharu.hideout.application.service.id.IdGenerateService import dev.usbharu.hideout.core.domain.model.post.Visibility -import dev.usbharu.hideout.core.domain.model.timeline.Timeline -import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository import org.jetbrains.exposed.sql.* import org.slf4j.Logger import org.slf4j.LoggerFactory diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt index 19e5cf8e..8882d480 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt @@ -17,10 +17,9 @@ package dev.usbharu.hideout.core.infrastructure.exposedrepository import dev.usbharu.hideout.application.service.id.IdGenerateService +import dev.usbharu.hideout.core.domain.model.media.FileType import dev.usbharu.hideout.core.domain.model.media.MediaRepository -import dev.usbharu.hideout.core.infrastructure.exposedrepository.Media.mimeType -import dev.usbharu.hideout.core.service.media.FileType -import dev.usbharu.hideout.core.service.media.MimeType +import dev.usbharu.hideout.core.domain.model.media.MimeType import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.slf4j.Logger diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MetaRepositoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MetaRepositoryImpl.kt index c9d76578..c70ec0d8 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MetaRepositoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MetaRepositoryImpl.kt @@ -16,8 +16,6 @@ package dev.usbharu.hideout.core.infrastructure.exposedrepository -import dev.usbharu.hideout.core.domain.model.meta.Jwt -import dev.usbharu.hideout.core.domain.model.meta.MetaRepository import org.jetbrains.exposed.sql.* import org.springframework.stereotype.Repository import java.util.* diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt deleted file mode 100644 index e9be4342..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt +++ /dev/null @@ -1,232 +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.core.infrastructure.exposedrepository - -import dev.usbharu.hideout.application.service.id.IdGenerateService -import dev.usbharu.hideout.core.domain.model.emoji.CustomEmoji -import dev.usbharu.hideout.core.domain.model.emoji.Emoji -import dev.usbharu.hideout.core.domain.model.emoji.UnicodeEmoji -import dev.usbharu.hideout.core.domain.model.reaction.Reaction -import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository -import org.jetbrains.exposed.dao.id.LongIdTable -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Repository - -@Repository -class ReactionRepositoryImpl( - private val idGenerateService: IdGenerateService -) : ReactionRepository, AbstractRepository() { - override val logger: Logger - get() = Companion.logger - - override suspend fun generateId(): Long = idGenerateService.generateId() - - override suspend fun save(reaction: Reaction): Reaction = query { - if (Reactions.selectAll().where { Reactions.id eq reaction.id }.forUpdate().empty()) { - Reactions.insert { - it[id] = reaction.id - if (reaction.emoji is CustomEmoji) { - it[customEmojiId] = reaction.emoji.id - it[unicodeEmoji] = null - } else { - it[customEmojiId] = null - it[unicodeEmoji] = reaction.emoji.name - } - it[postId] = reaction.postId - it[actorId] = reaction.actorId - } - } else { - Reactions.update({ Reactions.id eq reaction.id }) { - if (reaction.emoji is CustomEmoji) { - it[customEmojiId] = reaction.emoji.id - it[unicodeEmoji] = null - } else { - it[customEmojiId] = null - it[unicodeEmoji] = reaction.emoji.name - } - it[postId] = reaction.postId - it[actorId] = reaction.actorId - } - } - return@query reaction - } - - override suspend fun delete(reaction: Reaction): Reaction = query { - if (reaction.emoji is CustomEmoji) { - Reactions.deleteWhere { - id.eq(reaction.id).and(postId.eq(reaction.postId)).and(actorId.eq(reaction.actorId)) - .and(customEmojiId.eq(reaction.emoji.id)) - } - } else { - Reactions.deleteWhere { - id.eq(reaction.id).and(postId.eq(reaction.postId)).and(actorId.eq(reaction.actorId)) - .and(unicodeEmoji.eq(reaction.emoji.name)) - } - } - return@query reaction - } - - override suspend fun deleteByPostId(postId: Long): Int = query { - return@query Reactions.deleteWhere { - Reactions.postId eq postId - } - } - - override suspend fun deleteByActorId(actorId: Long): Int = query { - return@query Reactions.deleteWhere { - Reactions.actorId eq actorId - } - } - - override suspend fun deleteByPostIdAndActorId(postId: Long, actorId: Long): Unit = query { - Reactions.deleteWhere { - Reactions.postId eq postId and (Reactions.actorId eq actorId) - } - } - - override suspend fun deleteByPostIdAndActorIdAndEmoji(postId: Long, actorId: Long, emoji: Emoji): Unit = query { - if (emoji is CustomEmoji) { - Reactions.deleteWhere { - Reactions.postId.eq(postId) - .and(Reactions.actorId.eq(actorId)) - .and(customEmojiId.eq(emoji.id)) - } - } else { - Reactions.deleteWhere { - Reactions.postId.eq(postId) - .and(Reactions.actorId.eq(actorId)) - .and(unicodeEmoji.eq(emoji.name)) - } - } - } - - override suspend fun findById(id: Long): Reaction? = query { - return@query Reactions.leftJoin(CustomEmojis).selectAll().where { Reactions.id eq id }.singleOrNull() - ?.toReaction() - } - - override suspend fun findByPostId(postId: Long): List = query { - return@query Reactions.leftJoin(CustomEmojis).selectAll().where { Reactions.postId eq postId } - .map { it.toReaction() } - } - - override suspend fun findByPostIdAndActorIdAndEmojiId(postId: Long, actorId: Long, emojiId: Long): Reaction? = - query { - return@query Reactions.leftJoin(CustomEmojis).selectAll().where { - Reactions.postId eq postId and (Reactions.actorId eq actorId).and( - Reactions.customEmojiId.eq( - emojiId - ) - ) - }.singleOrNull()?.toReaction() - } - - override suspend fun existByPostIdAndActorIdAndEmojiId(postId: Long, actorId: Long, emojiId: Long): Boolean = - query { - return@query Reactions.selectAll().where { - Reactions.postId - .eq(postId) - .and(Reactions.actorId.eq(actorId)) - .and(Reactions.customEmojiId.eq(emojiId)) - }.empty().not() - } - - override suspend fun existByPostIdAndActorIdAndUnicodeEmoji( - postId: Long, - actorId: Long, - unicodeEmoji: String - ): Boolean = query { - return@query Reactions.selectAll().where { - Reactions.postId - .eq(postId) - .and(Reactions.actorId.eq(actorId)) - .and(Reactions.unicodeEmoji.eq(unicodeEmoji)) - }.empty().not() - } - - override suspend fun existByPostIdAndActorIdAndEmoji(postId: Long, actorId: Long, emoji: Emoji): Boolean = query { - val query = Reactions.selectAll().where { - Reactions.postId - .eq(postId) - .and(Reactions.actorId.eq(actorId)) - } - - if (emoji is UnicodeEmoji) { - query.andWhere { Reactions.unicodeEmoji eq emoji.name } - } else { - emoji as CustomEmoji - query.andWhere { Reactions.customEmojiId eq emoji.id } - } - - return@query query.empty().not() - } - - override suspend fun existByPostIdAndActor(postId: Long, actorId: Long): Boolean = query { - Reactions.selectAll().where { Reactions.postId.eq(postId).and(Reactions.actorId.eq(actorId)) }.empty().not() - } - - override suspend fun findByPostIdAndActorId(postId: Long, actorId: Long): List = query { - return@query Reactions.leftJoin(CustomEmojis) - .selectAll().where { Reactions.postId eq postId and (Reactions.actorId eq actorId) } - .map { it.toReaction() } - } - - companion object { - private val logger = LoggerFactory.getLogger(ReactionRepositoryImpl::class.java) - } -} - -fun ResultRow.toReaction(): Reaction { - val emoji = if (this[Reactions.customEmojiId] != null) { - CustomEmoji( - id = this[Reactions.customEmojiId]!!, - name = this[CustomEmojis.name], - domain = this[CustomEmojis.domain], - instanceId = this[CustomEmojis.instanceId], - url = this[CustomEmojis.url], - category = this[CustomEmojis.category], - createdAt = this[CustomEmojis.createdAt] - ) - } else if (this[Reactions.unicodeEmoji] != null) { - UnicodeEmoji(this[Reactions.unicodeEmoji]!!) - } else { - throw IllegalStateException("customEmojiId and unicodeEmoji is null.") - } - - return Reaction( - this[Reactions.id].value, - emoji, - this[Reactions.postId], - this[Reactions.actorId] - ) -} - -object Reactions : LongIdTable("reactions") { - val customEmojiId = long("custom_emoji_id").references(CustomEmojis.id).nullable() - val unicodeEmoji = varchar("unicode_emoji", 255).nullable() - val postId: Column = - long("post_id").references(Posts.id, onDelete = ReferenceOption.CASCADE, onUpdate = ReferenceOption.CASCADE) - val actorId: Column = - long("actor_id").references(Actors.id, onDelete = ReferenceOption.CASCADE, onUpdate = ReferenceOption.CASCADE) - - init { - uniqueIndex(customEmojiId, postId, actorId) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoTimelineRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoTimelineRepository.kt deleted file mode 100644 index 348d3abd..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoTimelineRepository.kt +++ /dev/null @@ -1,35 +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.core.infrastructure.mongorepository - -import dev.usbharu.hideout.core.domain.model.timeline.Timeline -import org.springframework.data.domain.Pageable -import org.springframework.data.mongodb.repository.MongoRepository - -@Suppress("LongParameterList", "FunctionMaxLength") -interface MongoTimelineRepository : MongoRepository { - fun findByUserId(id: Long): List - fun findByUserIdAndTimelineId(userId: Long, timelineId: Long): List - fun findByUserIdAndTimelineIdAndPostIdBetweenAndIsLocal( - userId: Long?, - timelineId: Long?, - postIdMin: Long?, - postIdMax: Long?, - isLocal: Boolean?, - pageable: Pageable - ): List -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoTimelineRepositoryWrapper.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoTimelineRepositoryWrapper.kt deleted file mode 100644 index 58d36a36..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoTimelineRepositoryWrapper.kt +++ /dev/null @@ -1,67 +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.core.infrastructure.mongorepository - -import dev.usbharu.hideout.application.service.id.IdGenerateService -import dev.usbharu.hideout.core.domain.exception.resource.DuplicateException -import dev.usbharu.hideout.core.domain.exception.resource.ResourceAccessException -import dev.usbharu.hideout.core.domain.model.timeline.Timeline -import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.dao.DataAccessException -import org.springframework.dao.DuplicateKeyException -import org.springframework.stereotype.Repository - -@Repository -@ConditionalOnProperty("hideout.use-mongodb", havingValue = "true", matchIfMissing = false) -class MongoTimelineRepositoryWrapper( - private val mongoTimelineRepository: MongoTimelineRepository, - private val idGenerateService: IdGenerateService -) : - TimelineRepository { - override suspend fun generateId(): Long = idGenerateService.generateId() - - override suspend fun save(timeline: Timeline): Timeline { - return withContext(Dispatchers.IO) { - mongoTimelineRepository.save(timeline) - } - } - - override suspend fun saveAll(timelines: List): List { - try { - return mongoTimelineRepository.saveAll(timelines) - } catch (e: DuplicateKeyException) { - throw DuplicateException("Timeline duplicate.", e) - } catch (e: DataAccessException) { - throw ResourceAccessException(e) - } - } - - override suspend fun findByUserId(id: Long): List { - return withContext(Dispatchers.IO) { - mongoTimelineRepository.findByUserId(id) - } - } - - override suspend fun findByUserIdAndTimelineId(userId: Long, timelineId: Long): List { - return withContext(Dispatchers.IO) { - mongoTimelineRepository.findByUserIdAndTimelineId(userId, timelineId) - } - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUserDetailsService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUserDetailsService.kt index 578da4ad..36c61d4c 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUserDetailsService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUserDetailsService.kt @@ -16,7 +16,7 @@ package dev.usbharu.hideout.core.infrastructure.springframework.httpsignature -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.exception.HttpSignatureVerifyException import dev.usbharu.hideout.util.RsaUtil import dev.usbharu.httpsignature.common.HttpMethod diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationConsentService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationConsentService.kt index 4ad94f0e..7c5126e9 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationConsentService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationConsentService.kt @@ -16,7 +16,7 @@ package dev.usbharu.hideout.core.infrastructure.springframework.oauth2 -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import kotlinx.coroutines.runBlocking import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt index 4cb43890..b6689829 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt @@ -19,7 +19,7 @@ package dev.usbharu.hideout.core.infrastructure.springframework.oauth2 import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.module.kotlin.readValue -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import kotlinx.coroutines.runBlocking import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsServiceImpl.kt index 6481007b..04b1f298 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsServiceImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsServiceImpl.kt @@ -17,7 +17,7 @@ package dev.usbharu.hideout.core.infrastructure.springframework.oauth2 import dev.usbharu.hideout.application.config.ApplicationConfig -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.exception.resource.UserNotFoundException import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import kotlinx.coroutines.runBlocking diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt index 22b6fd61..0c749ee5 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt @@ -40,13 +40,7 @@ class AuthController( @PostMapping("/auth/sign_up") suspend fun signUp(@Validated @ModelAttribute signUpForm: SignUpForm): String { - val registerAccount = authApiService.registerAccount( - RegisterAccountDto( - signUpForm.username, - signUpForm.password, - signUpForm.recaptchaResponse - ) - ) + return "redirect:" + registerAccount.url } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/ExposedFilterQueryService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/ExposedFilterQueryService.kt deleted file mode 100644 index 22defc4d..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/ExposedFilterQueryService.kt +++ /dev/null @@ -1,76 +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.core.query.model - -import dev.usbharu.hideout.core.domain.model.filter.FilterType -import dev.usbharu.hideout.core.infrastructure.exposedrepository.FilterKeywords -import dev.usbharu.hideout.core.infrastructure.exposedrepository.Filters -import dev.usbharu.hideout.core.infrastructure.exposedrepository.toFilter -import dev.usbharu.hideout.core.infrastructure.exposedrepository.toFilterKeyword -import org.jetbrains.exposed.sql.Query -import org.jetbrains.exposed.sql.and -import org.jetbrains.exposed.sql.selectAll -import org.springframework.stereotype.Repository - -@Repository -class ExposedFilterQueryService : FilterQueryService { - override suspend fun findByUserIdAndType(userId: Long, types: List): List { - return Filters - .rightJoin(FilterKeywords) - .selectAll() - .where { Filters.userId eq userId } - .toFilterQueryModel() - } - - override suspend fun findByUserId(userId: Long): List { - return Filters - .rightJoin(FilterKeywords) - .selectAll() - .where { Filters.userId eq userId } - .toFilterQueryModel() - } - - override suspend fun findByUserIdAndId(userId: Long, id: Long): FilterQueryModel? { - return Filters - .leftJoin(FilterKeywords) - .selectAll() - .where { Filters.userId eq userId and (Filters.id eq id) } - .toFilterQueryModel() - .firstOrNull() - } - - override suspend fun findByUserIdAndKeywordId(userId: Long, keywordId: Long): FilterQueryModel? { - return Filters - .leftJoin(FilterKeywords) - .selectAll() - .where { Filters.userId eq userId and (FilterKeywords.id eq keywordId) } - .toFilterQueryModel() - .firstOrNull() - } - - private fun Query.toFilterQueryModel(): List { - return this - .groupBy { it[Filters.id] } - .map { it.value } - .map { - FilterQueryModel.of( - it.first().toFilter(), - it.map { resultRow -> resultRow.toFilterKeyword() } - ) - } - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/FilterQueryModel.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/FilterQueryModel.kt deleted file mode 100644 index 767649c3..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/FilterQueryModel.kt +++ /dev/null @@ -1,43 +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.core.query.model - -import dev.usbharu.hideout.core.domain.model.filter.Filter -import dev.usbharu.hideout.core.domain.model.filter.FilterAction -import dev.usbharu.hideout.core.domain.model.filter.FilterType -import dev.usbharu.hideout.core.domain.model.filterkeyword.FilterKeyword - -data class FilterQueryModel( - val id: Long, - val userId: Long, - val name: String, - val context: List, - val filterAction: FilterAction, - val keywords: List -) { - companion object { - @Suppress("FunctionMinLength") - fun of(filter: Filter, keywords: List): FilterQueryModel = FilterQueryModel( - id = filter.id, - userId = filter.userId, - name = filter.name, - context = filter.context, - filterAction = filter.filterAction, - keywords = keywords - ) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/FilterQueryService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/FilterQueryService.kt deleted file mode 100644 index a0ad4f93..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/model/FilterQueryService.kt +++ /dev/null @@ -1,26 +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.core.query.model - -import dev.usbharu.hideout.core.domain.model.filter.FilterType - -interface FilterQueryService { - suspend fun findByUserIdAndType(userId: Long, types: List): List - suspend fun findByUserId(userId: Long): List - suspend fun findByUserIdAndId(userId: Long, id: Long): FilterQueryModel? - suspend fun findByUserIdAndKeywordId(userId: Long, keywordId: Long): FilterQueryModel? -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/FilterKeyword.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/FilterKeyword.kt deleted file mode 100644 index 6c2ebc39..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/FilterKeyword.kt +++ /dev/null @@ -1,24 +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.core.service.filter - -import dev.usbharu.hideout.core.domain.model.filter.FilterMode - -data class FilterKeyword( - val keyword: String, - val mode: FilterMode -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/FilterResult.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/FilterResult.kt deleted file mode 100644 index d87e6fea..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/FilterResult.kt +++ /dev/null @@ -1,24 +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.core.service.filter - -import dev.usbharu.hideout.core.query.model.FilterQueryModel - -data class FilterResult( - val filter: FilterQueryModel, - val keyword: String, -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/MuteService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/MuteService.kt deleted file mode 100644 index 63e1ac83..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/MuteService.kt +++ /dev/null @@ -1,33 +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.core.service.filter - -import dev.usbharu.hideout.core.domain.model.filter.FilterAction -import dev.usbharu.hideout.core.domain.model.filter.FilterType -import dev.usbharu.hideout.core.query.model.FilterQueryModel - -interface MuteService { - suspend fun createFilter( - title: String, - context: List, - action: FilterAction, - keywords: List, - loginUser: Long - ): FilterQueryModel - - suspend fun getFilters(userId: Long, types: List = emptyList()): List -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/MuteServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/MuteServiceImpl.kt deleted file mode 100644 index 27872d7d..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/filter/MuteServiceImpl.kt +++ /dev/null @@ -1,66 +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.core.service.filter - -import dev.usbharu.hideout.core.domain.model.filter.Filter -import dev.usbharu.hideout.core.domain.model.filter.FilterAction -import dev.usbharu.hideout.core.domain.model.filter.FilterRepository -import dev.usbharu.hideout.core.domain.model.filter.FilterType -import dev.usbharu.hideout.core.domain.model.filterkeyword.FilterKeywordRepository -import dev.usbharu.hideout.core.query.model.FilterQueryModel -import dev.usbharu.hideout.core.query.model.FilterQueryService -import org.springframework.stereotype.Service - -@Service -class MuteServiceImpl( - private val filterRepository: FilterRepository, - private val filterKeywordRepository: FilterKeywordRepository, - private val filterQueryService: FilterQueryService -) : MuteService { - override suspend fun createFilter( - title: String, - context: List, - action: FilterAction, - keywords: List, - loginUser: Long - ): FilterQueryModel { - val filter = Filter( - filterRepository.generateId(), - loginUser, - title, - context, - action - ) - - val filterKeywordList = keywords.map { - dev.usbharu.hideout.core.domain.model.filterkeyword.FilterKeyword( - filterKeywordRepository.generateId(), - filter.id, - it.keyword, - it.mode - ) - } - - val savedFilter = filterRepository.save(filter) - - filterKeywordRepository.saveAll(filterKeywordList) - return FilterQueryModel.of(savedFilter, filterKeywordList) - } - - override suspend fun getFilters(userId: Long, types: List): List = - filterQueryService.findByUserIdAndType(userId, types) -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceCreateDto.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceCreateDto.kt deleted file mode 100644 index f4d04b30..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceCreateDto.kt +++ /dev/null @@ -1,27 +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.core.service.instance - -data class InstanceCreateDto( - val name: String?, - val description: String?, - val url: String, - val iconUrl: String, - val sharedInbox: String?, - val software: String?, - val version: String?, -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt deleted file mode 100644 index a9a84f3d..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt +++ /dev/null @@ -1,124 +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.core.service.instance - -import com.fasterxml.jackson.databind.ObjectMapper -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.instance.Nodeinfo -import dev.usbharu.hideout.core.domain.model.instance.Nodeinfo2_0 -import dev.usbharu.hideout.core.service.resource.ResourceResolveService -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Qualifier -import org.springframework.stereotype.Service -import java.net.URL -import java.time.Instant - -interface InstanceService { - suspend fun fetchInstance(url: String, sharedInbox: String? = null): Instance - suspend fun createNewInstance(instanceCreateDto: InstanceCreateDto): Instance -} - -@Service -class InstanceServiceImpl( - private val instanceRepository: InstanceRepository, - private val resourceResolveService: ResourceResolveService, - @Qualifier("activitypub") private val objectMapper: ObjectMapper, -) : InstanceService { - override suspend fun fetchInstance(url: String, sharedInbox: String?): Instance { - val u = URL(url) - val resolveInstanceUrl = u.protocol + "://" + u.host - - val instance = instanceRepository.findByUrl(resolveInstanceUrl) - - if (instance != null) { - return instance - } - - logger.info("Instance not found. try fetch instance info. url: {}", resolveInstanceUrl) - @Suppress("TooGenericExceptionCaught") - try { - val nodeinfoJson = resourceResolveService.resolve("$resolveInstanceUrl/.well-known/nodeinfo").bodyAsText() - val nodeinfo = objectMapper.readValue(nodeinfoJson, Nodeinfo::class.java) - val nodeinfoPathMap = nodeinfo.links.associate { it.rel to it.href } - - for ((key, value) in nodeinfoPathMap) { - when (key) { - "http://nodeinfo.diaspora.software/ns/schema/2.0", - "http://nodeinfo.diaspora.software/ns/schema/2.1", - -> { - val nodeinfo20 = objectMapper.readValue( - resourceResolveService.resolve(value!!).bodyAsText(), - Nodeinfo2_0::class.java - ) - - val instanceCreateDto = InstanceCreateDto( - name = nodeinfo20.metadata?.nodeName, - description = nodeinfo20.metadata?.nodeDescription, - url = resolveInstanceUrl, - iconUrl = "$resolveInstanceUrl/favicon.ico", - sharedInbox = sharedInbox, - software = nodeinfo20.software?.name, - version = nodeinfo20.software?.version - ) - return createNewInstance(instanceCreateDto) - } - - else -> { - throw IllegalStateException("Unknown nodeinfo versions: $key url: $value") - } - } - } - } catch (e: Exception) { - logger.warn("FAILED Fetch Instance", e) - } - return createNewInstance( - InstanceCreateDto( - name = null, - description = null, - url = resolveInstanceUrl, - iconUrl = "$resolveInstanceUrl/favicon.ico", - sharedInbox = null, - software = null, - version = null - ) - ) - } - - override suspend fun createNewInstance(instanceCreateDto: InstanceCreateDto): Instance { - val instance = Instance( - id = instanceRepository.generateId(), - name = instanceCreateDto.name ?: instanceCreateDto.url, - description = instanceCreateDto.description.orEmpty(), - url = instanceCreateDto.url, - iconUrl = instanceCreateDto.iconUrl, - sharedInbox = instanceCreateDto.sharedInbox, - software = instanceCreateDto.software ?: "unknown", - version = instanceCreateDto.version ?: "unknown", - isBlocked = false, - isMuted = false, - moderationNote = "", - createdAt = Instant.now() - ) - instanceRepository.save(instance) - return instance - } - - companion object { - private val logger = LoggerFactory.getLogger(InstanceServiceImpl::class.java) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ApatcheTikaFileTypeDeterminationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ApatcheTikaFileTypeDeterminationService.kt deleted file mode 100644 index b4aa4c57..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ApatcheTikaFileTypeDeterminationService.kt +++ /dev/null @@ -1,105 +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.core.service.media - -import org.apache.tika.Tika -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Component -import java.nio.file.Path - -@Component -class ApatcheTikaFileTypeDeterminationService : FileTypeDeterminationService { - override fun fileType( - byteArray: ByteArray, - filename: String, - contentType: String? - ): MimeType { - logger.info("START Detect file type name: {}", filename) - - val tika = Tika() - - val detect = try { - tika.detect(byteArray, filename) - } catch (e: IllegalStateException) { - logger.warn("FAILED Detect file type", e) - "application/octet-stream" - } - - val type = detect.substringBefore("/") - val fileType = when (type) { - "image" -> { - FileType.Image - } - - "video" -> { - FileType.Video - } - - "audio" -> { - FileType.Audio - } - - else -> { - FileType.Unknown - } - } - val mimeType = MimeType(type, detect.substringAfter("/"), fileType) - - logger.info("SUCCESS Detect file type name: {},MimeType: {}", filename, mimeType) - return mimeType - } - - override fun fileType(path: Path, filename: String): MimeType { - logger.info("START Detect file type name: {}", filename) - - val tika = Tika() - - val detect = try { - tika.detect(path) - } catch (e: IllegalStateException) { - logger.warn("FAILED Detect file type", e) - "application/octet-stream" - } - - val type = detect.substringBefore("/") - val fileType = when (type) { - "image" -> { - FileType.Image - } - - "video" -> { - FileType.Video - } - - "audio" -> { - FileType.Audio - } - - else -> { - FileType.Unknown - } - } - val mimeType = MimeType(type, detect.substringAfter("/"), fileType) - - logger.info("SUCCESS Detect file type name: {},MimeType: {}", filename, mimeType) - return mimeType - } - - companion object { - private val logger = LoggerFactory.getLogger(ApatcheTikaFileTypeDeterminationService::class.java) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/FileTypeDeterminationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/FileTypeDeterminationService.kt deleted file mode 100644 index e09a263b..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/FileTypeDeterminationService.kt +++ /dev/null @@ -1,24 +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.core.service.media - -import java.nio.file.Path - -interface FileTypeDeterminationService { - fun fileType(byteArray: ByteArray, filename: String, contentType: String?): MimeType - fun fileType(path: Path, filename: String): MimeType -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/LocalFileSystemMediaDataStore.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/LocalFileSystemMediaDataStore.kt deleted file mode 100644 index 7ca382f6..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/LocalFileSystemMediaDataStore.kt +++ /dev/null @@ -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.core.service.media - -import dev.usbharu.hideout.application.config.ApplicationConfig -import dev.usbharu.hideout.application.config.LocalStorageConfig -import org.slf4j.LoggerFactory -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.stereotype.Service -import java.nio.file.Path -import java.nio.file.StandardOpenOption -import kotlin.io.path.copyTo -import kotlin.io.path.createDirectories -import kotlin.io.path.deleteIfExists -import kotlin.io.path.outputStream - -/** - * ローカルファイルシステムにメディアを保存します - * - * @constructor - * ApplicationConfigとLocalStorageConfigをもとに作成 - * - * @param applicationConfig ApplicationConfig - * @param localStorageConfig LocalStorageConfig - */ -@Service -@ConditionalOnProperty("hideout.storage.type", havingValue = "local", matchIfMissing = true) -class LocalFileSystemMediaDataStore( - applicationConfig: ApplicationConfig, - localStorageConfig: LocalStorageConfig -) : MediaDataStore { - - private val savePath: Path = Path.of(localStorageConfig.path).toAbsolutePath() - - private val publicUrl = localStorageConfig.publicUrl ?: "${applicationConfig.url}/files/" - - init { - savePath.createDirectories() - } - - @Suppress("NestedBlockDepth") - override suspend fun save(dataMediaSave: MediaSave): SavedMedia { - val fileSavePath = buildSavePath(savePath, dataMediaSave.name) - val thumbnailSavePath = buildSavePath(savePath, "thumbnail-" + dataMediaSave.name) - - dataMediaSave.thumbnailInputStream?.inputStream()?.use { - it.buffered().use { bufferedInputStream -> - thumbnailSavePath.outputStream(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE) - .use { outputStream -> - outputStream.buffered().use { - bufferedInputStream.transferTo(it) - } - } - } - } - - dataMediaSave.fileInputStream.inputStream().use { - it.buffered().use { bufferedInputStream -> - fileSavePath.outputStream(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE) - .use { outputStream -> outputStream.buffered().use { bufferedInputStream.transferTo(it) } } - } - } - - return SuccessSavedMedia( - dataMediaSave.name, - publicUrl + dataMediaSave.name, - publicUrl + "thumbnail-" + dataMediaSave.name - ) - } - - override suspend fun save(dataSaveRequest: MediaSaveRequest): SavedMedia { - logger.info("START Media upload. {}", dataSaveRequest.name) - val fileSavePath = buildSavePath(savePath, dataSaveRequest.name) - val thumbnailSavePath = buildSavePath(savePath, "thumbnail-" + dataSaveRequest.name) - - val fileSavePathString = fileSavePath.toAbsolutePath().toString() - logger.info("MEDIA save. path: {}", fileSavePathString) - - @Suppress("TooGenericExceptionCaught") - try { - dataSaveRequest.filePath.copyTo(fileSavePath) - dataSaveRequest.thumbnailPath?.copyTo(thumbnailSavePath) - } catch (e: Exception) { - logger.warn("FAILED to Save the media.", e) - return FaildSavedMedia("FAILED to Save the media.", "Failed copy to path: $fileSavePathString", e) - } - - logger.info("SUCCESS Media upload. {}", dataSaveRequest.name) - return SuccessSavedMedia( - dataSaveRequest.name, - publicUrl + dataSaveRequest.name, - publicUrl + "thumbnail-" + dataSaveRequest.name - ) - } - - /** - * メディアを削除します。サムネイルも削除されます。 - * - * @param id 削除するメディアのid [SuccessSavedMedia.name]を指定します。 - */ - override suspend fun delete(id: String) { - logger.info("START Media delete. id: {}", id) - @Suppress("TooGenericExceptionCaught") - try { - buildSavePath(savePath, id).deleteIfExists() - buildSavePath(savePath, "thumbnail-$id").deleteIfExists() - } catch (e: Exception) { - logger.warn("FAILED Media delete. id: {}", id, e) - } - } - - private fun buildSavePath(savePath: Path, name: String): Path = savePath.resolve(name) - - companion object { - private val logger = LoggerFactory.getLogger(LocalFileSystemMediaDataStore::class.java) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaBlurhashService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaBlurhashService.kt deleted file mode 100644 index 13fd1eee..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaBlurhashService.kt +++ /dev/null @@ -1,23 +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.core.service.media - -import java.awt.image.BufferedImage - -interface MediaBlurhashService { - fun generateBlurhash(bufferedImage: BufferedImage): String -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaBlurhashServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaBlurhashServiceImpl.kt deleted file mode 100644 index 963554a3..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaBlurhashServiceImpl.kt +++ /dev/null @@ -1,26 +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.core.service.media - -import io.trbl.blurhash.BlurHash -import org.springframework.stereotype.Service -import java.awt.image.BufferedImage - -@Service -class MediaBlurhashServiceImpl : MediaBlurhashService { - override fun generateBlurhash(bufferedImage: BufferedImage): String = BlurHash.encode(bufferedImage) -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaDataStore.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaDataStore.kt deleted file mode 100644 index 79a30159..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaDataStore.kt +++ /dev/null @@ -1,47 +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.core.service.media - -/** - * メディアを保存するインタフェース - * - */ -interface MediaDataStore { - /** - * InputStreamを使用してメディアを保存します - * - * @param dataMediaSave FileとThumbnailのinputStream - * @return 保存されたメディア - */ - suspend fun save(dataMediaSave: MediaSave): SavedMedia - - /** - * 一時ファイルのパスを使用してメディアを保存します - * - * @param dataSaveRequest FileとThumbnailのパス - * @return 保存されたメディア - */ - suspend fun save(dataSaveRequest: MediaSaveRequest): SavedMedia - - /** - * メディアを削除します - * 実装はサムネイル、メタデータなども削除するべきです。 - * - * @param id 削除するメディアのid 通常は[SuccessSavedMedia.name]を指定します。 - */ - suspend fun delete(id: String) -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaFileRenameService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaFileRenameService.kt deleted file mode 100644 index b130cb75..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaFileRenameService.kt +++ /dev/null @@ -1,30 +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.core.service.media - -interface MediaFileRenameService { - /** - * メディアをリネームします - * - * @param uploadName アップロードされた時点でのファイル名 - * @param uploadMimeType アップロードされた時点でのMimeType - * @param processedName 処理後のファイル名 - * @param processedMimeType 処理後のMimeType - * @return リネーム後のファイル名 - */ - fun rename(uploadName: String, uploadMimeType: MimeType, processedName: String, processedMimeType: MimeType): String -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt deleted file mode 100644 index f8754288..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt +++ /dev/null @@ -1,49 +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.core.service.media - -data class MediaSave( - val name: String, - 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/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSaveRequest.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSaveRequest.kt deleted file mode 100644 index 7e04f027..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSaveRequest.kt +++ /dev/null @@ -1,26 +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.core.service.media - -import java.nio.file.Path - -data class MediaSaveRequest( - val name: String, - val preffix: String, - val filePath: Path, - val thumbnailPath: Path? -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaService.kt deleted file mode 100644 index 386daa78..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaService.kt +++ /dev/null @@ -1,25 +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.core.service.media - -import dev.usbharu.hideout.core.domain.model.media.Media -import dev.usbharu.hideout.mastodon.interfaces.api.media.MediaRequest - -interface MediaService { - suspend fun uploadLocalMedia(mediaRequest: MediaRequest): Media - suspend fun uploadRemoteMedia(remoteMedia: RemoteMedia): Media -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt deleted file mode 100644 index d938d5df..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt +++ /dev/null @@ -1,218 +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.core.service.media - -import dev.usbharu.hideout.core.domain.exception.media.MediaSaveException -import dev.usbharu.hideout.core.domain.exception.media.UnsupportedMediaException -import dev.usbharu.hideout.core.domain.model.media.Media -import dev.usbharu.hideout.core.domain.model.media.MediaRepository -import dev.usbharu.hideout.core.service.media.converter.MediaProcessService -import dev.usbharu.hideout.mastodon.interfaces.api.media.MediaRequest -import dev.usbharu.hideout.util.withDelete -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service -import java.nio.file.Files -import javax.imageio.ImageIO -import dev.usbharu.hideout.core.domain.model.media.Media as EntityMedia - -@Service -@Suppress("TooGenericExceptionCaught") -class MediaServiceImpl( - private val mediaDataStore: MediaDataStore, - private val fileTypeDeterminationService: FileTypeDeterminationService, - private val mediaBlurhashService: MediaBlurhashService, - private val mediaRepository: MediaRepository, - private val mediaProcessServices: List, - private val remoteMediaDownloadService: RemoteMediaDownloadService, - private val renameService: MediaFileRenameService -) : MediaService { - @Suppress("LongMethod", "NestedBlockDepth") - override suspend fun uploadLocalMedia(mediaRequest: MediaRequest): EntityMedia { - val fileName = mediaRequest.file.name - logger.info( - "Media upload. filename:$fileName " + - "contentType:${mediaRequest.file.contentType}" - ) - - val tempFile = Files.createTempFile("hideout-tmp-file", ".tmp") - - tempFile.withDelete().use { - Files.newOutputStream(tempFile).use { outputStream -> - mediaRequest.file.inputStream.use { - it.transferTo(outputStream) - } - } - val mimeType = fileTypeDeterminationService.fileType(tempFile, fileName) - - val process = findMediaProcessor(mimeType).process( - mimeType, - fileName, - tempFile, - null - ) - - val dataMediaSave = MediaSaveRequest( - renameService.rename( - mediaRequest.file.name, - mimeType, - process.filePath.fileName.toString(), - process.fileMimeType - ), - "", - process.filePath, - process.thumbnailPath - ) - dataMediaSave.filePath.withDelete().use { - dataMediaSave.thumbnailPath.withDelete().use { - val save = try { - mediaDataStore.save(dataMediaSave) - } catch (e: Exception) { - logger.warn("Failed to save the media", e) - throw MediaSaveException("Failed to save the media.", e) - } - if (save.success.not()) { - save as FaildSavedMedia - logger.warn("Failed to save the media. reason: ${save.reason}") - logger.warn(save.description, save.trace) - throw MediaSaveException("Failed to save the media.") - } - save as SuccessSavedMedia - val blurHash = generateBlurhash(process) - return mediaRepository.save( - EntityMedia( - id = mediaRepository.generateId(), - name = fileName, - url = save.url, - remoteUrl = null, - thumbnailUrl = save.thumbnailUrl, - type = process.fileMimeType.fileType, - mimeType = process.fileMimeType, - blurHash = blurHash, - description = mediaRequest.description - ) - ) - } - } - } - } - - // TODO: 仮の処理として保存したように動かす - @Suppress("LongMethod", "NestedBlockDepth") - override suspend fun uploadRemoteMedia(remoteMedia: RemoteMedia): Media { - logger.info("MEDIA Remote media. filename:${remoteMedia.name} url:${remoteMedia.url}") - - val findByRemoteUrl = mediaRepository.findByRemoteUrl(remoteMedia.url) - if (findByRemoteUrl != null) { - logger.warn("DUPLICATED Remote media is duplicated. url: {}", remoteMedia.url) - return findByRemoteUrl - } - - remoteMediaDownloadService.download(remoteMedia.url).withDelete().use { - val mimeType = fileTypeDeterminationService.fileType(it.path, remoteMedia.name) - - val process = findMediaProcessor(mimeType).process(mimeType, remoteMedia.name, it.path, null) - - val mediaSaveRequest = MediaSaveRequest( - renameService.rename( - remoteMedia.name, - mimeType, - process.filePath.fileName.toString(), - process.fileMimeType - ), - "", - process.filePath, - process.thumbnailPath - ) - - mediaSaveRequest.filePath.withDelete().use { - mediaSaveRequest.filePath.withDelete().use { - val save = try { - mediaDataStore.save(mediaSaveRequest) - } catch (e: Exception) { - logger.warn("Failed to save the media", e) - throw MediaSaveException("Failed to save the media.", e) - } - - if (save is FaildSavedMedia) { - logger.warn("Failed to save the media. reason: ${save.reason}") - logger.warn(save.description, save.trace) - throw MediaSaveException("Failed to save the media.") - } - save as SuccessSavedMedia - val blurhash = generateBlurhash(process) - return mediaRepository.save( - EntityMedia( - id = mediaRepository.generateId(), - name = remoteMedia.name, - url = save.url, - remoteUrl = remoteMedia.url, - thumbnailUrl = save.thumbnailUrl, - type = process.fileMimeType.fileType, - mimeType = process.fileMimeType, - blurHash = blurhash - ) - ) - } - } - } - } - - private fun findMediaProcessor(mimeType: MimeType): MediaProcessService { - try { - return mediaProcessServices.first { - try { - it.isSupport(mimeType) - } catch (_: Exception) { - false - } - } - } catch (_: NoSuchElementException) { - throw UnsupportedMediaException("MediaType: $mimeType isn't supported.") - } - } - - private fun generateBlurhash(process: ProcessedMediaPath): String { - val path = if (process.thumbnailPath != null && process.thumbnailMimeType != null) { - process.thumbnailPath - } else { - process.filePath - } - val mimeType = if (process.thumbnailPath != null && process.thumbnailMimeType != null) { - process.thumbnailMimeType - } else { - process.fileMimeType - } - - val imageReadersByMIMEType = ImageIO.getImageReadersByMIMEType(mimeType.type + "/" + mimeType.subtype) - for (imageReader in imageReadersByMIMEType) { - try { - val bufferedImage = ImageIO.createImageInputStream(path.toFile()).use { - imageReader.input = it - imageReader.read(0) - } - return mediaBlurhashService.generateBlurhash(bufferedImage) - } catch (e: Exception) { - logger.warn("Failed to read thumbnail", e) - } - } - return "" - } - - companion object { - private val logger = LoggerFactory.getLogger(MediaServiceImpl::class.java) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt deleted file mode 100644 index d02f3be1..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt +++ /dev/null @@ -1,40 +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.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/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedMedia.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedMedia.kt deleted file mode 100644 index 8b1a1aff..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedMedia.kt +++ /dev/null @@ -1,22 +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.core.service.media - -data class ProcessedMedia( - val file: ProcessedFile, - val thumbnail: ProcessedFile? -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedMediaPath.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedMediaPath.kt deleted file mode 100644 index 61023d3e..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedMediaPath.kt +++ /dev/null @@ -1,26 +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.core.service.media - -import java.nio.file.Path - -data class ProcessedMediaPath( - val filePath: Path, - val thumbnailPath: Path?, - val fileMimeType: MimeType, - val thumbnailMimeType: MimeType? -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMedia.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMedia.kt deleted file mode 100644 index 0a2c21d9..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMedia.kt +++ /dev/null @@ -1,24 +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.core.service.media - -data class RemoteMedia( - val name: String, - val url: String, - val mediaType: String, - val description: String? = null -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadService.kt deleted file mode 100644 index a23f0b10..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadService.kt +++ /dev/null @@ -1,23 +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.core.service.media - -import java.nio.file.Path - -interface RemoteMediaDownloadService { - suspend fun download(url: String): Path -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadServiceImpl.kt deleted file mode 100644 index 26843782..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadServiceImpl.kt +++ /dev/null @@ -1,61 +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.core.service.media - -import dev.usbharu.hideout.application.config.MediaConfig -import dev.usbharu.hideout.core.domain.exception.media.RemoteMediaFileSizeException -import dev.usbharu.hideout.core.service.resource.KtorResourceResolveService -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service -import java.nio.file.Files -import java.nio.file.Path -import kotlin.io.path.outputStream - -@Service -class RemoteMediaDownloadServiceImpl( - private val resourceResolveService: KtorResourceResolveService, - private val mediaConfig: MediaConfig -) : - RemoteMediaDownloadService { - override suspend fun download(url: String): Path { - logger.info("START Download remote file. url: {}", url) - val httpResponse = resourceResolveService.resolve(url).body() - val createTempFile = Files.createTempFile("hideout-remote-download", ".tmp") - - logger.debug("Save to {} url: {} ", createTempFile, url) - - httpResponse.use { inputStream -> - createTempFile.outputStream().use { - inputStream.transferTo(it) - } - } - - val contentLength = createTempFile.toFile().length() - if (contentLength >= mediaConfig.remoteMediaFileSizeLimit) { - throw RemoteMediaFileSizeException( - "File size is too large. $contentLength >= ${mediaConfig.remoteMediaFileSizeLimit}" - ) - } - - logger.info("SUCCESS Download remote file. url: {}", url) - return createTempFile - } - - companion object { - private val logger = LoggerFactory.getLogger(RemoteMediaDownloadServiceImpl::class.java) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/S3MediaDataStore.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/S3MediaDataStore.kt deleted file mode 100644 index 8fb8ee8f..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/S3MediaDataStore.kt +++ /dev/null @@ -1,139 +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.core.service.media - -import dev.usbharu.hideout.application.config.S3StorageConfig -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.async -import kotlinx.coroutines.awaitAll -import kotlinx.coroutines.withContext -import org.slf4j.LoggerFactory -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.stereotype.Service -import software.amazon.awssdk.core.sync.RequestBody -import software.amazon.awssdk.services.s3.S3Client -import software.amazon.awssdk.services.s3.model.DeleteObjectRequest -import software.amazon.awssdk.services.s3.model.GetUrlRequest -import software.amazon.awssdk.services.s3.model.PutObjectRequest - -@Service -@ConditionalOnProperty("hideout.storage.type", havingValue = "s3") -class S3MediaDataStore(private val s3Client: S3Client, private val s3StorageConfig: S3StorageConfig) : MediaDataStore { - override suspend fun save(dataMediaSave: MediaSave): SavedMedia { - val fileUploadRequest = PutObjectRequest.builder() - .bucket(s3StorageConfig.bucket) - .key(dataMediaSave.name) - .build() - - val thumbnailKey = "thumbnail-${dataMediaSave.name}" - val thumbnailUploadRequest = PutObjectRequest.builder() - .bucket(s3StorageConfig.bucket) - .key(thumbnailKey) - .build() - - withContext(Dispatchers.IO) { - awaitAll( - async { - if (dataMediaSave.thumbnailInputStream != null) { - s3Client.putObject( - thumbnailUploadRequest, - RequestBody.fromBytes(dataMediaSave.thumbnailInputStream) - ) - s3Client.utilities() - .getUrl(GetUrlRequest.builder().bucket(s3StorageConfig.bucket).key(thumbnailKey).build()) - } else { - null - } - }, - async { - s3Client.putObject(fileUploadRequest, RequestBody.fromBytes(dataMediaSave.fileInputStream)) - s3Client.utilities() - .getUrl(GetUrlRequest.builder().bucket(s3StorageConfig.bucket).key(dataMediaSave.name).build()) - } - ) - } - return SuccessSavedMedia( - name = dataMediaSave.name, - url = "${s3StorageConfig.publicUrl}/${s3StorageConfig.bucket}/${dataMediaSave.name}", - thumbnailUrl = "${s3StorageConfig.publicUrl}/${s3StorageConfig.bucket}/$thumbnailKey" - ) - } - - override suspend fun save(dataSaveRequest: MediaSaveRequest): SavedMedia { - logger.info("MEDIA upload. {}", dataSaveRequest.name) - - val fileUploadRequest = PutObjectRequest.builder() - .bucket(s3StorageConfig.bucket) - .key(dataSaveRequest.name) - .build() - - logger.info("MEDIA upload. bucket: {} key: {}", s3StorageConfig.bucket, dataSaveRequest.name) - - val thumbnailKey = "thumbnail-${dataSaveRequest.name}" - val thumbnailUploadRequest = PutObjectRequest.builder() - .bucket(s3StorageConfig.bucket) - .key(thumbnailKey) - .build() - - logger.info("MEDIA upload. bucket: {} key: {}", s3StorageConfig.bucket, thumbnailKey) - - withContext(Dispatchers.IO) { - awaitAll( - async { - if (dataSaveRequest.thumbnailPath != null) { - s3Client.putObject( - thumbnailUploadRequest, - RequestBody.fromFile(dataSaveRequest.thumbnailPath) - ) - } else { - null - } - }, - async { - s3Client.putObject(fileUploadRequest, RequestBody.fromFile(dataSaveRequest.filePath)) - } - ) - } - val successSavedMedia = SuccessSavedMedia( - name = dataSaveRequest.name, - url = "${s3StorageConfig.publicUrl}/${s3StorageConfig.bucket}/${dataSaveRequest.name}", - thumbnailUrl = "${s3StorageConfig.publicUrl}/${s3StorageConfig.bucket}/$thumbnailKey" - ) - - logger.info("SUCCESS Media upload. {}", dataSaveRequest.name) - logger.debug( - "name: {} url: {} thumbnail url: {}", - successSavedMedia.name, - successSavedMedia.url, - successSavedMedia.thumbnailUrl - ) - - return successSavedMedia - } - - override suspend fun delete(id: String) { - val fileDeleteRequest = DeleteObjectRequest.builder().bucket(s3StorageConfig.bucket).key(id).build() - val thumbnailDeleteRequest = - DeleteObjectRequest.builder().bucket(s3StorageConfig.bucket).key("thumbnail-$id").build() - s3Client.deleteObject(fileDeleteRequest) - s3Client.deleteObject(thumbnailDeleteRequest) - } - - companion object { - private val logger = LoggerFactory.getLogger(S3MediaDataStore::class.java) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt deleted file mode 100644 index 14413c25..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt +++ /dev/null @@ -1,87 +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.core.service.media - -sealed class SavedMedia(val success: Boolean) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as SavedMedia - - return success == other.success - } - - override fun hashCode(): Int = success.hashCode() -} - -class SuccessSavedMedia( - val name: String, - val url: String, - val thumbnailUrl: String, -) : - SavedMedia(true) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - if (!super.equals(other)) return false - - other as SuccessSavedMedia - - if (name != other.name) return false - if (url != other.url) return false - if (thumbnailUrl != other.thumbnailUrl) return false - - return true - } - - override fun hashCode(): Int { - var result = super.hashCode() - result = 31 * result + name.hashCode() - result = 31 * result + url.hashCode() - result = 31 * result + thumbnailUrl.hashCode() - return result - } -} - -class FaildSavedMedia( - val reason: String, - val description: String, - val trace: Throwable? = null -) : SavedMedia(false) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - if (!super.equals(other)) return false - - other as FaildSavedMedia - - if (reason != other.reason) return false - if (description != other.description) return false - if (trace != other.trace) return false - - return true - } - - override fun hashCode(): Int { - var result = super.hashCode() - result = 31 * result + reason.hashCode() - result = 31 * result + description.hashCode() - result = 31 * result + (trace?.hashCode() ?: 0) - return result - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ThumbnailGenerateService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ThumbnailGenerateService.kt deleted file mode 100644 index 71258673..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ThumbnailGenerateService.kt +++ /dev/null @@ -1,24 +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.core.service.media - -import java.io.InputStream - -interface ThumbnailGenerateService { - fun generate(bufferedImage: InputStream, width: Int, height: Int): ProcessedFile? - fun generate(outputStream: ByteArray, width: Int, height: Int): ProcessedFile? -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ThumbnailGenerateServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ThumbnailGenerateServiceImpl.kt deleted file mode 100644 index c23fb2a6..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/ThumbnailGenerateServiceImpl.kt +++ /dev/null @@ -1,42 +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.core.service.media - -import org.springframework.stereotype.Service -import java.awt.image.BufferedImage -import java.io.ByteArrayOutputStream -import java.io.InputStream -import javax.imageio.ImageIO - -@Service -class ThumbnailGenerateServiceImpl : ThumbnailGenerateService { - override fun generate(bufferedImage: InputStream, width: Int, height: Int): ProcessedFile? { - val image = ImageIO.read(bufferedImage) - return internalGenerate(image) - } - - override fun generate(outputStream: ByteArray, width: Int, height: Int): ProcessedFile? { - val image = ImageIO.read(outputStream.inputStream()) - return internalGenerate(image) - } - - private fun internalGenerate(image: BufferedImage): ProcessedFile { - val byteArrayOutputStream = ByteArrayOutputStream() - ImageIO.write(image, "jpeg", byteArrayOutputStream) - return ProcessedFile(byteArrayOutputStream.toByteArray(), "jpg") - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/UUIDMediaFileRenameService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/UUIDMediaFileRenameService.kt deleted file mode 100644 index 3a9e748f..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/UUIDMediaFileRenameService.kt +++ /dev/null @@ -1,32 +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.core.service.media - -import org.springframework.beans.factory.annotation.Qualifier -import org.springframework.stereotype.Service -import java.util.* - -@Qualifier("uuid") -@Service -class UUIDMediaFileRenameService : MediaFileRenameService { - override fun rename( - uploadName: String, - uploadMimeType: MimeType, - processedName: String, - processedMimeType: MimeType - ): String = "${UUID.randomUUID()}.${uploadMimeType.subtype}.${processedMimeType.subtype}" -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverter.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverter.kt deleted file mode 100644 index e7767896..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverter.kt +++ /dev/null @@ -1,26 +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.core.service.media.converter - -import dev.usbharu.hideout.core.service.media.FileType -import dev.usbharu.hideout.core.service.media.ProcessedFile -import java.io.InputStream - -interface MediaConverter { - fun isSupport(fileType: FileType): Boolean - fun convert(inputStream: InputStream): ProcessedFile -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverterRoot.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverterRoot.kt deleted file mode 100644 index 5b837f7c..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverterRoot.kt +++ /dev/null @@ -1,30 +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.core.service.media.converter - -import dev.usbharu.hideout.core.service.media.FileType -import dev.usbharu.hideout.core.service.media.ProcessedFile -import java.io.InputStream - -interface MediaConverterRoot { - suspend fun convert( - fileType: FileType, - contentType: String, - filename: String, - inputStream: InputStream - ): ProcessedFile -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverterRootImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverterRootImpl.kt deleted file mode 100644 index 79c44ec3..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaConverterRootImpl.kt +++ /dev/null @@ -1,48 +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.core.service.media.converter - -import dev.usbharu.hideout.core.service.media.FileType -import dev.usbharu.hideout.core.service.media.ProcessedFile -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -import org.springframework.stereotype.Service -import java.io.InputStream - -@Service -class MediaConverterRootImpl(private val converters: List) : MediaConverterRoot { - override suspend fun convert( - fileType: FileType, - contentType: String, - filename: String, - inputStream: InputStream - ): ProcessedFile { - val convert = converters.find { - it.isSupport(fileType) - }?.convert(inputStream) - if (convert != null) { - return convert - } - return withContext(Dispatchers.IO) { - if (filename.contains('.')) { - ProcessedFile(inputStream.readAllBytes(), filename.substringAfterLast(".")) - } else { - ProcessedFile(inputStream.readAllBytes(), contentType.substringAfterLast("/")) - } - } - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaProcessService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaProcessService.kt deleted file mode 100644 index 53a11fc7..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaProcessService.kt +++ /dev/null @@ -1,42 +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.core.service.media.converter - -import dev.usbharu.hideout.core.service.media.FileType -import dev.usbharu.hideout.core.service.media.MimeType -import dev.usbharu.hideout.core.service.media.ProcessedMedia -import dev.usbharu.hideout.core.service.media.ProcessedMediaPath -import java.nio.file.Path - -interface MediaProcessService { - fun isSupport(mimeType: MimeType): Boolean - - suspend fun process( - fileType: FileType, - contentType: String, - fileName: String, - file: ByteArray, - thumbnail: ByteArray? - ): ProcessedMedia - - suspend fun process( - mimeType: MimeType, - fileName: String, - filePath: Path, - thumbnails: Path? - ): ProcessedMediaPath -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaProcessServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaProcessServiceImpl.kt deleted file mode 100644 index bd5f5f0a..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/MediaProcessServiceImpl.kt +++ /dev/null @@ -1,74 +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.core.service.media.converter - -import dev.usbharu.hideout.core.domain.exception.media.MediaConvertException -import dev.usbharu.hideout.core.service.media.* -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service -import java.nio.file.Path - -@Service -@Suppress("TooGenericExceptionCaught") -class MediaProcessServiceImpl( - private val mediaConverterRoot: MediaConverterRoot, - private val thumbnailGenerateService: ThumbnailGenerateService -) : MediaProcessService { - override fun isSupport(mimeType: MimeType): Boolean = false - - override suspend fun process( - fileType: FileType, - contentType: String, - filename: String, - file: ByteArray, - thumbnail: ByteArray? - ): ProcessedMedia { - val fileInputStream = try { - mediaConverterRoot.convert(fileType, contentType, filename, file.inputStream().buffered()) - } catch (e: Exception) { - logger.warn("Failed convert media.", e) - throw MediaConvertException("Failed convert media.", e) - } - val thumbnailInputStream = try { - thumbnail?.let { mediaConverterRoot.convert(fileType, contentType, filename, it.inputStream().buffered()) } - } catch (e: Exception) { - logger.warn("Failed convert thumbnail media.", e) - null - } - return ProcessedMedia( - fileInputStream, - thumbnailGenerateService.generate( - thumbnailInputStream?.byteArray ?: file, - 2048, - 2048 - ) - ) - } - - override suspend fun process( - mimeType: MimeType, - fileName: String, - filePath: Path, - thumbnails: Path? - ): ProcessedMediaPath { - TODO("Not yet implemented") - } - - companion object { - private val logger = LoggerFactory.getLogger(MediaProcessServiceImpl::class.java) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessService.kt deleted file mode 100644 index c41b7da8..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessService.kt +++ /dev/null @@ -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.core.service.media.converter.image - -import dev.usbharu.hideout.core.domain.exception.media.MediaProcessException -import dev.usbharu.hideout.core.service.media.FileType -import dev.usbharu.hideout.core.service.media.MimeType -import dev.usbharu.hideout.core.service.media.ProcessedMedia -import dev.usbharu.hideout.core.service.media.ProcessedMediaPath -import dev.usbharu.hideout.core.service.media.converter.MediaProcessService -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.slf4j.MDCContext -import kotlinx.coroutines.withContext -import net.coobird.thumbnailator.Thumbnails -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Qualifier -import org.springframework.stereotype.Service -import java.awt.Color -import java.awt.image.BufferedImage -import java.nio.file.Files -import java.nio.file.Path -import java.util.* -import javax.imageio.ImageIO -import kotlin.io.path.inputStream -import kotlin.io.path.outputStream - -@Service -@Qualifier("image") -class ImageMediaProcessService(private val imageMediaProcessorConfiguration: ImageMediaProcessorConfiguration?) : - MediaProcessService { - - private val convertType = imageMediaProcessorConfiguration?.convert ?: "jpeg" - - private val supportedTypes = imageMediaProcessorConfiguration?.supportedType ?: listOf("webp", "jpeg", "png") - - private val genThumbnail = imageMediaProcessorConfiguration?.thubnail?.generate ?: true - - private val width = imageMediaProcessorConfiguration?.thubnail?.width ?: 1000 - private val height = imageMediaProcessorConfiguration?.thubnail?.height ?: 1000 - - override fun isSupport(mimeType: MimeType): Boolean { - if (mimeType.type != "image") { - return false - } - return supportedTypes.contains(mimeType.subtype) - } - - override suspend fun process( - fileType: FileType, - contentType: String, - fileName: String, - file: ByteArray, - thumbnail: ByteArray? - ): ProcessedMedia { - TODO("Not yet implemented") - } - - override suspend fun process( - mimeType: MimeType, - fileName: String, - filePath: Path, - thumbnails: Path? - ): ProcessedMediaPath = withContext(Dispatchers.IO + MDCContext()) { - val read = ImageIO.read(filePath.inputStream()) - - val bufferedImage = BufferedImage(read.width, read.height, BufferedImage.TYPE_INT_RGB) - - val graphics = bufferedImage.createGraphics() - - graphics.drawImage(read, 0, 0, Color.BLACK, null) - - val tempFileName = UUID.randomUUID().toString() - val tempFile = Files.createTempFile(tempFileName, "tmp") - - val thumbnailPath = if (genThumbnail) { - val tempThumbnailFile = Files.createTempFile("thumbnail-$tempFileName", ".tmp") - - tempThumbnailFile.outputStream().use { - val write = ImageIO.write( - if (thumbnails != null) { - Thumbnails.of(thumbnails.toFile()) - .size(width, height) - .imageType(BufferedImage.TYPE_INT_RGB) - .asBufferedImage() - } else { - Thumbnails.of(bufferedImage) - .size(width, height) - .imageType(BufferedImage.TYPE_INT_RGB) - .asBufferedImage() - }, - convertType, - it - ) - tempThumbnailFile.takeIf { write } - } - } else { - null - } - - tempFile.outputStream().use { - if (ImageIO.write(bufferedImage, convertType, it).not()) { - logger.warn("Failed to save a temporary file. type: {} ,path: {}", convertType, tempFile) - throw MediaProcessException("Failed to save a temporary file.") - } - } - ProcessedMediaPath( - tempFile, - thumbnailPath, - MimeType("image", convertType, FileType.Image), - MimeType("image", convertType, FileType.Image).takeIf { genThumbnail } - ) - } - - companion object { - private val logger = LoggerFactory.getLogger(ImageMediaProcessService::class.java) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessorConfiguration.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessorConfiguration.kt deleted file mode 100644 index cd24a7d3..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessorConfiguration.kt +++ /dev/null @@ -1,33 +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.core.service.media.converter.image - -import org.springframework.boot.context.properties.ConfigurationProperties - -@ConfigurationProperties("hideout.media.image") -data class ImageMediaProcessorConfiguration( - val convert: String?, - val thubnail: ImageMediaProcessorThumbnailConfiguration?, - val supportedType: List?, - -) - -data class ImageMediaProcessorThumbnailConfiguration( - val generate: Boolean, - val width: Int, - val height: Int -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/movie/MovieMediaProcessService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/movie/MovieMediaProcessService.kt deleted file mode 100644 index bf8465e1..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/movie/MovieMediaProcessService.kt +++ /dev/null @@ -1,143 +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.core.service.media.converter.movie - -import dev.usbharu.hideout.core.service.media.FileType -import dev.usbharu.hideout.core.service.media.MimeType -import dev.usbharu.hideout.core.service.media.ProcessedMedia -import dev.usbharu.hideout.core.service.media.ProcessedMediaPath -import dev.usbharu.hideout.core.service.media.converter.MediaProcessService -import org.bytedeco.ffmpeg.global.avcodec -import org.bytedeco.javacv.FFmpegFrameFilter -import org.bytedeco.javacv.FFmpegFrameGrabber -import org.bytedeco.javacv.FFmpegFrameRecorder -import org.bytedeco.javacv.Java2DFrameConverter -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Qualifier -import org.springframework.stereotype.Service -import java.awt.image.BufferedImage -import java.nio.file.Files -import java.nio.file.Path -import javax.imageio.ImageIO -import kotlin.math.min - -@Service -@Qualifier("video") -class MovieMediaProcessService : MediaProcessService { - override fun isSupport(mimeType: MimeType): Boolean = mimeType.type == "video" - - override suspend fun process( - fileType: FileType, - contentType: String, - fileName: String, - file: ByteArray, - thumbnail: ByteArray? - ): ProcessedMedia { - TODO("Not yet implemented") - } - - @Suppress("LongMethod", "NestedBlockDepth", "CognitiveComplexMethod") - override suspend fun process( - mimeType: MimeType, - fileName: String, - filePath: Path, - thumbnails: Path? - ): ProcessedMediaPath { - val tempFile = Files.createTempFile("hideout-movie-processor-", ".tmp") - val thumbnailFile = Files.createTempFile("hideout-movie-thumbnail-generate-", ".tmp") - logger.info("START Convert Movie Media {}", fileName) - FFmpegFrameGrabber(filePath.toFile()).use { grabber -> - grabber.start() - val width = grabber.imageWidth - val height = grabber.imageHeight - val frameRate = 60.0 - - logger.debug("Movie Media Width {}, Height {}", width, height) - - FFmpegFrameFilter( - "fps=fps=${frameRate.toInt()}", - "anull", - width, - height, - grabber.audioChannels - ).use { filter -> - - filter.sampleFormat = grabber.sampleFormat - filter.sampleRate = grabber.sampleRate - filter.pixelFormat = grabber.pixelFormat - filter.frameRate = grabber.frameRate - filter.start() - - val videoBitRate = min(1300000, (width * height * frameRate * 1 * 0.07).toInt()) - - logger.debug("Movie Media BitRate {}", videoBitRate) - - FFmpegFrameRecorder(tempFile.toFile(), width, height, grabber.audioChannels).use { - it.sampleRate = grabber.sampleRate - it.format = "mp4" - it.videoCodec = avcodec.AV_CODEC_ID_H264 - it.audioCodec = avcodec.AV_CODEC_ID_AAC - it.audioChannels = grabber.audioChannels - it.videoQuality = 1.0 - it.frameRate = frameRate - it.setVideoOption("preset", "ultrafast") - it.timestamp = 0 - it.gopSize = frameRate.toInt() - it.videoBitrate = videoBitRate - it.start() - - var bufferedImage: BufferedImage? = null - - val frameConverter = Java2DFrameConverter() - - while (true) { - val grab = grabber.grab() ?: break - - if (bufferedImage == null) { - bufferedImage = frameConverter.convert(grab) - } - - if (grab.image != null || grab.samples != null) { - filter.push(grab) - } - while (true) { - val frame = filter.pull() ?: break - it.record(frame) - } - } - - if (bufferedImage != null) { - ImageIO.write(bufferedImage, "jpeg", thumbnailFile.toFile()) - } - } - } - } - - logger.info("SUCCESS Convert Movie Media {}", fileName) - - return ProcessedMediaPath( - tempFile, - thumbnailFile, - MimeType("video", "mp4", FileType.Video), - MimeType("image", "jpeg", FileType.Image) - ) - } - - companion object { - private val logger = LoggerFactory.getLogger(MovieMediaProcessService::class.java) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationRequest.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationRequest.kt deleted file mode 100644 index 8f4c382f..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationRequest.kt +++ /dev/null @@ -1,136 +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.core.service.notification - -import dev.usbharu.hideout.core.domain.model.notification.Notification -import java.time.Instant - -sealed class NotificationRequest(open val userId: Long, open val sourceActorId: Long?, val type: String) { - abstract fun buildNotification(id: Long, createdAt: Instant): Notification -} - -interface PostId { - val postId: Long -} - -data class MentionNotificationRequest( - override val userId: Long, - override val sourceActorId: Long, - override val postId: Long -) : NotificationRequest( - userId, - sourceActorId, - "mention" -), - PostId { - override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id = id, - type = type, - userId = userId, - sourceActorId = sourceActorId, - postId = postId, - text = null, - reactionId = null, - createdAt = createdAt - ) -} - -data class PostNotificationRequest( - override val userId: Long, - override val sourceActorId: Long, - override val postId: Long - -) : NotificationRequest(userId, sourceActorId, "post"), PostId { - override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id = id, - type = type, - userId = userId, - sourceActorId = sourceActorId, - postId = postId, - text = null, - reactionId = null, - createdAt = createdAt - ) -} - -data class RepostNotificationRequest( - override val userId: Long, - override val sourceActorId: Long, - override val postId: Long -) : NotificationRequest(userId, sourceActorId, "repost"), PostId { - override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id = id, - type = type, - userId = userId, - sourceActorId = sourceActorId, - postId = postId, - text = null, - reactionId = null, - createdAt = createdAt - ) -} - -data class FollowNotificationRequest( - override val userId: Long, - override val sourceActorId: Long -) : NotificationRequest(userId, sourceActorId, "follow") { - override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id = id, - type = type, - userId = userId, - sourceActorId = sourceActorId, - postId = null, - text = null, - reactionId = null, - createdAt = createdAt - ) -} - -data class FollowRequestNotificationRequest( - override val userId: Long, - override val sourceActorId: Long -) : NotificationRequest(userId, sourceActorId, "follow-request") { - override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id = id, - type = type, - userId = userId, - sourceActorId = sourceActorId, - postId = null, - text = null, - reactionId = null, - createdAt = createdAt - ) -} - -data class ReactionNotificationRequest( - override val userId: Long, - override val sourceActorId: Long, - override val postId: Long, - val reactionId: Long - -) : NotificationRequest(userId, sourceActorId, "reaction"), PostId { - override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id = id, - type = type, - userId = userId, - sourceActorId = sourceActorId, - postId = postId, - text = null, - reactionId = reactionId, - createdAt = createdAt - ) -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationService.kt deleted file mode 100644 index 14354b26..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationService.kt +++ /dev/null @@ -1,24 +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.core.service.notification - -import dev.usbharu.hideout.core.domain.model.notification.Notification - -interface NotificationService { - suspend fun publishNotify(notificationRequest: NotificationRequest): Notification? - suspend fun unpublishNotify(notificationId: Long) -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationServiceImpl.kt deleted file mode 100644 index 189ac6fc..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationServiceImpl.kt +++ /dev/null @@ -1,110 +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.core.service.notification - -import dev.usbharu.hideout.application.config.ApplicationConfig -import dev.usbharu.hideout.core.domain.model.notification.Notification -import dev.usbharu.hideout.core.domain.model.notification.NotificationRepository -import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service -import java.time.Instant - -@Service -class NotificationServiceImpl( - private val relationshipNotificationManagementService: RelationshipNotificationManagementService, - private val relationshipRepository: RelationshipRepository, - private val notificationStoreList: List, - private val notificationRepository: NotificationRepository, - private val actorRepository: ActorRepository, - private val postRepository: PostRepository, - private val reactionRepository: ReactionRepository, - private val applicationConfig: ApplicationConfig -) : NotificationService { - override suspend fun publishNotify(notificationRequest: NotificationRequest): Notification? { - logger.debug("NOTIFICATION REQUEST user: {} type: {}", notificationRequest.userId, notificationRequest.type) - logger.trace("NotificationRequest: {}", notificationRequest) - - val user = actorRepository.findById(notificationRequest.userId) - if (user == null || user.domain != applicationConfig.url.host) { - logger.debug("NOTIFICATION REQUEST is rejected. (Remote Actor or user not found.)") - return null - } - - // とりあえず個人間のRelationshipに基づいてきめる。今後増やす - if (!relationship(notificationRequest)) { - logger.debug("NOTIFICATION REQUEST is rejected. (relationship)") - return null - } - - val id = notificationRepository.generateId() - val createdAt = Instant.now() - - val notification = notificationRequest.buildNotification(id, createdAt) - - val savedNotification = notificationRepository.save(notification) - - val sourceActor = savedNotification.sourceActorId?.let { actorRepository.findById(it) } - - val post = savedNotification.postId?.let { postRepository.findById(it) } - val reaction = savedNotification.reactionId?.let { reactionRepository.findById(it) } - - logger.info( - "NOTIFICATION id: {} user: {} type: {}", - savedNotification.id, - savedNotification.userId, - savedNotification.type - ) - - logger.debug("push to {} notification store.", notificationStoreList.size) - for (it in notificationStoreList) { - @Suppress("TooGenericExceptionCaught") - try { - it.publishNotification(savedNotification, user, sourceActor, post, reaction) - } catch (e: Exception) { - logger.warn("FAILED Publish to notification.", e) - } - } - logger.debug("SUCCESS Notification id: {}", savedNotification.id) - - return savedNotification - } - - override suspend fun unpublishNotify(notificationId: Long) { - notificationRepository.deleteById(notificationId) - for (notificationStore in notificationStoreList) { - notificationStore.unpulishNotification(notificationId) - } - } - - /** - * 個人間のRelationshipに基づいて通知を送信するか判断します - * - * @param notificationRequest - * @return trueの場合送信する - */ - private suspend fun relationship(notificationRequest: NotificationRequest): Boolean { - val targetActorId = notificationRequest.sourceActorId ?: return true - val relationship = - relationshipRepository.findByUserIdAndTargetUserId(notificationRequest.userId, targetActorId) ?: return true - return relationshipNotificationManagementService.sendNotification(relationship, notificationRequest) - } - - companion object { - private val logger = LoggerFactory.getLogger(NotificationServiceImpl::class.java) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementService.kt deleted file mode 100644 index d7c89265..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementService.kt +++ /dev/null @@ -1,23 +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.core.service.notification - -import dev.usbharu.hideout.core.domain.model.relationship.Relationship - -interface RelationshipNotificationManagementService { - fun sendNotification(relationship: Relationship, notificationRequest: NotificationRequest): Boolean -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementServiceImpl.kt deleted file mode 100644 index 0f1bd478..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementServiceImpl.kt +++ /dev/null @@ -1,26 +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.core.service.notification - -import dev.usbharu.hideout.core.domain.model.relationship.Relationship -import org.springframework.stereotype.Service - -@Service -class RelationshipNotificationManagementServiceImpl : RelationshipNotificationManagementService { - override fun sendNotification(relationship: Relationship, notificationRequest: NotificationRequest): Boolean = - relationship.muting.not() -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt deleted file mode 100644 index bc203296..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt +++ /dev/null @@ -1,99 +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.core.service.post - -import org.jsoup.Jsoup -import org.jsoup.nodes.Document -import org.jsoup.nodes.Element -import org.jsoup.nodes.TextNode -import org.jsoup.select.Elements -import org.owasp.html.PolicyFactory -import org.springframework.stereotype.Service - -@Service -class DefaultPostContentFormatter(private val policyFactory: PolicyFactory) : PostContentFormatter { - override fun format(content: String): FormattedPostContent { - // まず不正なHTMLを整形する - val document = Jsoup.parseBodyFragment(content) - val outputSettings = Document.OutputSettings() - outputSettings.prettyPrint(false) - - document.outputSettings(outputSettings) - - val unsafeElement = document.getElementsByTag("body").first() ?: return FormattedPostContent( - "", - "" - ) - - // 文字だけのHTMLなどはここでpタグで囲む - val flattenHtml = unsafeElement.childNodes().mapNotNull { - if (it is Element) { - it - } else if (it is TextNode) { - Element("p").appendText(it.text()) - } else { - null - } - }.filter { it.text().isNotBlank() } - - // HTMLのサニタイズをする - val unsafeHtml = Elements(flattenHtml).outerHtml() - - val safeHtml = policyFactory.sanitize(unsafeHtml) - - val safeDocument = - Jsoup.parseBodyFragment(safeHtml).getElementsByTag("body").first() ?: return FormattedPostContent("", "") - - val formattedHtml = mutableListOf() - - // 連続するbrタグを段落に変換する - for (element in safeDocument.children()) { - var brCount = 0 - var prevIndex = 0 - val childNodes = element.childNodes() - for ((index, childNode) in childNodes.withIndex()) { - if (childNode is Element && childNode.tagName() == "br") { - brCount++ - } else if (brCount >= 2) { - formattedHtml.add(Element("p").appendChildren(childNodes.subList(prevIndex, index - brCount))) - prevIndex = index - } - } - formattedHtml.add(Element("p").appendChildren(childNodes.subList(prevIndex, childNodes.size))) - } - - val elements = Elements(formattedHtml) - - return FormattedPostContent(elements.outerHtml().replace("\n", ""), printHtml(elements)) - } - - private fun printHtml(element: Elements): String { - return element.joinToString("\n\n") { - it.childNodes().joinToString("") { node -> - if (node is Element && node.tagName() == "br") { - "\n" - } else if (node is Element) { - node.text() - } else if (node is TextNode) { - node.text() - } else { - "" - } - } - } - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostContentFormatter.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostContentFormatter.kt deleted file mode 100644 index 7a0269d5..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostContentFormatter.kt +++ /dev/null @@ -1,21 +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.core.service.post - -interface PostContentFormatter { - fun format(content: String): FormattedPostContent -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostCreateDto.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostCreateDto.kt deleted file mode 100644 index f2450dd4..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostCreateDto.kt +++ /dev/null @@ -1,29 +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.core.service.post - -import dev.usbharu.hideout.core.domain.model.post.Visibility - -data class PostCreateDto( - val text: String, - val overview: String? = null, - val visibility: Visibility = Visibility.PUBLIC, - val repostId: Long? = null, - val repolyId: Long? = null, - val userId: Long, - val mediaIds: List = emptyList() -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionService.kt deleted file mode 100644 index 5b3421cc..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionService.kt +++ /dev/null @@ -1,28 +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.core.service.reaction - -import dev.usbharu.hideout.core.domain.model.emoji.Emoji -import org.springframework.stereotype.Service - -@Service -interface ReactionService { - suspend fun receiveReaction(emoji: Emoji, actorId: Long, postId: Long) - suspend fun receiveRemoveReaction(actorId: Long, postId: Long) - suspend fun sendReaction(emoji: Emoji, actorId: Long, postId: Long) - suspend fun removeReaction(actorId: Long, postId: Long) -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt deleted file mode 100644 index 26fe8d61..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt +++ /dev/null @@ -1,101 +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.core.service.reaction - -import dev.usbharu.hideout.activitypub.service.activity.like.APReactionService -import dev.usbharu.hideout.core.domain.exception.resource.DuplicateException -import dev.usbharu.hideout.core.domain.model.emoji.Emoji -import dev.usbharu.hideout.core.domain.model.reaction.Reaction -import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository -import dev.usbharu.hideout.core.service.notification.NotificationService -import dev.usbharu.hideout.core.service.notification.ReactionNotificationRequest -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service - -@Service -class ReactionServiceImpl( - private val reactionRepository: ReactionRepository, - private val apReactionService: APReactionService, - private val notificationService: NotificationService, - private val postRepository: PostRepository -) : ReactionService { - override suspend fun receiveReaction( - emoji: Emoji, - actorId: Long, - postId: Long - ) { - if (reactionRepository.existByPostIdAndActor(postId, actorId)) { - reactionRepository.deleteByPostIdAndActorId(postId, actorId) - } - try { - val reaction = reactionRepository.save(Reaction(reactionRepository.generateId(), emoji, postId, actorId)) - - notificationService.publishNotify( - ReactionNotificationRequest( - postRepository.findById(postId)!!.actorId, - actorId, - postId, - reaction.id - ) - ) - } catch (_: DuplicateException) { - } - } - - override suspend fun receiveRemoveReaction(actorId: Long, postId: Long) { - val reaction = reactionRepository.findByPostIdAndActorIdAndEmojiId(postId, actorId, 0) - if (reaction == null) { - LOGGER.warn("FAILED receive Remove Reaction. $actorId $postId") - return - } - reactionRepository.delete(reaction) - } - - override suspend fun sendReaction(emoji: Emoji, actorId: Long, postId: Long) { - val findByPostIdAndUserIdAndEmojiId = - reactionRepository.findByPostIdAndActorIdAndEmojiId(postId, actorId, 0) - - if (findByPostIdAndUserIdAndEmojiId != null) { - apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId) - reactionRepository.delete(findByPostIdAndUserIdAndEmojiId) - } - - val reaction = Reaction(reactionRepository.generateId(), emoji, postId, actorId) - reactionRepository.save(reaction) - apReactionService.reaction(reaction) - - val id = postRepository.findById(postId)!!.actorId - - notificationService.publishNotify(ReactionNotificationRequest(id, actorId, postId, reaction.id)) - } - - override suspend fun removeReaction(actorId: Long, postId: Long) { - val findByPostIdAndUserIdAndEmojiId = - reactionRepository.findByPostIdAndActorIdAndEmojiId(postId, actorId, 0) - if (findByPostIdAndUserIdAndEmojiId == null) { - LOGGER.warn("FAILED Remove reaction. actorId: $actorId postId: $postId") - return - } - reactionRepository.delete(findByPostIdAndUserIdAndEmojiId) - apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId) - } - - companion object { - val LOGGER: Logger = LoggerFactory.getLogger(ReactionServiceImpl::class.java) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/CacheManager.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/CacheManager.kt deleted file mode 100644 index 3e6408fe..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/CacheManager.kt +++ /dev/null @@ -1,22 +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.core.service.resource - -interface CacheManager { - suspend fun putCache(key: String, block: suspend () -> ResolveResponse) - suspend fun getOrWait(key: String): ResolveResponse -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt deleted file mode 100644 index 39c1239f..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt +++ /dev/null @@ -1,71 +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.core.service.resource - -import dev.usbharu.hideout.util.LruCache -import kotlinx.coroutines.delay -import kotlinx.coroutines.sync.Mutex -import kotlinx.coroutines.sync.withLock -import org.springframework.stereotype.Service -import java.time.Instant - -@Service -class InMemoryCacheManager : CacheManager { - private val cacheKey = LruCache(15) - private val valueStore = mutableMapOf() - private val keyMutex = Mutex() - - override suspend fun putCache(key: String, block: suspend () -> ResolveResponse) { - val needRunBlock: Boolean - keyMutex.withLock { - cacheKey.filter { Instant.ofEpochMilli(it.value).plusSeconds(300) <= Instant.now() } - - val cached = cacheKey[key] - if (cached == null) { - needRunBlock = true - cacheKey[key] = Instant.now().toEpochMilli() - - valueStore.remove(key) - } else { - needRunBlock = false - } - } - if (needRunBlock) { - @Suppress("TooGenericExceptionCaught") - val processed = try { - block() - } catch (e: Exception) { - cacheKey.remove(key) - throw e - } - - if (cacheKey.containsKey(key)) { - valueStore[key] = processed - } - } - } - - override suspend fun getOrWait(key: String): ResolveResponse { - while (valueStore.contains(key).not()) { - if (cacheKey.containsKey(key).not()) { - throw IllegalStateException("Invalid cache key. $key") - } - delay(1) - } - return valueStore.getValue(key) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResolveResponse.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResolveResponse.kt deleted file mode 100644 index c2453e7a..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResolveResponse.kt +++ /dev/null @@ -1,66 +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.core.service.resource - -import io.ktor.client.statement.* -import io.ktor.util.* -import io.ktor.utils.io.jvm.javaio.* -import java.io.InputStream - -class KtorResolveResponse(val ktorHttpResponse: HttpResponse) : ResolveResponse { - - private lateinit var _bodyAsText: String - private lateinit var _bodyAsBytes: ByteArray - - override suspend fun body(): InputStream = ktorHttpResponse.bodyAsChannel().toInputStream() - override suspend fun bodyAsText(): String { - if (!this::_bodyAsText.isInitialized) { - _bodyAsText = ktorHttpResponse.bodyAsText() - } - return _bodyAsText - } - - override suspend fun bodyAsBytes(): ByteArray { - if (!this::_bodyAsBytes.isInitialized) { - _bodyAsBytes = ktorHttpResponse.readBytes() - } - return _bodyAsBytes - } - - override suspend fun header(): Map> = ktorHttpResponse.headers.toMap() - override suspend fun status(): Int = ktorHttpResponse.status.value - override suspend fun statusMessage(): String = ktorHttpResponse.status.description - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as KtorResolveResponse - - if (ktorHttpResponse != other.ktorHttpResponse) return false - if (_bodyAsText != other._bodyAsText) return false - if (!_bodyAsBytes.contentEquals(other._bodyAsBytes)) return false - - return true - } - - override fun hashCode(): Int { - var result = ktorHttpResponse.hashCode() - result = 31 * result + _bodyAsText.hashCode() - result = 31 * result + _bodyAsBytes.contentHashCode() - return result - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResourceResolveService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResourceResolveService.kt deleted file mode 100644 index f8407b23..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResourceResolveService.kt +++ /dev/null @@ -1,53 +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.core.service.resource - -import dev.usbharu.hideout.application.config.MediaConfig -import dev.usbharu.hideout.core.domain.exception.media.RemoteMediaFileSizeException -import io.ktor.client.* -import io.ktor.client.request.* -import io.ktor.http.* -import org.springframework.stereotype.Service - -@Service -class KtorResourceResolveService( - private val httpClient: HttpClient, - private val cacheManager: CacheManager, - private val mediaConfig: MediaConfig -) : - ResourceResolveService { - - var sizeLimit = mediaConfig.remoteMediaFileSizeLimit - - override suspend fun resolve(url: String): ResolveResponse { - cacheManager.putCache(getCacheKey(url)) { - runResolve(url) - } - return cacheManager.getOrWait(getCacheKey(url)) - } - - protected suspend fun runResolve(url: String): ResolveResponse { - val httpResponse = httpClient.get(url) - val contentLength = httpResponse.contentLength() - if ((contentLength ?: 0) >= sizeLimit) { - throw RemoteMediaFileSizeException("File size is too large. $contentLength >= $sizeLimit") - } - return KtorResolveResponse(httpResponse) - } - - protected suspend fun getCacheKey(url: String) = url -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/ResolveResponse.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/ResolveResponse.kt deleted file mode 100644 index 8da3c7cb..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/ResolveResponse.kt +++ /dev/null @@ -1,28 +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.core.service.resource - -import java.io.InputStream - -interface ResolveResponse { - suspend fun body(): InputStream - suspend fun bodyAsText(): String - suspend fun bodyAsBytes(): ByteArray - suspend fun header(): Map> - suspend fun status(): Int - suspend fun statusMessage(): String -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/ResourceResolveService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/ResourceResolveService.kt deleted file mode 100644 index bcb1c97f..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/resource/ResourceResolveService.kt +++ /dev/null @@ -1,21 +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.core.service.resource - -interface ResourceResolveService { - suspend fun resolve(url: String): ResolveResponse -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/ExposedGenerateTimelineService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/ExposedGenerateTimelineService.kt deleted file mode 100644 index 98447037..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/ExposedGenerateTimelineService.kt +++ /dev/null @@ -1,68 +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.core.service.timeline - -import dev.usbharu.hideout.application.infrastructure.exposed.Page -import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList -import dev.usbharu.hideout.application.infrastructure.exposed.withPagination -import dev.usbharu.hideout.core.infrastructure.exposedrepository.Timelines -import dev.usbharu.hideout.domain.mastodon.model.generated.Status -import dev.usbharu.hideout.mastodon.interfaces.api.status.StatusQuery -import dev.usbharu.hideout.mastodon.query.StatusQueryService -import org.jetbrains.exposed.sql.andWhere -import org.jetbrains.exposed.sql.selectAll -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.stereotype.Service - -@Service -@ConditionalOnProperty("hideout.use-mongodb", havingValue = "false", matchIfMissing = true) -class ExposedGenerateTimelineService(private val statusQueryService: StatusQueryService) : GenerateTimelineService { - - override suspend fun getTimeline( - forUserId: Long?, - localOnly: Boolean, - mediaOnly: Boolean, - page: Page - ): PaginationList { - val query = Timelines.selectAll() - - if (forUserId != null) { - query.andWhere { Timelines.userId eq forUserId } - } - if (localOnly) { - query.andWhere { Timelines.isLocal eq true } - } - val result = query.withPagination(page, Timelines.id) - - val statusQueries = result.map { - StatusQuery( - it[Timelines.postId], - it[Timelines.replyId], - it[Timelines.repostId], - it[Timelines.mediaIds].split(",").mapNotNull { s -> s.toLongOrNull() }, - it[Timelines.emojiIds].split(",").mapNotNull { s -> s.toLongOrNull() } - ) - } - - val findByPostIdsWithMediaIds = statusQueryService.findByPostIdsWithMediaIds(statusQueries) - return PaginationList( - findByPostIdsWithMediaIds, - findByPostIdsWithMediaIds.lastOrNull()?.id?.toLongOrNull(), - findByPostIdsWithMediaIds.firstOrNull()?.id?.toLongOrNull() - ) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/GenerateTimelineService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/GenerateTimelineService.kt deleted file mode 100644 index a065a58d..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/GenerateTimelineService.kt +++ /dev/null @@ -1,34 +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.core.service.timeline - -import dev.usbharu.hideout.application.infrastructure.exposed.Page -import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList -import dev.usbharu.hideout.domain.mastodon.model.generated.Status -import org.springframework.stereotype.Service - -@Service -@Suppress("LongParameterList") -interface GenerateTimelineService { - - suspend fun getTimeline( - forUserId: Long? = null, - localOnly: Boolean = false, - mediaOnly: Boolean = false, - page: Page - ): PaginationList -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/MongoGenerateTimelineService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/MongoGenerateTimelineService.kt deleted file mode 100644 index 39ce7e52..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/MongoGenerateTimelineService.kt +++ /dev/null @@ -1,89 +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.core.service.timeline - -import dev.usbharu.hideout.application.infrastructure.exposed.Page -import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList -import dev.usbharu.hideout.core.domain.model.timeline.Timeline -import dev.usbharu.hideout.domain.mastodon.model.generated.Status -import dev.usbharu.hideout.mastodon.interfaces.api.status.StatusQuery -import dev.usbharu.hideout.mastodon.query.StatusQueryService -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.data.domain.Sort -import org.springframework.data.mongodb.core.MongoTemplate -import org.springframework.data.mongodb.core.query.Criteria -import org.springframework.data.mongodb.core.query.Query -import org.springframework.stereotype.Service - -@Service -@ConditionalOnProperty("hideout.use-mongodb", havingValue = "true", matchIfMissing = false) -class MongoGenerateTimelineService( - private val statusQueryService: StatusQueryService, - private val mongoTemplate: MongoTemplate -) : - GenerateTimelineService { - - override suspend fun getTimeline( - forUserId: Long?, - localOnly: Boolean, - mediaOnly: Boolean, - page: Page - ): PaginationList { - val query = Query() - - if (forUserId != null) { - val criteria = Criteria.where("userId").`is`(forUserId) - query.addCriteria(criteria) - } - if (localOnly) { - val criteria = Criteria.where("isLocal").`is`(true) - query.addCriteria(criteria) - } - - if (page.minId != null) { - page.minId?.let { query.addCriteria(Criteria.where("id").gt(it)) } - page.maxId?.let { query.addCriteria(Criteria.where("id").lt(it)) } - } else { - query.with(Sort.by(Sort.Direction.DESC, "createdAt")) - page.sinceId?.let { query.addCriteria(Criteria.where("id").gt(it)) } - page.maxId?.let { query.addCriteria(Criteria.where("id").lt(it)) } - } - - page.limit?.let { query.limit(it) } - - query.with(Sort.by(Sort.Direction.DESC, "createdAt")) - - val timelines = mongoTemplate.find(query, Timeline::class.java) - - val statuses = statusQueryService.findByPostIdsWithMediaIds( - timelines.map { - StatusQuery( - it.postId, - it.replyId, - it.repostId, - it.mediaIds, - it.emojiIds - ) - } - ) - return PaginationList( - statuses, - statuses.lastOrNull()?.id?.toLongOrNull(), - statuses.firstOrNull()?.id?.toLongOrNull() - ) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserCreateDto.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserCreateDto.kt deleted file mode 100644 index be7b5e0d..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserCreateDto.kt +++ /dev/null @@ -1,24 +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.core.service.user - -data class UserCreateDto( - val name: String, - val screenName: String, - val description: String, - val password: String -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/CollectionUtil.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/CollectionUtil.kt deleted file mode 100644 index 03249388..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/CollectionUtil.kt +++ /dev/null @@ -1,29 +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.util - -class CollectionUtil - -fun Iterable.singleOr(block: (e: RuntimeException) -> Throwable): T { - return try { - this.single() - } catch (e: NoSuchElementException) { - throw block(e) - } catch (e: IllegalArgumentException) { - throw block(e) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt deleted file mode 100644 index 01fd3842..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt +++ /dev/null @@ -1,54 +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.util - -import io.ktor.http.* - -object HttpUtil { - val Activity: ContentType - get() = ContentType("application", "activity+json") - - val JsonLd: ContentType - get() { - return ContentType( - contentType = "application", - contentSubtype = "ld+json", - parameters = listOf(HeaderValueParam("profile", "https://www.w3.org/ns/activitystreams")) - ) - } - - fun isContentTypeOfActivityPub( - contentType: String, - subType: String - ): Boolean { - if (contentType != "application") { - return false - } - if (subType == "activity+json") { - return true - } - return subType == "ld+json" - } - - fun isContentTypeOfActivityPub(contentType: ContentType): Boolean { - return isContentTypeOfActivityPub( - contentType.contentType, - contentType.contentSubtype - ) - } -// fun -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/InstantParseUtil.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/InstantParseUtil.kt deleted file mode 100644 index fd6c3669..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/InstantParseUtil.kt +++ /dev/null @@ -1,34 +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.util - -import java.time.Instant -import java.time.format.DateTimeParseException - -object InstantParseUtil { - fun parse(str: String?): Instant? { - return try { - Instant.ofEpochMilli(str?.toLong() ?: return null) - } catch (e: NumberFormatException) { - try { - Instant.parse(str) - } catch (e: DateTimeParseException) { - null - } - } - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/LruCache.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/LruCache.kt deleted file mode 100644 index c5ffdea2..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/LruCache.kt +++ /dev/null @@ -1,35 +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.util - -import java.io.Serial - -class LruCache(private val maxSize: Int) : LinkedHashMap(15, 0.75f, true) { - - override fun removeEldestEntry(eldest: MutableMap.MutableEntry?): Boolean = size > maxSize - override fun toString(): String { - return "LruCache(" + - "maxSize=$maxSize" + - ")" + - " ${super.toString()}" - } - - companion object { - @Serial - private const val serialVersionUID: Long = -6446947260925053191L - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt index 8827b61a..8efbd8b0 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt @@ -45,9 +45,4 @@ object RsaUtil { fun decodeRsaPrivateKey(encoded: String): RSAPrivateKey = decodeRsaPrivateKey(Base64Util.decode(encoded)) - fun decodeRsaPrivateKeyPem(pem: String): RSAPrivateKey { - val replace = pem.replace(replaceHeaderAndFooterRegex, "") - .replace("\n", "") - return decodeRsaPrivateKey(replace) - } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/ServerUtil.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/ServerUtil.kt deleted file mode 100644 index 137d449a..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/ServerUtil.kt +++ /dev/null @@ -1,22 +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.util - -object ServerUtil { - fun getImplementationVersion(): String = - ServerUtil.javaClass.`package`.implementationVersion ?: "DEVELOPMENT-VERSION" -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt deleted file mode 100644 index 39fcda52..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt +++ /dev/null @@ -1,39 +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.util - -import java.nio.file.Files -import java.nio.file.Path - -fun T.withDelete(): TempFile = TempFile(this) - -class TempFile(val path: T) : AutoCloseable { - override fun close() { - path?.let { Files.deleteIfExists(it) } - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as TempFile<*> - - return path == other.path - } - - override fun hashCode(): Int = path?.hashCode() ?: 0 -} diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/application/service/init/MetaServiceImplTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/application/service/init/MetaServiceImplTest.kt index bba96791..532f6403 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/application/service/init/MetaServiceImplTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/application/service/init/MetaServiceImplTest.kt @@ -19,9 +19,6 @@ package dev.usbharu.hideout.application.service.init import dev.usbharu.hideout.core.domain.exception.NotInitException -import dev.usbharu.hideout.core.domain.model.meta.Jwt -import dev.usbharu.hideout.core.domain.model.meta.Meta -import dev.usbharu.hideout.core.domain.model.meta.MetaRepository import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Test diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/application/service/init/ServerInitialiseServiceImplTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/application/service/init/ServerInitialiseServiceImplTest.kt deleted file mode 100644 index d24bc17c..00000000 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/application/service/init/ServerInitialiseServiceImplTest.kt +++ /dev/null @@ -1,73 +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. - */ - -@file:OptIn(ExperimentalCoroutinesApi::class) - -package dev.usbharu.hideout.application.service.init - -import dev.usbharu.hideout.core.domain.model.meta.Jwt -import dev.usbharu.hideout.core.domain.model.meta.Meta -import dev.usbharu.hideout.core.domain.model.meta.MetaRepository -import dev.usbharu.hideout.util.ServerUtil -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.runTest -import org.junit.jupiter.api.Test -import org.mockito.kotlin.* -import utils.TestTransaction -import java.util.* -import kotlin.test.assertEquals - -class ServerInitialiseServiceImplTest { - @Test - fun `init メタデータが無いときに初期化を実行する`() = runTest { - val metaRepository = mock { - onBlocking { get() } doReturn null - onBlocking { save(any()) } doReturn Unit - } - val serverInitialiseServiceImpl = ServerInitialiseServiceImpl(metaRepository, TestTransaction) - - serverInitialiseServiceImpl.init() - verify(metaRepository, times(1)).save(any()) - } - - @Test - fun `init メタデータが存在して同じバージョンのときは何もしない`() = runTest { - val meta = Meta(ServerUtil.getImplementationVersion(), Jwt(UUID.randomUUID(), "aaafafd", "afafasdf")) - val metaRepository = mock { - onBlocking { get() } doReturn meta - } - val serverInitialiseServiceImpl = ServerInitialiseServiceImpl(metaRepository, TestTransaction) - serverInitialiseServiceImpl.init() - verify(metaRepository, times(0)).save(any()) - } - - @Test - fun `init メタデータが存在して違うバージョンのときはバージョンを変更する`() = runTest { - val meta = Meta("1.0.0", Jwt(UUID.randomUUID(), "aaafafd", "afafasdf")) - val metaRepository = mock { - onBlocking { get() } doReturn meta - onBlocking { save(any()) } doReturn Unit - } - - val serverInitialiseServiceImpl = ServerInitialiseServiceImpl(metaRepository, TestTransaction) - serverInitialiseServiceImpl.init() - verify(metaRepository, times(1)).save(any()) - argumentCaptor { - verify(metaRepository, times(1)).save(capture()) - assertEquals(ServerUtil.getImplementationVersion(), firstValue.version) - } - } -} diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementServiceImplTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementServiceImplTest.kt index 43167eef..30508ea1 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementServiceImplTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/notification/RelationshipNotificationManagementServiceImplTest.kt @@ -16,7 +16,7 @@ package dev.usbharu.hideout.core.service.notification -import dev.usbharu.hideout.core.domain.model.relationship.Relationship +import dev.usbharu.hideout.domain.mastodon.model.generated.Relationship import org.junit.jupiter.api.Test import kotlin.test.assertTrue diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt index 0d82e8b5..acff5e20 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt @@ -21,8 +21,8 @@ import dev.usbharu.hideout.activitypub.service.activity.follow.APSendFollowServi import dev.usbharu.hideout.activitypub.service.activity.reject.ApSendRejectService import dev.usbharu.hideout.activitypub.service.activity.undo.APSendUndoService import dev.usbharu.hideout.application.config.ApplicationConfig -import dev.usbharu.hideout.core.domain.model.relationship.Relationship import dev.usbharu.hideout.core.service.notification.NotificationService +import dev.usbharu.hideout.domain.mastodon.model.generated.Relationship import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/timeline/TimelineServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/timeline/TimelineServiceTest.kt index 29db21c2..71c05e4a 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/timeline/TimelineServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/timeline/TimelineServiceTest.kt @@ -18,8 +18,6 @@ package dev.usbharu.hideout.core.service.timeline import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService import dev.usbharu.hideout.core.domain.model.post.Visibility -import dev.usbharu.hideout.core.domain.model.timeline.Timeline -import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository import kotlinx.coroutines.test.runTest import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt index bfd88778..feb0cc4f 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt @@ -25,7 +25,6 @@ import dev.usbharu.hideout.core.domain.model.deletedActor.DeletedActorRepository import dev.usbharu.hideout.core.domain.model.instance.Instance import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository -import dev.usbharu.hideout.core.service.instance.InstanceService import dev.usbharu.owl.producer.api.OwlProducer import jakarta.validation.Validation import kotlinx.coroutines.ExperimentalCoroutinesApi diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiServiceImplTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiServiceImplTest.kt index e1676e7a..0640f8ba 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiServiceImplTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiServiceImplTest.kt @@ -16,9 +16,9 @@ package dev.usbharu.hideout.mastodon.service.account -import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.application.infrastructure.exposed.Page import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.service.media.MediaService import dev.usbharu.hideout.domain.mastodon.model.generated.Account import dev.usbharu.hideout.domain.mastodon.model.generated.Relationship diff --git a/hideout-core/src/test/kotlin/utils/TestTransaction.kt b/hideout-core/src/test/kotlin/utils/TestTransaction.kt index 4fc832fd..a32bf303 100644 --- a/hideout-core/src/test/kotlin/utils/TestTransaction.kt +++ b/hideout-core/src/test/kotlin/utils/TestTransaction.kt @@ -16,7 +16,7 @@ package utils -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction object TestTransaction : Transaction { override suspend fun transaction(block: suspend () -> T): T = block() diff --git a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverAcceptTaskRunner.kt b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverAcceptTaskRunner.kt index 7d939be0..71817b59 100644 --- a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverAcceptTaskRunner.kt +++ b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverAcceptTaskRunner.kt @@ -17,7 +17,7 @@ package dev.usbharu.hideout.worker import dev.usbharu.hideout.activitypub.service.common.APRequestService -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.external.job.DeliverAcceptTask import dev.usbharu.hideout.core.external.job.DeliverAcceptTaskDef import dev.usbharu.owl.consumer.AbstractTaskRunner diff --git a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverCreateTaskRunner.kt b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverCreateTaskRunner.kt index 9d880986..0f71f98c 100644 --- a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverCreateTaskRunner.kt +++ b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverCreateTaskRunner.kt @@ -17,7 +17,7 @@ package dev.usbharu.hideout.worker import dev.usbharu.hideout.activitypub.service.common.APRequestService -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.external.job.DeliverCreateTask import dev.usbharu.hideout.core.external.job.DeliverCreateTaskDef import dev.usbharu.owl.consumer.AbstractTaskRunner diff --git a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverRejectTaskRunner.kt b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverRejectTaskRunner.kt index 73179f07..b84a5d7a 100644 --- a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverRejectTaskRunner.kt +++ b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverRejectTaskRunner.kt @@ -17,7 +17,7 @@ package dev.usbharu.hideout.worker import dev.usbharu.hideout.activitypub.service.common.APRequestService -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.external.job.DeliverRejectTask import dev.usbharu.hideout.core.external.job.DeliverRejectTaskDef import dev.usbharu.owl.consumer.AbstractTaskRunner diff --git a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverUndoTaskRunner.kt b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverUndoTaskRunner.kt index 949435ba..4c08786f 100644 --- a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverUndoTaskRunner.kt +++ b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/DeliverUndoTaskRunner.kt @@ -17,7 +17,7 @@ package dev.usbharu.hideout.worker import dev.usbharu.hideout.activitypub.service.common.APRequestService -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.external.job.DeliverUndoTask import dev.usbharu.hideout.core.external.job.DeliverUndoTaskDef import dev.usbharu.owl.consumer.AbstractTaskRunner diff --git a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/InboxTaskRunner.kt b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/InboxTaskRunner.kt index 1a5be9a4..ae4af395 100644 --- a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/InboxTaskRunner.kt +++ b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/InboxTaskRunner.kt @@ -18,11 +18,10 @@ package dev.usbharu.hideout.worker import com.fasterxml.jackson.core.JsonParseException import com.fasterxml.jackson.databind.ObjectMapper -import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessor import dev.usbharu.hideout.activitypub.service.objects.user.APUserService -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.external.job.InboxTask import dev.usbharu.hideout.core.external.job.InboxTaskDef import dev.usbharu.hideout.util.RsaUtil diff --git a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/ReceiveFollowTaskRunner.kt b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/ReceiveFollowTaskRunner.kt index 7839bc01..9a73010f 100644 --- a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/ReceiveFollowTaskRunner.kt +++ b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/ReceiveFollowTaskRunner.kt @@ -17,7 +17,7 @@ package dev.usbharu.hideout.worker import dev.usbharu.hideout.activitypub.service.objects.user.APUserService -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.exception.resource.UserNotFoundException import dev.usbharu.hideout.core.external.job.ReceiveFollowTask import dev.usbharu.hideout.core.external.job.ReceiveFollowTaskDef diff --git a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/UpdateActorWorker.kt b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/UpdateActorWorker.kt index 9faec4c6..e7de84b0 100644 --- a/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/UpdateActorWorker.kt +++ b/hideout-worker/src/main/kotlin/dev/usbharu/hideout/worker/UpdateActorWorker.kt @@ -17,7 +17,7 @@ package dev.usbharu.hideout.worker import dev.usbharu.hideout.activitypub.service.objects.user.APUserService -import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.external.job.UpdateActorTask import dev.usbharu.hideout.core.external.job.UpdateActorTaskDef import dev.usbharu.owl.consumer.AbstractTaskRunner