mirror of https://github.com/usbharu/Hideout.git
feat: /nodeinfo/2.0,/nodeinfo/2.1を作成
This commit is contained in:
parent
4be93fea86
commit
4c026fb243
hideout/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub
application/nodeinfo
interfaces/wellknown
|
@ -1,3 +1,15 @@
|
||||||
package dev.usbharu.hideout.activitypub.application.nodeinfo
|
package dev.usbharu.hideout.activitypub.application.nodeinfo
|
||||||
|
|
||||||
data class Nodeinfo2_0()
|
data class Nodeinfo2_0(
|
||||||
|
val version: String = "2,0",
|
||||||
|
val software: Map<String, String>,
|
||||||
|
val protocol: List<String>,
|
||||||
|
val usage: NodeinfoUsage,
|
||||||
|
val openRegistration: Boolean,
|
||||||
|
val metadata: Map<String, Any>,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class NodeinfoUsage(
|
||||||
|
val users: Map<String, String>,
|
||||||
|
val localPosts: Long,
|
||||||
|
)
|
|
@ -0,0 +1,43 @@
|
||||||
|
package dev.usbharu.hideout.activitypub.application.nodeinfo
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
|
||||||
|
import dev.usbharu.hideout.core.application.shared.Transaction
|
||||||
|
import dev.usbharu.hideout.core.config.ApplicationConfig
|
||||||
|
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
|
||||||
|
import org.slf4j.Logger
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.boot.info.BuildProperties
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service/*
|
||||||
|
* 今後ユーザーエージェントに応じてレスポンスを変更する可能性があるためApplicationServiceとして作成する commandは現時点ではUnitだが今後変化する可能性あり
|
||||||
|
*/
|
||||||
|
class NodeinfoApplicationService(
|
||||||
|
@Autowired(required = false) private val buildInfo: BuildProperties? = null,
|
||||||
|
private val applicationConfig: ApplicationConfig,
|
||||||
|
transaction: Transaction,
|
||||||
|
) : AbstractApplicationService<Unit, Nodeinfo2_0>(
|
||||||
|
transaction, logger
|
||||||
|
) {
|
||||||
|
override suspend fun internalExecute(command: Unit, principal: Principal): Nodeinfo2_0 {
|
||||||
|
return Nodeinfo2_0(
|
||||||
|
version = "2.0",
|
||||||
|
software = mapOf(
|
||||||
|
"name" to "hideout", "version" to (buildInfo?.version ?: "UNKNOWN")
|
||||||
|
),
|
||||||
|
protocol = listOf("activitypub"),
|
||||||
|
NodeinfoUsage(
|
||||||
|
users = mapOf(
|
||||||
|
"total" to "0", "activeMonth" to "0", "activeHalfyear" to "0"
|
||||||
|
), localPosts = 0
|
||||||
|
),
|
||||||
|
openRegistration = applicationConfig.private.not(),
|
||||||
|
metadata = mapOf()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val logger: Logger = LoggerFactory.getLogger(NodeinfoApplicationService::class.java)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +1,19 @@
|
||||||
package dev.usbharu.hideout.activitypub.interfaces.wellknown
|
package dev.usbharu.hideout.activitypub.interfaces.wellknown
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.activitypub.application.nodeinfo.Nodeinfo2_0
|
||||||
|
import dev.usbharu.hideout.activitypub.application.nodeinfo.NodeinfoApplicationService
|
||||||
import dev.usbharu.hideout.core.config.ApplicationConfig
|
import dev.usbharu.hideout.core.config.ApplicationConfig
|
||||||
|
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
|
||||||
import org.springframework.web.bind.annotation.GetMapping
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/.well-known")
|
class NodeinfoController(
|
||||||
class NodeinfoController(private val applicationConfig: ApplicationConfig) {
|
private val applicationConfig: ApplicationConfig,
|
||||||
@GetMapping("/nodeinfo", produces = ["application/json"])
|
private val nodeinfoApplicationService: NodeinfoApplicationService,
|
||||||
suspend fun nodeinfo(): XRD = XRD(
|
) {
|
||||||
|
@GetMapping("/.well-known/nodeinfo", produces = ["application/json"])
|
||||||
|
fun nodeinfo(): XRD = XRD(
|
||||||
listOf(
|
listOf(
|
||||||
Link(
|
Link(
|
||||||
"http://nodeinfo.diaspora.software/ns/schema/2.1",
|
"http://nodeinfo.diaspora.software/ns/schema/2.1",
|
||||||
|
@ -20,4 +24,14 @@ class NodeinfoController(private val applicationConfig: ApplicationConfig) {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@GetMapping("/nodeinfo/2.0", produces = ["application/json"])
|
||||||
|
suspend fun nodeinfo2_0(): Nodeinfo2_0 {
|
||||||
|
return nodeinfoApplicationService.execute(Unit, Anonymous)
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/nodeinfo/2.1", produces = ["application/json"])
|
||||||
|
suspend fun nodeinfo2_1(): Nodeinfo2_0 {
|
||||||
|
return nodeinfoApplicationService.execute(Unit, Anonymous)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue