mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-10 06:42:07 +01:00
Fix websocket token (#1766)
This commit is contained in:
@@ -251,4 +251,8 @@ tasks {
|
||||
processResources {
|
||||
dependsOn(":server:server-config-generate:generateSettings")
|
||||
}
|
||||
|
||||
processTestResources {
|
||||
dependsOn(":server:server-config-generate:generateSettings")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +155,10 @@ class ApolloSubscriptionProtocolHandler(
|
||||
): Flow<SubscriptionOperationMessage> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val user =
|
||||
context.getAttributeOrSet(Attribute.TachideskUser) {
|
||||
context.getAttributeOrSet(
|
||||
Attribute.TachideskUser,
|
||||
replaceIf = { it == UserType.Visitor },
|
||||
) {
|
||||
val payload = operationMessage.payload as? Map<String, Any?>
|
||||
val token = payload?.let { it[Header.AUTHORIZATION] as? String }
|
||||
getUserFromToken(token)
|
||||
|
||||
@@ -319,8 +319,15 @@ object JavalinSetup {
|
||||
|
||||
fun <T : Any> WsContext.getAttributeOrSet(
|
||||
attribute: Attribute<T>,
|
||||
replaceIf: (T) -> Boolean = { false },
|
||||
set: () -> T,
|
||||
): T =
|
||||
attribute(attribute.name)
|
||||
?: set().also { setAttribute(attribute, it) }
|
||||
): T {
|
||||
var item: T? = attribute(attribute.name)
|
||||
|
||||
if (item != null && replaceIf(item)) {
|
||||
item = null
|
||||
}
|
||||
|
||||
return item ?: set().also { setAttribute(attribute, it) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user