mirror of
https://github.com/gotson/komga.git
synced 2025-12-06 00:25:08 +01:00
fix(kobo): proxy 401 errors on initialization
Co-authored-by: Gauthier Roebroeck <gauthier.roebroeck@gmail.com>
This commit is contained in:
parent
0f25453949
commit
3739951b36
2 changed files with 21 additions and 24 deletions
|
|
@ -30,28 +30,24 @@ class KoboProxy(
|
|||
private val komgaSyncTokenGenerator: KomgaSyncTokenGenerator,
|
||||
private val komgaSettingsProvider: KomgaSettingsProvider,
|
||||
) {
|
||||
private val koboApiClient: RestClient
|
||||
private val koboApiClient: RestClient =
|
||||
RestClient
|
||||
.builder()
|
||||
.uriBuilderFactory(
|
||||
DefaultUriBuilderFactory("https://storeapi.kobo.com")
|
||||
.apply {
|
||||
this.encodingMode = DefaultUriBuilderFactory.EncodingMode.NONE
|
||||
},
|
||||
).requestFactory(
|
||||
ClientHttpRequestFactoryBuilder.reactor().build(
|
||||
ClientHttpRequestFactorySettings
|
||||
.defaults()
|
||||
.withReadTimeout(1.minutes.toJavaDuration())
|
||||
.withConnectTimeout(1.minutes.toJavaDuration()),
|
||||
),
|
||||
).build()
|
||||
|
||||
init {
|
||||
val uriBuilderFactory = DefaultUriBuilderFactory("https://storeapi.kobo.com")
|
||||
uriBuilderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE)
|
||||
|
||||
koboApiClient =
|
||||
RestClient
|
||||
.builder()
|
||||
.uriBuilderFactory(
|
||||
uriBuilderFactory,
|
||||
).requestFactory(
|
||||
ClientHttpRequestFactoryBuilder.reactor().build(
|
||||
ClientHttpRequestFactorySettings
|
||||
.defaults()
|
||||
.withReadTimeout(1.minutes.toJavaDuration())
|
||||
.withConnectTimeout(1.minutes.toJavaDuration()),
|
||||
),
|
||||
).build()
|
||||
}
|
||||
|
||||
private val pathRegex = """\/kobo\/[-\w]*(.*)""".toRegex()
|
||||
private val pathRegex = """/kobo/[-\w]*(.*)""".toRegex()
|
||||
|
||||
private val headersOutInclude =
|
||||
setOf(
|
||||
|
|
@ -120,7 +116,7 @@ class KoboProxy(
|
|||
}.apply { if (body != null) body(body) }
|
||||
.retrieve()
|
||||
.onStatus(HttpStatusCode::isError) { _, response ->
|
||||
logger.debug { "Kobo response: $response" }
|
||||
logger.debug { "Kobo response: ${response.statusCode}: ${response.body.bufferedReader().use { it.readText() }}" }
|
||||
throw ResponseStatusException(response.statusCode, response.statusText)
|
||||
}.toEntity<JsonNode>()
|
||||
|
||||
|
|
|
|||
|
|
@ -194,6 +194,7 @@ class KoboController(
|
|||
try {
|
||||
koboProxy.proxyCurrentRequest().body?.get("Resources")
|
||||
} catch (e: Exception) {
|
||||
if (e is ResponseStatusException && e.statusCode == HttpStatus.UNAUTHORIZED) throw e
|
||||
logger.warn { "Failed to get response from Kobo /v1/initialization, fallback to noproxy" }
|
||||
null
|
||||
} ?: koboProxy.nativeKoboResources
|
||||
|
|
@ -233,7 +234,7 @@ class KoboController(
|
|||
): Any {
|
||||
try {
|
||||
return koboProxy.proxyCurrentRequest(body)
|
||||
} catch (e: Exception) {
|
||||
} catch (_: Exception) {
|
||||
logger.warn { "Failed to get response from Kobo /v1/auth/device, fallback to noproxy" }
|
||||
}
|
||||
|
||||
|
|
@ -395,7 +396,7 @@ class KoboController(
|
|||
addAll(
|
||||
// changed books are also passed as changed reading state because Kobo does not process ChangedEntitlement even if it contains a ReadingState
|
||||
(booksChanged.content + changedReadingState.content).mapNotNull { book ->
|
||||
readProgress[book.bookId]?.let { it ->
|
||||
readProgress[book.bookId]?.let {
|
||||
ChangedReadingStateDto(
|
||||
WrappedReadingStateDto(
|
||||
it.toDto(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue