diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt index 19c32b90..e0040d91 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt @@ -18,11 +18,19 @@ class GetLocalInstanceApplicationService( AbstractApplicationService( transaction, logger ) { + var cachedInstance: Instance? = null + override suspend fun internalExecute(command: Unit, principal: Principal): Instance { + + if (cachedInstance != null) { + return cachedInstance!! + } + val instance = (instanceRepository.findByUrl(applicationConfig.url.toURI()) ?: throw InternalServerException("Local instance not found.")) - return Instance.of(instance) + cachedInstance = Instance.of(instance) + return cachedInstance!! } companion object { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/posts/PublishController.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/posts/PublishController.kt new file mode 100644 index 00000000..c3c30076 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/posts/PublishController.kt @@ -0,0 +1,32 @@ +package dev.usbharu.hideout.core.interfaces.web.posts + +import dev.usbharu.hideout.core.application.actor.GetUserDetail +import dev.usbharu.hideout.core.application.actor.GetUserDetailApplicationService +import dev.usbharu.hideout.core.application.instance.GetLocalInstanceApplicationService +import dev.usbharu.hideout.core.infrastructure.springframework.SpringSecurityFormLoginPrincipalContextHolder +import org.springframework.security.access.AccessDeniedException +import org.springframework.stereotype.Controller +import org.springframework.ui.Model +import org.springframework.web.bind.annotation.GetMapping + +@Controller +class PublishController( + private val getLocalInstanceApplicationService: GetLocalInstanceApplicationService, + private val springSecurityFormLoginPrincipalContextHolder: SpringSecurityFormLoginPrincipalContextHolder, + private val getUserDetailApplicationService: GetUserDetailApplicationService +) { + @GetMapping("/publish") + suspend fun publish(model: Model): String { + val principal = springSecurityFormLoginPrincipalContextHolder.getPrincipal() + + if (principal.userDetailId == null) { + throw AccessDeniedException("403 Forbidden") + } + + val instance = getLocalInstanceApplicationService.execute(Unit, principal) + val userDetail = getUserDetailApplicationService.execute(GetUserDetail(principal.userDetailId!!.id), principal) + model.addAttribute("instance", instance) + model.addAttribute("user") + return "post-postForm" + } +} \ No newline at end of file diff --git a/hideout-core/src/main/resources/messages/hideout-web-messages.properties b/hideout-core/src/main/resources/messages/hideout-web-messages.properties index 4151646d..92164d8a 100644 --- a/hideout-core/src/main/resources/messages/hideout-web-messages.properties +++ b/hideout-core/src/main/resources/messages/hideout-web-messages.properties @@ -6,5 +6,6 @@ common.unknwon-file-type=\u4E0D\u660E\u306A\u30D5\u30A1\u30A4\u30EB\u5F62\u5F0F common.video=\u52D5\u753B common.video-download-link=\u52D5\u753B\u30D5\u30A1\u30A4\u30EB\u307E\u305F\u306F\u30B5\u30E0\u30CD\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9 post-by-id.title={0} \u3055\u3093\u306E\u6295\u7A3F - {1} +post-form.new-posts=\u65B0\u3057\u3044\u6295\u7A3F! post.repost=\u30EA\u30DD\u30B9\u30C8 post.repost-by={0}\u304C\u30EA\u30DD\u30B9\u30C8 \ No newline at end of file diff --git a/hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties b/hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties index f56efdb9..facd4eed 100644 --- a/hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties +++ b/hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties @@ -5,5 +5,6 @@ common.thumbnail=thumbnail common.unknwon-file-type=Unknown filetype common.video=Video common.video-download-link=Download the Video or thumbnail. +post-form.new-posts=New Posts! post.repost=Repost post.repost-by=Repost by {0} \ No newline at end of file diff --git a/hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties b/hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties index 4151646d..92164d8a 100644 --- a/hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties +++ b/hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties @@ -6,5 +6,6 @@ common.unknwon-file-type=\u4E0D\u660E\u306A\u30D5\u30A1\u30A4\u30EB\u5F62\u5F0F common.video=\u52D5\u753B common.video-download-link=\u52D5\u753B\u30D5\u30A1\u30A4\u30EB\u307E\u305F\u306F\u30B5\u30E0\u30CD\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9 post-by-id.title={0} \u3055\u3093\u306E\u6295\u7A3F - {1} +post-form.new-posts=\u65B0\u3057\u3044\u6295\u7A3F! post.repost=\u30EA\u30DD\u30B9\u30C8 post.repost-by={0}\u304C\u30EA\u30DD\u30B9\u30C8 \ No newline at end of file diff --git a/hideout-core/src/main/resources/templates/fragments-actor.html b/hideout-core/src/main/resources/templates/fragments-actor.html new file mode 100644 index 00000000..829f124b --- /dev/null +++ b/hideout-core/src/main/resources/templates/fragments-actor.html @@ -0,0 +1,10 @@ + + + + + Title + + +
+ + \ No newline at end of file diff --git a/hideout-core/src/main/resources/templates/post-postForm.html b/hideout-core/src/main/resources/templates/post-postForm.html new file mode 100644 index 00000000..1709ce9a --- /dev/null +++ b/hideout-core/src/main/resources/templates/post-postForm.html @@ -0,0 +1,12 @@ + + + + + New Posts! + + + + + + + \ No newline at end of file