<commit_before>package controllers

import akka.pattern.ask
import com.github.ghik.silencer.silent
import play.api.data._, Forms._
import play.api.libs.json._
import play.api.mvc._

import lila.app._
import lila.common.HTTPRequest
import lila.hub.actorApi.captcha.ValidCaptcha
import makeTimeout.large
import views._

final class Main(
    env: Env,
    prismicC: Prismic,
    assetsC: ExternalAssets
) extends LilaController(env) {

  private lazy val blindForm = Form(
    tuple(
      "enable"   -> nonEmptyText,
      "redirect" -> nonEmptyText
    )
  )

  def toggleBlindMode = OpenBody { implicit ctx =>
    implicit val req = ctx.body
    fuccess {
      blindForm.bindFromRequest.fold(
        _ => BadRequest, {
          case (enable, redirect) =>
            Redirect(redirect) withCookies env.lilaCookie.cookie(
              env.api.config.accessibility.blindCookieName,
              if (enable == "0") "" else env.api.config.accessibility.hash,
              maxAge = env.api.config.accessibility.blindCookieMaxAge.toSeconds.toInt.some,
              httpOnly = true.some
            )
        }
      )
    }
  }

  def handlerNotFound(req: RequestHeader) = reqToCtx(req) map renderNotFound

  def captchaCheck(id: String) = Open { implicit ctx =>
    env.hub.captcher.actor ? ValidCaptcha(id, ~get("solution")) map {
      case valid: Boolean => Ok(if (valid) 1 else 0)
    }
  }

  def webmasters = Open { implicit ctx =>
    pageHit
    fuccess {
      html.site.help.webmasters()
    }
  }

  def lag = Open { implicit ctx =>
    pageHit
    fuccess {
      html.site.lag()
    }
  }

  def mobile = Open { implicit ctx =>
    pageHit
    OptionOk(prismicC getBookmark "mobile-apk") {
      case (doc, resolver) => html.mobile(doc, resolver)
    }
  }

  def dailyPuzzleSlackApp = Open { implicit ctx =>
    pageHit
    fuccess {
      html.site.dailyPuzzleSlackApp()
    }
  }

  def jslog(id: String) = Open { ctx =>
    env.round.selfReport(
      userId = ctx.userId,
      ip = HTTPRequest lastRemoteAddress ctx.req,
      fullId = lila.game.Game.FullId(id),
      name = get("n", ctx.req) | "?"
    )
    NoContent.fuccess
  }

  /**
    * Event monitoring endpoint
    */
  def jsmon(event: String) = Action {
    lila.mon.http.jsmon(event).increment
    NoContent
  }

  private lazy val glyphsResult: Result = {
    import chess.format.pgn.Glyph
    import lila.tree.Node.glyphWriter
    Ok(
      Json.obj(
        "move"        -> (Glyph.MoveAssessment.display: List[Glyph]),
        "position"    -> (Glyph.PositionAssessment.display: List[Glyph]),
        "observation" -> (Glyph.Observation.display: List[Glyph])
      )
    ) as JSON
  }
  val glyphs = Action(glyphsResult)

  def image(id: String, @silent hash: String, @silent name: String) = Action.async {
    env.imageRepo
      .fetch(id)
      .map {
        case None => NotFound
        case Some(image) =>
          lila.mon.http.imageBytes.record(image.size)
          Ok(image.data).withHeaders(
            CONTENT_DISPOSITION -> image.name
          ) as image.contentType.getOrElse("image/jpeg")
      }
  }

  val robots = Action { req =>
    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
"""
      else "User-agent: *\nDisallow: /"
    }
  }<commit_msg>tweak robots.txt to satisfy twitterbot<commit_after>package controllers

import akka.pattern.ask
import com.github.ghik.silencer.silent
import play.api.data._, Forms._
import play.api.libs.json._
import play.api.mvc._

import lila.app._
import lila.common.HTTPRequest
import lila.hub.actorApi.captcha.ValidCaptcha
import makeTimeout.large
import views._

final class Main(
    env: Env,
    prismicC: Prismic,
    assetsC: ExternalAssets
) extends LilaController(env) {

  private lazy val blindForm = Form(
    tuple(
      "enable"   -> nonEmptyText,
      "redirect" -> nonEmptyText
    )
  )

  def toggleBlindMode = OpenBody { implicit ctx =>
    implicit val req = ctx.body
    fuccess {
      blindForm.bindFromRequest.fold(
        _ => BadRequest, {
          case (enable, redirect) =>
            Redirect(redirect) withCookies env.lilaCookie.cookie(
              env.api.config.accessibility.blindCookieName,
              if (enable == "0") "" else env.api.config.accessibility.hash,
              maxAge = env.api.config.accessibility.blindCookieMaxAge.toSeconds.toInt.some,
              httpOnly = true.some
            )
        }
      )
    }
  }

  def handlerNotFound(req: RequestHeader) = reqToCtx(req) map renderNotFound

  def captchaCheck(id: String) = Open { implicit ctx =>
    env.hub.captcher.actor ? ValidCaptcha(id, ~get("solution")) map {
      case valid: Boolean => Ok(if (valid) 1 else 0)
    }
  }

  def webmasters = Open { implicit ctx =>
    pageHit
    fuccess {
      html.site.help.webmasters()
    }
  }

  def lag = Open { implicit ctx =>
    pageHit
    fuccess {
      html.site.lag()
    }
  }

  def mobile = Open { implicit ctx =>
    pageHit
    OptionOk(prismicC getBookmark "mobile-apk") {
      case (doc, resolver) => html.mobile(doc, resolver)
    }
  }

  def dailyPuzzleSlackApp = Open { implicit ctx =>
    pageHit
    fuccess {
      html.site.dailyPuzzleSlackApp()
    }
  }

  def jslog(id: String) = Open { ctx =>
    env.round.selfReport(
      userId = ctx.userId,
      ip = HTTPRequest lastRemoteAddress ctx.req,
      fullId = lila.game.Game.FullId(id),
      name = get("n", ctx.req) | "?"
    )
    NoContent.fuccess
  }

  /**
    * Event monitoring endpoint
    */
  def jsmon(event: String) = Action {
    lila.mon.http.jsmon(event).increment
    NoContent
  }

  private lazy val glyphsResult: Result = {
    import chess.format.pgn.Glyph
    import lila.tree.Node.glyphWriter
    Ok(
      Json.obj(
        "move"        -> (Glyph.MoveAssessment.display: List[Glyph]),
        "position"    -> (Glyph.PositionAssessment.display: List[Glyph]),
        "observation" -> (Glyph.Observation.display: List[Glyph])
      )
    ) as JSON
  }
  val glyphs = Action(glyphsResult)

  def image(id: String, @silent hash: String, @silent name: String) = Action.async {
    env.imageRepo
      .fetch(id)
      .map {
        case None => NotFound
        case Some(image) =>
          lila.mon.http.imageBytes.record(image.size)
          Ok(image.data).withHeaders(
            CONTENT_DISPOSITION -> image.name
          ) as image.contentType.getOrElse("image/jpeg")
      }
  }

  val robots = Action { req =>
    Ok {
      if (env.net.crawlable && req.domain == env.net.domain.value) """User-agent: *
Allow: /
Disallow: /game/export/
Disallow: /games/export/
Allow: /game/export/gif/thumbnail/
"""
      else "User-agent: *\nDisallow: /"
    }
  }
{'fraction_non_alphanumeric': 0.12090495078595563, 'fraction_numerical': 0.0008814455707360071, 'mean_word_length': 2.3972055888223553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5771372', 'n_tokens_mistral': 2301, 'n_tokens_neox': 2215, 'n_words': 464}