mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-09 07:18:22 +00:00
Merge pull request #53 from dalbodeule/develop
debug discordHook logics, session fix.
This commit is contained in:
commit
6f9fe9ee21
@ -34,7 +34,8 @@ object Connector {
|
||||
TimerConfigs,
|
||||
LiveStatuses,
|
||||
SongLists,
|
||||
SongConfigs
|
||||
SongConfigs,
|
||||
Sessions
|
||||
)
|
||||
|
||||
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) {
|
||||
cookie<UserSession>("user_session", storage = SessionStorageMemory()) {}
|
||||
cookie<UserSession>("user_session", storage = MariadbSessionStorage()) {}
|
||||
}
|
||||
install(Authentication) {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
call.respond(HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class DiscordRequireRegisterDTO(
|
||||
val user: String,
|
||||
val passkey: String
|
||||
val token: String
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user