1
0
Fork 1
mirror of https://gitlab.com/mangadex-pub/mangadex_at_home.git synced 2024-01-19 02:48:37 +00:00

Fix stuff

This commit is contained in:
carbotaniuman 2021-01-09 05:25:11 +00:00
parent ab33d7a647
commit 93e8572c75
3 changed files with 35 additions and 13 deletions

View file

@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.2.3] - 2021-01-08 ## [1.2.3] - 2021-01-08
### Fixed ### Fixed
- [2021-01-08] Fix a bunch of stupid edge cases [@carbotaniuman]. - [2021-01-08] Fix a bunch of stupid edge cases [@carbotaniuman].
- [2021-01-08] Fix pathological shutdown issues [@carbotaniuman].
- [2021-01-08] Provide messages on request failures [@carbotaniuman].
- [2021-01-08] Exempt well-known test images [@carbotaniuman].
- [2021-01-08] Give actual errors and not 500 [@carbotaniuman].
## [1.2.2] - 2020-08-21 ## [1.2.2] - 2020-08-21
### Changed ### Changed
@ -246,7 +250,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- [2020-06-11] Tweaked logging configuration to reduce log file sizes by [@carbotaniuman]. - [2020-06-11] Tweaked logging configuration to reduce log file sizes by [@carbotaniuman].
[Unreleased]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.2.2...HEAD [Unreleased]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.2.3...HEAD
[1.2.3]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.2.2...1.2.3
[1.2.2]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.2.1...1.2.2 [1.2.2]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.2.1...1.2.2
[1.2.1]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.2.0...1.2.1 [1.2.1]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.2.0...1.2.1
[1.2.0]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.1.5...1.2.0 [1.2.0]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.1.5...1.2.0

View file

@ -172,16 +172,22 @@ class ServerManager(serverSettings: ServerSettings, devSettings: DevSettings, ma
} }
private fun pingControl() { private fun pingControl() {
// this is currentSettings, other is newSettings
// if tls is null that means same as previous ping
fun RemoteSettings.logicalEqual(other: RemoteSettings): Boolean {
val test = if (other.tls != null) {
other
} else {
other.copy(tls = this.tls)
}
return this == test
}
val state = this.state as Running val state = this.state as Running
val newSettings = serverHandler.pingControl(state.settings)?.run { val newSettings = serverHandler.pingControl(state.settings)
// copy the old tls over so we can do a simply equality check
if (tls == null) {
copy(tls = state.settings.tls)
} else {
this
}
}
if (newSettings != null) { if (newSettings != null) {
LOGGER.info { "Server settings received: $newSettings" } LOGGER.info { "Server settings received: $newSettings" }
@ -190,9 +196,9 @@ class ServerManager(serverSettings: ServerSettings, devSettings: DevSettings, ma
"Outdated build detected! Latest: ${newSettings.latestBuild}, Current: ${Constants.CLIENT_BUILD}" "Outdated build detected! Latest: ${newSettings.latestBuild}, Current: ${Constants.CLIENT_BUILD}"
} }
} }
if (state.settings != newSettings) { if (!state.settings.logicalEqual(newSettings)) {
// certificates or upstream url must have changed, restart webserver // certificates or upstream url must have changed, restart webserver
LOGGER.info { "Doing internal restart of HTTP server to refresh certs/upstream URL" } LOGGER.info { "Doing internal restart of HTTP server to refresh settings" }
this.state = GracefulStop(lastRunning = state) { this.state = GracefulStop(lastRunning = state) {
loginAndStartServer() loginAndStartServer()

View file

@ -60,6 +60,7 @@ import org.http4k.client.Apache4Client
import org.http4k.core.* import org.http4k.core.*
import org.http4k.filter.CachingFilters import org.http4k.filter.CachingFilters
import org.http4k.filter.ServerFilters import org.http4k.filter.ServerFilters
import org.http4k.lens.LensFailure
import org.http4k.lens.Path import org.http4k.lens.Path
import org.http4k.routing.bind import org.http4k.routing.bind
import org.http4k.routing.routes import org.http4k.routing.routes
@ -106,9 +107,15 @@ class ImageServer(
return@then Response(Status.FORBIDDEN) return@then Response(Status.FORBIDDEN)
} }
if (tokenized || remoteSettings.forceTokens) { if ((tokenized || remoteSettings.forceTokens) && !isTestImage(chapterHash)) {
val tokenArr = try { val tokenArr = try {
Base64.getUrlDecoder().decode(Path.of("token")(request)) val toDecode = try {
Path.of("token")(request)
} catch (e: LensFailure) {
LOGGER.info(e) { "Request for $sanitizedUri rejected for missing token" }
return@then Response(Status.FORBIDDEN).body("Token is missing")
}
Base64.getUrlDecoder().decode(toDecode)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
LOGGER.info(e) { "Request for $sanitizedUri rejected for non-base64 token" } LOGGER.info(e) { "Request for $sanitizedUri rejected for non-base64 token" }
return@then Response(Status.FORBIDDEN).body("Token is invalid base64") return@then Response(Status.FORBIDDEN).body("Token is invalid base64")
@ -338,6 +345,10 @@ class ImageServer(
.header("timing-allow-origin", "https://mangadex.org") .header("timing-allow-origin", "https://mangadex.org")
} }
}) })
private fun isTestImage(chapter: String): Boolean {
return chapter == "1b682e7b24ae7dbdc5064eeeb8e8e353" || chapter == "8172a46adc798f4f4ace6663322a383e"
}
} }
} }