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 a bunch of stupid edge cases

This commit is contained in:
carbotaniuman 2021-01-08 17:02:24 -06:00
parent 59fd85c628
commit 6a3446a3d5
2 changed files with 15 additions and 9 deletions

View file

@ -97,7 +97,7 @@ class ServerManager(serverSettings: ServerSettings, devSettings: DevSettings, ma
lastBytesSent = statistics.get().bytesSent lastBytesSent = statistics.get().bytesSent
val state = this.state val state = this.state
if (state is GracefulStop) { if (state is GracefulStop && state.nextState != Shutdown) {
LOGGER.info { "Aborting graceful shutdown started due to hourly bandwidth limit" } LOGGER.info { "Aborting graceful shutdown started due to hourly bandwidth limit" }
this.state = state.lastRunning this.state = state.lastRunning
@ -164,7 +164,7 @@ class ServerManager(serverSettings: ServerSettings, devSettings: DevSettings, ma
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
LOGGER.warn(e) { "Graceful shutdown checker failed" } LOGGER.warn(e) { "Bandwidth shutdown checker/ping failed" }
} }
}, 45, 45, TimeUnit.SECONDS) }, 45, 45, TimeUnit.SECONDS)

View file

@ -69,6 +69,7 @@ import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.lang.IllegalArgumentException
private val LOGGER = LoggerFactory.getLogger(ImageServer::class.java) private val LOGGER = LoggerFactory.getLogger(ImageServer::class.java)
@ -106,7 +107,12 @@ class ImageServer(
} }
if (tokenized || remoteSettings.forceTokens) { if (tokenized || remoteSettings.forceTokens) {
val tokenArr = Base64.getUrlDecoder().decode(Path.of("token")(request)) val tokenArr = try {
Base64.getUrlDecoder().decode(Path.of("token")(request))
} catch (e: IllegalArgumentException) {
LOGGER.info(e) { "Request for $sanitizedUri rejected for non-base64 token" }
return@then Response(Status.FORBIDDEN).body("Token is invalid base64")
}
if (tokenArr.size < 24) { if (tokenArr.size < 24) {
LOGGER.info { "Request for $sanitizedUri rejected for invalid token" } LOGGER.info { "Request for $sanitizedUri rejected for invalid token" }
return@then Response(Status.FORBIDDEN) return@then Response(Status.FORBIDDEN)
@ -122,17 +128,17 @@ class ImageServer(
) )
} catch (e: JsonProcessingException) { } catch (e: JsonProcessingException) {
LOGGER.info(e) { "Request for $sanitizedUri rejected for invalid token" } LOGGER.info(e) { "Request for $sanitizedUri rejected for invalid token" }
return@then Response(Status.FORBIDDEN) return@then Response(Status.FORBIDDEN).body("Token is invalid")
} }
if (OffsetDateTime.now().isAfter(token.expires)) { if (OffsetDateTime.now().isAfter(token.expires)) {
LOGGER.info { "Request for $sanitizedUri rejected for expired token" } LOGGER.info { "Request for $sanitizedUri rejected for expired token" }
return@then Response(Status.GONE) return@then Response(Status.GONE).body("Token has expired")
} }
if (token.hash != chapterHash) { if (token.hash != chapterHash) {
LOGGER.info { "Request for $sanitizedUri rejected for inapplicable token" } LOGGER.info { "Request for $sanitizedUri rejected for inapplicable token" }
return@then Response(Status.FORBIDDEN) return@then Response(Status.FORBIDDEN).body("Token is inapplicable for the image")
} }
} }
@ -353,11 +359,11 @@ fun getServer(cache: DiskLruCache, database: Database, remoteSettings: RemoteSet
val imageServer = ImageServer(cache, database, statistics, remoteSettings, client) val imageServer = ImageServer(cache, database, statistics, remoteSettings, client)
return timeRequest() return addCommonHeaders()
.then(timeRequest())
.then(setHandled(isHandled))
.then(catchAllHideDetails()) .then(catchAllHideDetails())
.then(ServerFilters.CatchLensFailure) .then(ServerFilters.CatchLensFailure)
.then(setHandled(isHandled))
.then(addCommonHeaders())
.then( .then(
routes( routes(
"/data/{chapterHash}/{fileName}" bind Method.GET to imageServer.handler(dataSaver = false), "/data/{chapterHash}/{fileName}" bind Method.GET to imageServer.handler(dataSaver = false),