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 {
|
processResources {
|
||||||
dependsOn(":server:server-config-generate:generateSettings")
|
dependsOn(":server:server-config-generate:generateSettings")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processTestResources {
|
||||||
|
dependsOn(":server:server-config-generate:generateSettings")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,10 @@ class ApolloSubscriptionProtocolHandler(
|
|||||||
): Flow<SubscriptionOperationMessage> {
|
): Flow<SubscriptionOperationMessage> {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val user =
|
val user =
|
||||||
context.getAttributeOrSet(Attribute.TachideskUser) {
|
context.getAttributeOrSet(
|
||||||
|
Attribute.TachideskUser,
|
||||||
|
replaceIf = { it == UserType.Visitor },
|
||||||
|
) {
|
||||||
val payload = operationMessage.payload as? Map<String, Any?>
|
val payload = operationMessage.payload as? Map<String, Any?>
|
||||||
val token = payload?.let { it[Header.AUTHORIZATION] as? String }
|
val token = payload?.let { it[Header.AUTHORIZATION] as? String }
|
||||||
getUserFromToken(token)
|
getUserFromToken(token)
|
||||||
|
|||||||
@@ -319,8 +319,15 @@ object JavalinSetup {
|
|||||||
|
|
||||||
fun <T : Any> WsContext.getAttributeOrSet(
|
fun <T : Any> WsContext.getAttributeOrSet(
|
||||||
attribute: Attribute<T>,
|
attribute: Attribute<T>,
|
||||||
|
replaceIf: (T) -> Boolean = { false },
|
||||||
set: () -> T,
|
set: () -> T,
|
||||||
): T =
|
): T {
|
||||||
attribute(attribute.name)
|
var item: T? = attribute(attribute.name)
|
||||||
?: set().also { setAttribute(attribute, it) }
|
|
||||||
|
if (item != null && replaceIf(item)) {
|
||||||
|
item = null
|
||||||
|
}
|
||||||
|
|
||||||
|
return item ?: set().also { setAttribute(attribute, it) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user