Decider admin access to deciders by steam id
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package controllers
|
||||
|
||||
import java.io.File
|
||||
import javax.inject.{Inject, Singleton}
|
||||
|
||||
import play.api.mvc.{AbstractController, ControllerComponents}
|
||||
import repository.MapImageRepository
|
||||
|
||||
import scala.concurrent.ExecutionContext
|
||||
|
||||
/**
|
||||
* Раздаёт картинки карт из каталога, заданного в конфиге (`maps.imagesDir`).
|
||||
*
|
||||
* Нужен потому, что каталог может находиться вне `public`/`app/assets`
|
||||
* (например, на сервере), и стандартный Assets его не отдаст.
|
||||
*/
|
||||
@Singleton
|
||||
class MapImageController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
|
||||
|
||||
implicit val ec: ExecutionContext = cc.executionContext
|
||||
|
||||
def image(file: String) = Action { implicit request =>
|
||||
MapImageRepository.findFile(file) match {
|
||||
case Some(image) =>
|
||||
Ok.sendFile(image, inline = true)
|
||||
.as(contentType(image))
|
||||
.withHeaders(CACHE_CONTROL -> "public, max-age=86400")
|
||||
case None => NotFound
|
||||
}
|
||||
}
|
||||
|
||||
private def contentType(file: File): String = {
|
||||
val name = file.getName.toLowerCase
|
||||
if (name.endsWith(".png")) "image/png"
|
||||
else if (name.endsWith(".webp")) "image/webp"
|
||||
else "image/jpeg"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user