Merge pull request #121 from dalbodeule/develop

debug chzzk login
This commit is contained in:
JinU Choi 2025-01-08 23:45:30 +09:00 committed by GitHub
commit 6bf80c309f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,19 +40,13 @@ data class GetSessionDTO(
val isDisabled: Boolean val isDisabled: Boolean
) )
@Serializable
data class GetSettingDTO(
val isBotDisabled: Boolean,
val isBotMsgDisabled: Boolean,
)
@Serializable @Serializable
data class RegisterChzzkUserDTO( data class RegisterChzzkUserDTO(
val chzzkUrl: String val chzzkUrl: String
) )
fun Routing.apiRoutes() { fun Routing.apiRoutes() {
val chzzkIDRegex = """(?:.+chzzk\.naver\.com/)?([a-f0-9]{32})(?:.+)?""".toRegex() val chzzkIDRegex = """(?:.+chzzk\.naver\.com\/)?([a-f0-9]{32})(?:.+)?""".toRegex()
val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java) val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
route("/") { route("/") {
@ -108,16 +102,11 @@ fun Routing.apiRoutes() {
status.content?.channel?.let { it1 -> UserService.updateUser(user, it1.channelId, it1.channelName) } status.content?.channel?.let { it1 -> UserService.updateUser(user, it1.channelId, it1.channelName) }
} }
if(status.content == null) {
call.respondText(user.token, status = HttpStatusCode.NotFound)
return@get
}
returnUsers.add(GetSessionDTO( returnUsers.add(GetSessionDTO(
status.content!!.channel.channelId, status.content?.channel?.channelId ?: user.token,
status.content!!.channel.channelName, status.content?.channel?.channelName ?: user.token,
status.content!!.status == "OPEN", status.content?.status == "OPEN",
status.content!!.channel.channelImageUrl, status.content?.channel?.channelImageUrl ?: "",
songConfig.queueLimit, songConfig.queueLimit,
songConfig.personalLimit, songConfig.personalLimit,
songConfig.streamerOnly, songConfig.streamerOnly,
@ -128,7 +117,7 @@ fun Routing.apiRoutes() {
user.subordinates.toList() user.subordinates.toList()
} }
returnUsers.addAll(subordinates.map { returnUsers.addAll(subordinates.map {
val subStatus = it.token.let { token -> ChzzkUserCache.getCachedUser(token) } val subStatus = ChzzkUserCache.getCachedUser(it.token)
return@map if (subStatus?.content == null) { return@map if (subStatus?.content == null) {
null null
} else { } else {
@ -188,46 +177,4 @@ fun Routing.apiRoutes() {
return@post return@post
} }
} }
route("/settings") {
get {
val session = call.sessions.get<UserSession>()
if(session == null) {
call.respondText("No session found", status = HttpStatusCode.Unauthorized)
return@get
}
val user = UserService.getUser(session.id)
if(user == null) {
call.respondText("No session found", status = HttpStatusCode.Unauthorized)
return@get
}
call.respond(GetSettingDTO(
user.isDisabled, user.isDisableStartupMsg
))
}
post {
val session = call.sessions.get<UserSession>()
if(session == null) {
call.respondText("No session found", status = HttpStatusCode.Unauthorized)
return@post
}
val body: GetSettingDTO = call.receive()
val user = UserService.getUser(session.id)
if(user == null) {
call.respondText("No session found", status = HttpStatusCode.Unauthorized)
return@post
}
UserService.setIsDisabled(user, body.isBotDisabled)
UserService.setIsStartupDisabled(user, body.isBotMsgDisabled)
call.respond(GetSettingDTO(
user.isDisabled, user.isDisableStartupMsg
))
}
}
} }