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:
parent
59fd85c628
commit
6a3446a3d5
|
@ -97,7 +97,7 @@ class ServerManager(serverSettings: ServerSettings, devSettings: DevSettings, ma
|
|||
lastBytesSent = statistics.get().bytesSent
|
||||
|
||||
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" }
|
||||
|
||||
this.state = state.lastRunning
|
||||
|
@ -164,7 +164,7 @@ class ServerManager(serverSettings: ServerSettings, devSettings: DevSettings, ma
|
|||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
LOGGER.warn(e) { "Graceful shutdown checker failed" }
|
||||
LOGGER.warn(e) { "Bandwidth shutdown checker/ping failed" }
|
||||
}
|
||||
}, 45, 45, TimeUnit.SECONDS)
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ import org.jetbrains.exposed.sql.Database
|
|||
import org.jetbrains.exposed.sql.SchemaUtils
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
private val LOGGER = LoggerFactory.getLogger(ImageServer::class.java)
|
||||
|
||||
|
@ -106,7 +107,12 @@ class ImageServer(
|
|||
}
|
||||
|
||||
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) {
|
||||
LOGGER.info { "Request for $sanitizedUri rejected for invalid token" }
|
||||
return@then Response(Status.FORBIDDEN)
|
||||
|
@ -122,17 +128,17 @@ class ImageServer(
|
|||
)
|
||||
} catch (e: JsonProcessingException) {
|
||||
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)) {
|
||||
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) {
|
||||
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)
|
||||
|
||||
return timeRequest()
|
||||
return addCommonHeaders()
|
||||
.then(timeRequest())
|
||||
.then(setHandled(isHandled))
|
||||
.then(catchAllHideDetails())
|
||||
.then(ServerFilters.CatchLensFailure)
|
||||
.then(setHandled(isHandled))
|
||||
.then(addCommonHeaders())
|
||||
.then(
|
||||
routes(
|
||||
"/data/{chapterHash}/{fileName}" bind Method.GET to imageServer.handler(dataSaver = false),
|
||||
|
|
Loading…
Reference in a new issue