Skip to content

Commit

Permalink
allow robot access to gif thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Mar 9, 2020
1 parent 532b024 commit 5e8ecef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
30 changes: 13 additions & 17 deletions app/controllers/Export.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ final class Export(env: Env) extends LilaController(env) {
}

def gameThumbnail(id: String) = Open { implicit ctx =>
OnlyHumansAndFacebookOrTwitter {
ExportRateLimitGlobal("-", msg = HTTPRequest.lastRemoteAddress(ctx.req).value) {
OptionFuResult(env.game.gameRepo game id) { game =>
env.game.gifExport.gameThumbnail(game) map
stream("image/gif") map
gameImageCacheSeconds(game)
}
ExportRateLimitGlobal("-", msg = HTTPRequest.lastRemoteAddress(ctx.req).value) {
OptionFuResult(env.game.gameRepo game id) { game =>
env.game.gifExport.gameThumbnail(game) map
stream("image/gif") map
gameImageCacheSeconds(game)
}
}
}
Expand All @@ -54,16 +52,14 @@ final class Export(env: Env) extends LilaController(env) {
}

def puzzleThumbnail(id: Int) = Open { implicit ctx =>
OnlyHumansAndFacebookOrTwitter {
ExportRateLimitGlobal("-", msg = HTTPRequest.lastRemoteAddress(ctx.req).value) {
OptionFuResult(env.puzzle.api.puzzle find id) { puzzle =>
env.game.gifExport.thumbnail(
fen = chess.format.FEN(puzzle.fenAfterInitialMove | puzzle.fen),
lastMove = puzzle.initialMove.uci.some,
orientation = puzzle.color
) map stream("image/gif") map { res =>
res.withHeaders(CACHE_CONTROL -> "max-age=86400")
}
ExportRateLimitGlobal("-", msg = HTTPRequest.lastRemoteAddress(ctx.req).value) {
OptionFuResult(env.puzzle.api.puzzle find id) { puzzle =>
env.game.gifExport.thumbnail(
fen = chess.format.FEN(puzzle.fenAfterInitialMove | puzzle.fen),
lastMove = puzzle.initialMove.uci.some,
orientation = puzzle.color
) map stream("image/gif") map { res =>
res.withHeaders(CACHE_CONTROL -> "max-age=86400")
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/controllers/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ final class Main(
Ok {
if (env.net.crawlable && req.domain == env.net.domain.value) """User-agent: *
Allow: /
Allow: /game/export/gif/thumbnail/
Disallow: /game/export
Disallow: /games/export
"""
Expand Down

0 comments on commit 5e8ecef

Please sign in to comment.