live secret keys to bypass live game export delay

pull/6578/head
Thibault Duplessis 2020-05-08 09:31:27 -06:00
parent e86a9fd797
commit 2db2fdd1e2
4 changed files with 15 additions and 5 deletions

View File

@ -2,14 +2,15 @@ package lila.app
import akka.actor._
import com.softwaremill.macwire._
import lila.memo.SettingStore.Strings._
import play.api.libs.ws.WSClient
import play.api.mvc.{ ControllerComponents, SessionCookieBaker }
import play.api.{ Configuration, Environment, Mode }
import scala.concurrent.duration._
import scala.concurrent.{ ExecutionContext, Future }
import lila.common.{ Bus, Lilakka }
import lila.common.config._
import lila.common.{ Bus, Lilakka, Strings }
final class Env(
val config: Configuration,
@ -99,6 +100,12 @@ final class Env(
default = 10,
text = "API timeline entries to serve".some
)
lazy val noDelaySecretSetting = memo.settingStore[Strings](
"noDelaySecrets",
default = Strings(Nil),
text =
"Secret tokens that allows fetching ongoing games without the 3-moves delay. Separated by commas.".some
)
lazy val preloader = wire[mashup.Preload]
lazy val socialInfo = wire[mashup.UserInfo.SocialApi]

View File

@ -17,7 +17,8 @@ final class Dev(env: Env) extends LilaController(env) {
env.streamer.alwaysFeaturedSetting,
env.rating.ratingFactorsSetting,
env.plan.donationGoalSetting,
env.apiTimelineSetting
env.apiTimelineSetting,
env.noDelaySecretSetting
)
def settings =

View File

@ -41,7 +41,8 @@ final class Game(
val config = GameApiV2.OneConfig(
format = if (HTTPRequest acceptsJson req) GameApiV2.Format.JSON else GameApiV2.Format.PGN,
imported = getBool("imported", req),
flags = requestPgnFlags(req, extended = true)
flags = requestPgnFlags(req, extended = true),
noDelay = get("key", req).exists(env.noDelaySecretSetting.get().value.contains)
)
env.api.gameApiV2.exportOne(game, config) flatMap { content =>
env.api.gameApiV2.filename(game, config.format) map { filename =>

View File

@ -31,7 +31,7 @@ final class GameApiV2(
def exportOne(game: Game, configInput: OneConfig): Fu[String] = {
val config = configInput.copy(
flags = configInput.flags.copy(
delayMoves = game.playable ?? 3,
delayMoves = (game.playable && !configInput.noDelay) ?? 3,
evals = configInput.flags.evals && !game.playable
)
)
@ -237,7 +237,8 @@ object GameApiV2 {
case class OneConfig(
format: Format,
imported: Boolean,
flags: WithFlags
flags: WithFlags,
noDelay: Boolean
) extends Config
case class ByUserConfig(