mirror of https://github.com/usbharu/Hideout.git
feat: Createのアクティビティに対応
This commit is contained in:
parent
89c299d3c0
commit
3009ca1532
|
@ -0,0 +1,14 @@
|
||||||
|
package dev.usbharu.hideout.activitypub.domain.exception
|
||||||
|
|
||||||
|
class HttpSignatureUnauthorizedException : RuntimeException {
|
||||||
|
constructor() : super()
|
||||||
|
constructor(message: String?) : super(message)
|
||||||
|
constructor(message: String?, cause: Throwable?) : super(message, cause)
|
||||||
|
constructor(cause: Throwable?) : super(cause)
|
||||||
|
constructor(message: String?, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) : super(
|
||||||
|
message,
|
||||||
|
cause,
|
||||||
|
enableSuppression,
|
||||||
|
writableStackTrace
|
||||||
|
)
|
||||||
|
}
|
|
@ -2,14 +2,21 @@ package dev.usbharu.hideout.activitypub.service.tmp
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.domain.exception.ActivityPubProcessException
|
import dev.usbharu.hideout.activitypub.domain.exception.ActivityPubProcessException
|
||||||
import dev.usbharu.hideout.activitypub.domain.exception.FailedProcessException
|
import dev.usbharu.hideout.activitypub.domain.exception.FailedProcessException
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.exception.HttpSignatureUnauthorizedException
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
abstract class AbstractActivityPubProcessor<T : Object>(val transaction: Transaction) : ActivityPubProcessor<T> {
|
abstract class AbstractActivityPubProcessor<T : Object>(
|
||||||
|
private val transaction: Transaction,
|
||||||
|
private val allowUnauthorized: Boolean = false
|
||||||
|
) : ActivityPubProcessor<T> {
|
||||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||||
|
|
||||||
override suspend fun process(activity: ActivityPubProcessContext<T>) {
|
override suspend fun process(activity: ActivityPubProcessContext<T>) {
|
||||||
|
if (activity.isAuthorized.not() && allowUnauthorized.not()) {
|
||||||
|
throw HttpSignatureUnauthorizedException()
|
||||||
|
}
|
||||||
logger.info("START ActivityPub process")
|
logger.info("START ActivityPub process")
|
||||||
try {
|
try {
|
||||||
transaction.transaction {
|
transaction.transaction {
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package dev.usbharu.hideout.activitypub.service.tmp.impl
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Create
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Note
|
||||||
|
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
||||||
|
import dev.usbharu.hideout.activitypub.service.objects.note.APNoteService
|
||||||
|
import dev.usbharu.hideout.activitypub.service.tmp.AbstractActivityPubProcessor
|
||||||
|
import dev.usbharu.hideout.activitypub.service.tmp.ActivityPubProcessContext
|
||||||
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class CreateActivityProcessor(transaction: Transaction, private val apNoteService: APNoteService) :
|
||||||
|
AbstractActivityPubProcessor<Create>(transaction, false) {
|
||||||
|
override suspend fun internalProcess(activity: ActivityPubProcessContext<Create>) {
|
||||||
|
apNoteService.fetchNote(activity.activity.`object` as Note)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSupported(activityType: ActivityType): Boolean = activityType == ActivityType.Create
|
||||||
|
|
||||||
|
override fun type(): Class<Create> = Create::class.java
|
||||||
|
}
|
Loading…
Reference in New Issue