diff --git a/src/main/kotlin/dev/usbharu/hideout/Application.kt b/src/main/kotlin/dev/usbharu/hideout/Application.kt index 56f3f1d8..e99bef82 100644 --- a/src/main/kotlin/dev/usbharu/hideout/Application.kt +++ b/src/main/kotlin/dev/usbharu/hideout/Application.kt @@ -12,6 +12,7 @@ import dev.usbharu.hideout.repository.UserAuthRepository import dev.usbharu.hideout.repository.UserRepository import dev.usbharu.hideout.routing.* import dev.usbharu.hideout.service.* +import dev.usbharu.hideout.service.impl.* import io.ktor.client.* import io.ktor.client.engine.cio.* import io.ktor.client.plugins.contentnegotiation.* diff --git a/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt b/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt index 7d0a41d2..2c8d1d52 100644 --- a/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt +++ b/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt @@ -3,7 +3,7 @@ package dev.usbharu.hideout.plugins import dev.usbharu.hideout.ap.JsonLd import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.service.IUserAuthService -import dev.usbharu.hideout.service.UserAuthService +import dev.usbharu.hideout.service.impl.UserAuthService import dev.usbharu.hideout.util.HttpUtil.Activity import io.ktor.client.* import io.ktor.client.plugins.api.* @@ -12,7 +12,6 @@ import io.ktor.client.statement.* import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.response.* -import io.ktor.util.* import kotlinx.coroutines.runBlocking import tech.barbero.http.message.signing.HttpMessage import tech.barbero.http.message.signing.HttpMessageSigner diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/UserRouting.kt b/src/main/kotlin/dev/usbharu/hideout/routing/UserRouting.kt index d73c8ad0..d43b070d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/UserRouting.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/UserRouting.kt @@ -4,8 +4,8 @@ import dev.usbharu.hideout.domain.model.User import dev.usbharu.hideout.plugins.UserSession import dev.usbharu.hideout.plugins.respondAp import dev.usbharu.hideout.plugins.tokenAuth -import dev.usbharu.hideout.service.ActivityPubUserService -import dev.usbharu.hideout.service.UserService +import dev.usbharu.hideout.service.impl.ActivityPubUserService +import dev.usbharu.hideout.service.impl.UserService import dev.usbharu.hideout.util.HttpUtil import io.ktor.http.* import io.ktor.server.application.* @@ -13,7 +13,6 @@ import io.ktor.server.auth.* import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* -import io.ktor.server.sessions.* @Suppress("unused") fun Application.user(userService: UserService, activityPubUserService: ActivityPubUserService) { diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/WellKnownRouting.kt b/src/main/kotlin/dev/usbharu/hideout/routing/WellKnownRouting.kt index 41fc6fd1..f1e6a7a6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/WellKnownRouting.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/WellKnownRouting.kt @@ -1,7 +1,7 @@ package dev.usbharu.hideout.routing import dev.usbharu.hideout.config.Config -import dev.usbharu.hideout.service.UserService +import dev.usbharu.hideout.service.impl.UserService import dev.usbharu.hideout.util.HttpUtil.Activity import io.ktor.http.* import io.ktor.server.application.* diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/userActivityPubRouting.kt b/src/main/kotlin/dev/usbharu/hideout/routing/userActivityPubRouting.kt index 8993ecda..73d54fa8 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/userActivityPubRouting.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/userActivityPubRouting.kt @@ -3,8 +3,8 @@ package dev.usbharu.hideout.routing import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.ap.Follow import dev.usbharu.hideout.config.Config -import dev.usbharu.hideout.service.ActivityPubService -import dev.usbharu.hideout.service.ActivityPubUserService +import dev.usbharu.hideout.service.impl.ActivityPubService +import dev.usbharu.hideout.service.impl.ActivityPubUserService import dev.usbharu.hideout.util.HttpUtil import io.ktor.http.* import io.ktor.server.application.* diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt new file mode 100644 index 00000000..070046a3 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt @@ -0,0 +1,39 @@ +package dev.usbharu.hideout.service.activitypub + +interface ActivityPubService { + fun parseActivity(json:String): ActivityType + + fun processActivity(json:String, type: ActivityType) +} + +enum class ActivityType { + 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, + Other +} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ActivityPubService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/ActivityPubService.kt similarity index 74% rename from src/main/kotlin/dev/usbharu/hideout/service/ActivityPubService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/impl/ActivityPubService.kt index bc6c9f17..e693bd57 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ActivityPubService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/ActivityPubService.kt @@ -1,6 +1,5 @@ -package dev.usbharu.hideout.service +package dev.usbharu.hideout.service.impl -import com.fasterxml.jackson.databind.ObjectMapper import dev.usbharu.hideout.config.Config class ActivityPubService() { @@ -10,7 +9,7 @@ class ActivityPubService() { Undo } - fun switchApType(json:String):ActivityType{ + fun switchApType(json:String): ActivityType { val typeAsText = Config.configData.objectMapper.readTree(json).get("type").asText() return when(typeAsText){ "Follow" -> ActivityType.Follow diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ActivityPubUserService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/ActivityPubUserService.kt similarity index 93% rename from src/main/kotlin/dev/usbharu/hideout/service/ActivityPubUserService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/impl/ActivityPubUserService.kt index 4c2b0f82..fd26123c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ActivityPubUserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/ActivityPubUserService.kt @@ -1,8 +1,10 @@ -package dev.usbharu.hideout.service +package dev.usbharu.hideout.service.impl import dev.usbharu.hideout.ap.* import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.plugins.postAp +import dev.usbharu.hideout.service.IUserAuthService +import dev.usbharu.hideout.service.IWebFingerService import io.ktor.client.* class ActivityPubUserService( diff --git a/src/main/kotlin/dev/usbharu/hideout/service/HttpSignService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/HttpSignService.kt similarity index 68% rename from src/main/kotlin/dev/usbharu/hideout/service/HttpSignService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/impl/HttpSignService.kt index 440ee426..07cf8941 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/HttpSignService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/HttpSignService.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service +package dev.usbharu.hideout.service.impl import java.security.PrivateKey diff --git a/src/main/kotlin/dev/usbharu/hideout/service/UserAuthService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserAuthService.kt similarity index 97% rename from src/main/kotlin/dev/usbharu/hideout/service/UserAuthService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/impl/UserAuthService.kt index ac60a847..cf5b0a48 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/UserAuthService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserAuthService.kt @@ -1,13 +1,13 @@ -package dev.usbharu.hideout.service +package dev.usbharu.hideout.service.impl import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.domain.model.User import dev.usbharu.hideout.domain.model.UserAuthentication import dev.usbharu.hideout.domain.model.UserAuthenticationEntity -import dev.usbharu.hideout.domain.model.Users.screenName import dev.usbharu.hideout.exception.UserNotFoundException import dev.usbharu.hideout.repository.IUserAuthRepository import dev.usbharu.hideout.repository.IUserRepository +import dev.usbharu.hideout.service.IUserAuthService import io.ktor.util.* import java.security.KeyPair import java.security.KeyPairGenerator diff --git a/src/main/kotlin/dev/usbharu/hideout/service/UserService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt similarity index 96% rename from src/main/kotlin/dev/usbharu/hideout/service/UserService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt index 3183b212..4736338a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/UserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service +package dev.usbharu.hideout.service.impl import dev.usbharu.hideout.domain.model.User import dev.usbharu.hideout.domain.model.UserEntity diff --git a/src/main/kotlin/dev/usbharu/hideout/service/WebFingerService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/WebFingerService.kt similarity index 96% rename from src/main/kotlin/dev/usbharu/hideout/service/WebFingerService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/impl/WebFingerService.kt index 9cc2cf52..8bf1c420 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/WebFingerService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/WebFingerService.kt @@ -1,8 +1,9 @@ -package dev.usbharu.hideout.service +package dev.usbharu.hideout.service.impl import dev.usbharu.hideout.ap.Person import dev.usbharu.hideout.domain.model.User import dev.usbharu.hideout.domain.model.UserEntity +import dev.usbharu.hideout.service.IWebFingerService import dev.usbharu.hideout.util.HttpUtil import dev.usbharu.hideout.webfinger.WebFinger import io.ktor.client.* diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt index 8c7e7d76..36cefbbd 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt @@ -7,8 +7,8 @@ import dev.usbharu.hideout.domain.model.UserAuthenticationEntity import dev.usbharu.hideout.domain.model.UserEntity import dev.usbharu.hideout.repository.IUserAuthRepository import dev.usbharu.hideout.repository.IUserRepository -import dev.usbharu.hideout.service.UserAuthService -import dev.usbharu.hideout.service.toPem +import dev.usbharu.hideout.service.impl.UserAuthService +import dev.usbharu.hideout.service.impl.toPem import io.ktor.client.* import io.ktor.client.engine.mock.* import io.ktor.client.plugins.logging.* @@ -17,7 +17,6 @@ import org.junit.jupiter.api.Test import java.security.KeyPairGenerator import java.security.interfaces.RSAPrivateKey import java.security.interfaces.RSAPublicKey -import java.util.* class ActivityPubKtTest { @Test diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt index 9f9a7cfe..3f56dd92 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt @@ -6,13 +6,12 @@ import dev.usbharu.hideout.domain.model.UserAuthenticationEntity import dev.usbharu.hideout.domain.model.UserEntity import dev.usbharu.hideout.repository.IUserAuthRepository import dev.usbharu.hideout.repository.IUserRepository -import dev.usbharu.hideout.service.UserAuthService -import dev.usbharu.hideout.service.toPem +import dev.usbharu.hideout.service.impl.UserAuthService +import dev.usbharu.hideout.service.impl.toPem import org.junit.jupiter.api.Test import java.security.KeyPairGenerator import java.security.interfaces.RSAPrivateKey import java.security.interfaces.RSAPublicKey -import java.util.* class KtorKeyMapTest {