fix: Createを正常に処理できていなかったのを修正

This commit is contained in:
usbharu 2023-05-23 23:51:53 +09:00
parent b8613e2bf1
commit f9e47c0a31
3 changed files with 66 additions and 5 deletions

View File

@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.JsonNode
import dev.usbharu.hideout.service.activitypub.ActivityType
import dev.usbharu.hideout.service.activitypub.ActivityVocabulary
class ObjectDeserializer : JsonDeserializer<Object>() {
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): Object {
@ -22,21 +22,25 @@ class ObjectDeserializer : JsonDeserializer<Object>() {
val type = treeNode["type"]
val activityType = if (type.isArray) {
type.firstNotNullOf { jsonNode: JsonNode ->
ActivityType.values().firstOrNull { it.name.equals(jsonNode.asText(), true) }
ActivityVocabulary.values().firstOrNull { it.name.equals(jsonNode.asText(), true) }
}
} else if (type.isValueNode) {
ActivityType.values().first { it.name.equals(type.asText(), true) }
ActivityVocabulary.values().first { it.name.equals(type.asText(), true) }
} else {
TODO()
}
return when (activityType) {
ActivityType.Follow -> {
ActivityVocabulary.Follow -> {
val readValue = p.codec.treeToValue(treeNode, Follow::class.java)
println(readValue)
readValue
}
ActivityVocabulary.Note -> {
p.codec.treeToValue(treeNode, Note::class.java)
}
else -> {
TODO()
}

View File

@ -20,6 +20,6 @@ class ActivityPubCreateServiceImpl(
val note = value as Note
activityPubNoteService.fetchNote(note)
return ActivityPubStringResponse(HttpStatusCode.Created, "Created")
return ActivityPubStringResponse(HttpStatusCode.OK, "Created")
}
}

View File

@ -43,3 +43,60 @@ enum class ActivityType {
View,
Other
}
enum class ActivityVocabulary {
Object,
Link,
Activity,
IntransitiveActivity,
Collection,
OrderedCollection,
CollectionPage,
OrderedCollectionPage,
Accept,
Add,
Announce,
Arrive,
Block,
Create,
Delete,
Dislike,
Flag,
Follow,
Ignore,
Invite,
Join,
Leave,
Like,
Listen,
Move,
Offer,
Question,
Reject,
Read,
Remove,
TentativeReject,
TentativeAccept,
Travel,
Undo,
Update,
View,
Application,
Group,
Organization,
Person,
Service,
Article,
Audio,
Document,
Event,
Image,
Note,
Page,
Place,
Profile,
Relationship,
Tombstone,
Video,
Mention,
}