Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Nov 15, 2024
1 parent 8b20f3e commit c1c0142
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions app/src/main/java/io/legado/app/data/entities/BaseSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import io.legado.app.help.SymmetricCryptoAndroid
import io.legado.app.help.config.AppConfig
import io.legado.app.help.http.CookieStore
import io.legado.app.model.SharedJsScope
import io.legado.app.utils.*
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.has
import io.legado.app.utils.printOnDebug
import org.intellij.lang.annotations.Language
import org.mozilla.javascript.Scriptable

Expand Down Expand Up @@ -99,19 +103,13 @@ interface BaseSource : JsExtensions {
*/
fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap<String, String>().apply {
header?.let {
val savedHeader = it
header = null
val json = try {
when {
it.startsWith("@js:", true) -> evalJS(it.substring(4)).toString()
it.startsWith("<js>", true) -> evalJS(
it.substring(4, it.lastIndexOf("<"))
).toString()

else -> it
}
} finally {
header = savedHeader
val json = when {
it.startsWith("@js:", true) -> evalJS(it.substring(4)).toString()
it.startsWith("<js>", true) -> evalJS(
it.substring(4, it.lastIndexOf("<"))
).toString()

else -> it
}
GSON.fromJsonObject<Map<String, String>>(json).getOrNull()?.let { map ->
putAll(map)
Expand Down

0 comments on commit c1c0142

Please sign in to comment.