mirror of https://github.com/usbharu/Hideout.git
fix: 依存関係を修正
This commit is contained in:
parent
64ef0b70b4
commit
428c096fa6
|
@ -41,14 +41,14 @@ fun Application.module() {
|
|||
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
||||
)
|
||||
}
|
||||
single<HttpClient> { HttpClient(CIO) }
|
||||
single<IUserRepository> { UserRepository(get()) }
|
||||
single<IUserAuthRepository> { UserAuthRepository(get()) }
|
||||
single<IUserAuthService> { UserAuthService(get(), get()) }
|
||||
single<UserService> { UserService(get()) }
|
||||
single<WebFingerService> { WebFingerService(get(),get(),get(),get()) }
|
||||
single<ActivityPubUserService> { ActivityPubUserService(get(), get(),get(),get()) }
|
||||
single<ActivityPubService> { ActivityPubService() }
|
||||
single<HttpClient> { HttpClient(CIO) }
|
||||
single<ActivityPubUserService> { ActivityPubUserService(get(), get(),get(),get()) }
|
||||
single<IWebFingerService> { WebFingerService(get(),get()) }
|
||||
}
|
||||
configureKoin(module)
|
||||
val configData by inject<ConfigData>()
|
||||
|
@ -70,5 +70,5 @@ fun Application.module() {
|
|||
register(userAuthService)
|
||||
wellKnown(userService)
|
||||
val activityPubService by inject<ActivityPubService>()
|
||||
userActivityPubRouting(activityPubService)
|
||||
userActivityPubRouting(activityPubService, activityPubUserService)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class ActivityPubUserService(
|
|||
private val httpClient: HttpClient,
|
||||
private val userService: UserService,
|
||||
private val userAuthService: IUserAuthService,
|
||||
private val webFingerService: WebFingerService
|
||||
private val webFingerService: IWebFingerService
|
||||
) {
|
||||
suspend fun generateUserModel(name: String): Person {
|
||||
val userEntity = userService.findByName(name)
|
||||
|
@ -43,20 +43,9 @@ class ActivityPubUserService(
|
|||
)
|
||||
}
|
||||
|
||||
suspend fun fetchUserModel(url: String): Person? {
|
||||
return try {
|
||||
httpClient.get(url).body<Person>()
|
||||
} catch (e: ResponseException) {
|
||||
if (e.response.status == HttpStatusCode.NotFound) {
|
||||
return null
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun receiveFollow(follow: Follow) {
|
||||
val actor = follow.actor ?: throw IllegalArgumentException("actor is null")
|
||||
val person = fetchUserModel(actor) ?: throw IllegalArgumentException("actor is not found")
|
||||
val person = webFingerService.fetchUserModel(actor) ?: throw IllegalArgumentException("actor is not found")
|
||||
val inboxUrl = person.inbox ?: throw IllegalArgumentException("inbox is not found")
|
||||
httpClient.post(inboxUrl) {
|
||||
setBody(Accept(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.usbharu.hideout.service
|
||||
|
||||
import dev.usbharu.hideout.ap.Person
|
||||
import dev.usbharu.hideout.domain.model.UserEntity
|
||||
import dev.usbharu.hideout.webfinger.WebFinger
|
||||
|
||||
|
@ -12,4 +13,6 @@ interface IWebFingerService {
|
|||
val webFinger = fetch(acct)?: throw IllegalArgumentException()
|
||||
return sync(webFinger)
|
||||
}
|
||||
|
||||
suspend fun fetchUserModel(actor: String): Person?
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.usbharu.hideout.service
|
||||
|
||||
import dev.usbharu.hideout.ap.Person
|
||||
import dev.usbharu.hideout.domain.model.User
|
||||
import dev.usbharu.hideout.domain.model.UserEntity
|
||||
import dev.usbharu.hideout.util.HttpUtil
|
||||
|
@ -12,9 +13,7 @@ import io.ktor.http.*
|
|||
|
||||
class WebFingerService(
|
||||
private val httpClient: HttpClient,
|
||||
private val userService: UserService,
|
||||
private val userAuthService: IUserAuthService,
|
||||
private val activityPubUserService: ActivityPubUserService
|
||||
private val userService: UserService
|
||||
) : IWebFingerService {
|
||||
override suspend fun fetch(acct: String): WebFinger? {
|
||||
|
||||
|
@ -32,6 +31,17 @@ class WebFingerService(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun fetchUserModel(url: String): Person? {
|
||||
return try {
|
||||
httpClient.get(url).body<Person>()
|
||||
} catch (e: ResponseException) {
|
||||
if (e.response.status == HttpStatusCode.NotFound) {
|
||||
return null
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun sync(webFinger: WebFinger): UserEntity {
|
||||
|
||||
val link = webFinger.links.find {
|
||||
|
@ -46,7 +56,7 @@ class WebFingerService(
|
|||
val domain = fullName.substringAfterLast("@")
|
||||
val userName = fullName.substringBeforeLast("@")
|
||||
|
||||
val userModel = activityPubUserService.fetchUserModel(link) ?: throw Exception()
|
||||
val userModel = fetchUserModel(link) ?: throw Exception()
|
||||
|
||||
val user = User(
|
||||
userModel.preferredUsername ?: throw IllegalStateException(),
|
||||
|
|
Loading…
Reference in New Issue