Skip to content

Commit

Permalink
Add get file logs
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPowerGamerBR committed Nov 16, 2024
1 parent dfc5fdb commit 1aacac1
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.ktor.server.application.*
import io.ktor.server.response.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import mu.KotlinLogging
import net.perfectdreams.etherealgambi.backend.EtherealGambi
import net.perfectdreams.etherealgambi.backend.utils.SimpleImageInfo
import net.perfectdreams.sequins.ktor.BaseRoute
Expand All @@ -13,6 +14,7 @@ import java.io.File
class GetFileRoute(val m: EtherealGambi) : BaseRoute("/{file...}") {
companion object {
val variantRegex = Regex("@([A-z0-9]+)")
private val logger = KotlinLogging.logger {}
}

override suspend fun onRequest(call: ApplicationCall) {
Expand All @@ -27,10 +29,14 @@ class GetFileRoute(val m: EtherealGambi) : BaseRoute("/{file...}") {
if (completePath.any { it == ".." })
return

logger.info { "Trying to get file $completePath" }

val fileWithUnknownVariant = completePath.last()
val pathWithoutFile = completePath.dropLast(1)
val variantResult = m.getVariantFromFileName(pathWithoutFile.joinToString("/"), fileWithUnknownVariant)

logger.info { "Get file $completePath result is $variantResult" }

when (variantResult) {
is EtherealGambi.UnsupportedVariantImageFormat -> {
// Couldn't figure out an image from the URL... so let's check if we can serve the file "raw"!
Expand Down Expand Up @@ -86,7 +92,7 @@ class GetFileRoute(val m: EtherealGambi) : BaseRoute("/{file...}") {
}
}
} catch (e: Exception) {
e.printStackTrace()
logger.warn(e) { "Something went wrong while trying to get file!" }
}
}
}

0 comments on commit 1aacac1

Please sign in to comment.