Update apiKey extraction logic
This commit is contained in:
parent
f644b2a2a2
commit
0e49ff8549
2 changed files with 14 additions and 10 deletions
|
@ -339,7 +339,7 @@ internal val ApiEndpointsMap = mapOf(
|
|||
"WiadomoscNowa" to "67601f5e-c268-43d6-8083-09c4dc3381e6",
|
||||
"Pracownicy" to "8c104c09-55b2-44b8-9b6a-22bd5cb86f39",
|
||||
"MoveTrash" to "51a490c5-a6dc-4cff-9216-b2dadb0707df",
|
||||
"RestoreTrash" to "",
|
||||
"RestoreTrash" to "c9848486-e687-4179-a73e-55b1781f3e19",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
@ -422,4 +422,7 @@ internal val ApiEndpointsVTokenSchemeMap = mapOf(
|
|||
"24.04.0005.58736" to mapOf(
|
||||
"uonetplus-wiadomosciplus" to "{UUID}-{appCustomerDb}-{appVersion}-{apiKey}",
|
||||
),
|
||||
"24.04.0006.58753" to mapOf(
|
||||
"uonetplus-wiadomosciplus" to "{UUID}-{appCustomerDb}-{appVersion}-{apiKey}",
|
||||
),
|
||||
)
|
||||
|
|
|
@ -77,17 +77,14 @@ internal fun getScriptParam(name: String, content: String, fallback: String = ""
|
|||
}
|
||||
|
||||
internal fun getApiKey(document: Document, fallback: String = ""): String {
|
||||
val script = document.getElementsByTag("script").toList()
|
||||
.map { element -> element.html() }
|
||||
.filter { text -> text.length < 500 }
|
||||
.filter { text -> text.contains("VParam") && text.contains("apiKey") }
|
||||
.firstOrNull()
|
||||
val scripts = document.getElementsByTag("script").toList().map { it.html() }
|
||||
val script = scripts.lastOrNull { "VParam" in it }
|
||||
|
||||
if (script == null) {
|
||||
return fallback
|
||||
}
|
||||
|
||||
return "(\\d{5,8})".toRegex().find(script).let { result ->
|
||||
return "(\\d{7})".toRegex().findAll(script).lastOrNull().let { result ->
|
||||
if (null !== result) result.groupValues[1] else fallback
|
||||
}
|
||||
}
|
||||
|
@ -307,15 +304,19 @@ private fun getVToken(uuid: String, headers: ModuleHeaders?, moduleHost: String)
|
|||
|
||||
val scheme = Scrapper.vTokenSchemeMap[headers?.appVersion]
|
||||
?.get(moduleHost)
|
||||
?: "{UUID}-{appCustomerDb}-{appVersion}"
|
||||
?: "{UUID}-{appCustomerDb}-{appVersion}-{apiKey}"
|
||||
val schemeToSubstitute = scheme
|
||||
.replace("{UUID}", uuid)
|
||||
.let { updatedScheme ->
|
||||
headers?.apiKey?.takeIf { it.isNotBlank() }?.let {
|
||||
updatedScheme.replace("{apiKey}", it)
|
||||
} ?: updatedScheme
|
||||
}
|
||||
|
||||
val vTokenEncoded = runCatching {
|
||||
vTokenSchemeKeysRegex.replace(schemeToSubstitute) {
|
||||
val key = it.groupValues[1]
|
||||
val fallback = if (key == "apiKey") headers?.apiKey.orEmpty() else key
|
||||
headers?.vParams.orEmpty()[key] ?: fallback
|
||||
headers?.vParams.orEmpty()[key] ?: key
|
||||
}
|
||||
}.onFailure {
|
||||
logger.error("Error preparing vtoken!", it)
|
||||
|
|
Loading…
Reference in a new issue