mirror of
https://github.com/gotson/komga.git
synced 2025-12-06 08:32:25 +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 komgaSyncTokenGenerator: KomgaSyncTokenGenerator,
|
||||||
private val komgaSettingsProvider: KomgaSettingsProvider,
|
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 {
|
private val pathRegex = """/kobo/[-\w]*(.*)""".toRegex()
|
||||||
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 headersOutInclude =
|
private val headersOutInclude =
|
||||||
setOf(
|
setOf(
|
||||||
|
|
@ -120,7 +116,7 @@ class KoboProxy(
|
||||||
}.apply { if (body != null) body(body) }
|
}.apply { if (body != null) body(body) }
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.onStatus(HttpStatusCode::isError) { _, response ->
|
.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)
|
throw ResponseStatusException(response.statusCode, response.statusText)
|
||||||
}.toEntity<JsonNode>()
|
}.toEntity<JsonNode>()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -194,6 +194,7 @@ class KoboController(
|
||||||
try {
|
try {
|
||||||
koboProxy.proxyCurrentRequest().body?.get("Resources")
|
koboProxy.proxyCurrentRequest().body?.get("Resources")
|
||||||
} catch (e: Exception) {
|
} 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" }
|
logger.warn { "Failed to get response from Kobo /v1/initialization, fallback to noproxy" }
|
||||||
null
|
null
|
||||||
} ?: koboProxy.nativeKoboResources
|
} ?: koboProxy.nativeKoboResources
|
||||||
|
|
@ -233,7 +234,7 @@ class KoboController(
|
||||||
): Any {
|
): Any {
|
||||||
try {
|
try {
|
||||||
return koboProxy.proxyCurrentRequest(body)
|
return koboProxy.proxyCurrentRequest(body)
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
logger.warn { "Failed to get response from Kobo /v1/auth/device, fallback to noproxy" }
|
logger.warn { "Failed to get response from Kobo /v1/auth/device, fallback to noproxy" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -395,7 +396,7 @@ class KoboController(
|
||||||
addAll(
|
addAll(
|
||||||
// changed books are also passed as changed reading state because Kobo does not process ChangedEntitlement even if it contains a ReadingState
|
// 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 ->
|
(booksChanged.content + changedReadingState.content).mapNotNull { book ->
|
||||||
readProgress[book.bookId]?.let { it ->
|
readProgress[book.bookId]?.let {
|
||||||
ChangedReadingStateDto(
|
ChangedReadingStateDto(
|
||||||
WrappedReadingStateDto(
|
WrappedReadingStateDto(
|
||||||
it.toDto(),
|
it.toDto(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue