[hotfix] hotfix on register and activate logics.

This commit is contained in:
dalbodeule 2025-05-16 00:54:43 +09:00
parent d0292e0aa6
commit 1465716e72
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65
2 changed files with 18 additions and 4 deletions

View File

@ -43,7 +43,7 @@ class Discord: ListenerAdapter() {
embed.setDescription("${user.username} 님이 방송을 시작했습니다.")
embed.setTimestamp(Instant.now())
embed.setAuthor(user.username, "https://chzzk.naver.com/live/${user.token}")
embed.addField("카테고리", status.categoryType.getOrNull() ?: "Unknown", true)
embed.addField("카테고리", status.liveCategoryValue, true)
embed.addField("태그", status.tags.joinToString(", ") { it.trim() }, true)
// embed.setImage(status.)

View File

@ -22,12 +22,16 @@ import io.ktor.server.websocket.*
import kotlinx.coroutines.delay
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import org.koin.java.KoinJavaComponent.inject
import space.mori.chzzk_bot.common.events.CoroutinesEventBus
import space.mori.chzzk_bot.common.events.UserRegisterEvent
import space.mori.chzzk_bot.common.services.UserService
import space.mori.chzzk_bot.webserver.routes.*
import space.mori.chzzk_bot.webserver.utils.DiscordRatelimits
import java.math.BigInteger
import java.security.SecureRandom
import java.time.Duration
import kotlin.getValue
import kotlin.time.toKotlinDuration
val dotenv = dotenv {
@ -81,6 +85,8 @@ val server = embeddedServer(Netty, port = 8080, ) {
}
}
routing {
val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
route("/auth") {
// discord login
authenticate("auth-oauth-discord") {
@ -191,7 +197,12 @@ val server = embeddedServer(Netty, port = 8080, ) {
val userInfo = getChzzkUser(tokenResponse.content.accessToken)
if(userInfo.content != null) {
val user = UserService.getUser(userInfo.content.channelId)
var user = UserService.getUser(userInfo.content.channelId)
if(user == null) {
user = UserService.saveUser(userInfo.content.channelName , userInfo.content.channelId)
}
call.sessions.set(
UserSession(
session.state,
@ -199,10 +210,13 @@ val server = embeddedServer(Netty, port = 8080, ) {
listOf()
)
)
user?.let { UserService.setRefreshToken(it,
UserService.setRefreshToken(user,
tokenResponse.content.accessToken,
tokenResponse.content.refreshToken ?: ""
) }
)
dispatcher.post(UserRegisterEvent(user.token))
call.respondRedirect(getFrontendURL(""))
}
} catch (e: Exception) {