Skip to content

Commit

Permalink
don't let crawlers generate game gifs
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 19, 2025
1 parent 9e4ccc0 commit 7a1ddb8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions app/controllers/Export.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,29 @@ import lila.pref.{ PieceSet, Theme }

final class Export(env: Env) extends LilaController(env):

private def exportImageOf[A](fetch: Fu[Option[A]])(convert: A => Fu[Result]) = Anon:
private def exportImageOf[A](fetch: Fu[Option[A]])(convert: A => Fu[Result])(using Context) =
Found(fetch): res =>
limit.exportImage(((), req.ipAddress), rateLimited)(convert(res))

def gif(id: GameId, color: Color, theme: Option[String], piece: Option[String]) =
exportImageOf(env.game.gameRepo.gameWithInitialFen(id)) { g =>
env.game.gifExport
.fromPov(Pov(g.game, color), g.fen, Theme(theme).name, PieceSet.get(piece).name)
.pipe(stream(cacheSeconds = if g.game.finishedOrAborted then 3600 * 24 else 10))
}
def gif(id: GameId, color: Color, theme: Option[String], piece: Option[String]) = Anon:
NoCrawlers:
exportImageOf(env.game.gameRepo.gameWithInitialFen(id)) { g =>
env.game.gifExport
.fromPov(Pov(g.game, color), g.fen, Theme(theme).name, PieceSet.get(piece).name)
.pipe(stream(cacheSeconds = if g.game.finishedOrAborted then 3600 * 24 else 10))
}

def legacyGameThumbnail(id: GameId, theme: Option[String], piece: Option[String]) = Anon:
MovedPermanently(routes.Export.gameThumbnail(id, theme, piece).url)

def gameThumbnail(id: GameId, theme: Option[String], piece: Option[String]) =
def gameThumbnail(id: GameId, theme: Option[String], piece: Option[String]) = Anon:
exportImageOf(env.game.gameRepo.game(id)) { game =>
env.game.gifExport
.gameThumbnail(game, Theme(theme).name, PieceSet.get(piece).name)
.pipe(stream(cacheSeconds = if game.finishedOrAborted then 3600 * 24 else 10))
}

def puzzleThumbnail(id: PuzzleId, theme: Option[String], piece: Option[String]) =
def puzzleThumbnail(id: PuzzleId, theme: Option[String], piece: Option[String]) = Anon:
exportImageOf(env.puzzle.api.puzzle.find(id)) { puzzle =>
env.game.gifExport
.thumbnail(
Expand All @@ -54,7 +55,7 @@ final class Export(env: Env) extends LilaController(env):
variant: Option[Variant.LilaKey],
theme: Option[String],
piece: Option[String]
) =
) = Anon:
exportImageOf(fuccess(Fen.read(Variant.orDefault(variant), Fen.Full.clean(fen)))) { situation =>
env.game.gifExport
.thumbnail(
Expand Down

0 comments on commit 7a1ddb8

Please sign in to comment.