mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-09 07:18:22 +00:00
debug discordHook logics, session fix.
- DiscordHook normal respond is not defined - add MariadbSessionStorage
This commit is contained in:
parent
e951ccee56
commit
2335a09391
@ -34,7 +34,8 @@ object Connector {
|
|||||||
TimerConfigs,
|
TimerConfigs,
|
||||||
LiveStatuses,
|
LiveStatuses,
|
||||||
SongLists,
|
SongLists,
|
||||||
SongConfigs
|
SongConfigs,
|
||||||
|
Sessions
|
||||||
)
|
)
|
||||||
|
|
||||||
transaction {
|
transaction {
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package space.mori.chzzk_bot.common.models
|
||||||
|
|
||||||
|
import org.jetbrains.exposed.dao.IntEntity
|
||||||
|
import org.jetbrains.exposed.dao.IntEntityClass
|
||||||
|
import org.jetbrains.exposed.dao.id.EntityID
|
||||||
|
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||||
|
|
||||||
|
object Sessions: IntIdTable("session") {
|
||||||
|
val key = text("key")
|
||||||
|
val value = text("value")
|
||||||
|
}
|
||||||
|
|
||||||
|
class Session(id: EntityID<Int>) : IntEntity(id) {
|
||||||
|
companion object : IntEntityClass<Session>(Sessions)
|
||||||
|
|
||||||
|
var key by Sessions.key
|
||||||
|
var value by Sessions.value
|
||||||
|
}
|
@ -47,7 +47,7 @@ val server = embeddedServer(Netty, port = 8080, ) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
install(Sessions) {
|
install(Sessions) {
|
||||||
cookie<UserSession>("user_session", storage = SessionStorageMemory()) {}
|
cookie<UserSession>("user_session", storage = MariadbSessionStorage()) {}
|
||||||
}
|
}
|
||||||
install(Authentication) {
|
install(Authentication) {
|
||||||
oauth("auth-oauth-naver") {
|
oauth("auth-oauth-naver") {
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package space.mori.chzzk_bot.webserver
|
||||||
|
|
||||||
|
import io.ktor.server.sessions.*
|
||||||
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
import space.mori.chzzk_bot.common.models.Session
|
||||||
|
import space.mori.chzzk_bot.common.models.Sessions as SessionTable
|
||||||
|
|
||||||
|
class MariadbSessionStorage: SessionStorage {
|
||||||
|
override suspend fun invalidate(id: String) {
|
||||||
|
return transaction {
|
||||||
|
val session = Session.find(
|
||||||
|
SessionTable.key eq id
|
||||||
|
).firstOrNull()
|
||||||
|
session?.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun read(id: String): String {
|
||||||
|
return transaction {
|
||||||
|
val session = Session.find(SessionTable.key eq id).firstOrNull()
|
||||||
|
?: throw NoSuchElementException("Session $id not found")
|
||||||
|
session.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun write(id: String, value: String) {
|
||||||
|
Session.findSingleByAndUpdate(SessionTable.key eq id) {
|
||||||
|
it.value = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -49,12 +49,12 @@ fun Route.apiDiscordRoutes() {
|
|||||||
return@get
|
return@get
|
||||||
}
|
}
|
||||||
|
|
||||||
|
call.respond(HttpStatusCode.OK)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class DiscordRequireRegisterDTO(
|
data class DiscordRequireRegisterDTO(
|
||||||
val user: String,
|
val user: String,
|
||||||
val passkey: String
|
val token: String
|
||||||
)
|
)
|
Loading…
x
Reference in New Issue
Block a user