diff --git a/app/controllers/Analyse.scala b/app/controllers/Analyse.scala index c3e1c3a731..65aa2ef22b 100644 --- a/app/controllers/Analyse.scala +++ b/app/controllers/Analyse.scala @@ -63,7 +63,7 @@ object Analyse extends LilaController { if (HTTPRequest.isBot(ctx.req)) divider.empty else divider(pov.game, initialFen) val pgn = Env.game.pgnDump(pov.game, initialFen) - Env.api.roundApi.watcher(pov, Env.api.version, tv = none, analysis.map(pgn -> _), initialFen = initialFen.some) map { data => + Env.api.roundApi.watcher(pov, lila.api.MobileApi.currentVersion, tv = none, analysis.map(pgn -> _), initialFen = initialFen.some) map { data => Ok(html.analyse.replay( pov, data, diff --git a/app/controllers/Round.scala b/app/controllers/Round.scala index 3dd483c396..e0c5642197 100644 --- a/app/controllers/Round.scala +++ b/app/controllers/Round.scala @@ -56,7 +56,7 @@ object Round extends LilaController with TheftPrevention { Env.game.crosstableApi(pov.game) zip (!pov.game.isTournament ?? otherPovs(pov.gameId)) flatMap { case ((tour, crosstable), playing) => - Env.api.roundApi.player(pov, Env.api.version, playing) map { data => + Env.api.roundApi.player(pov, lila.api.MobileApi.currentVersion, playing) map { data => Ok(html.round.player(pov, data, tour = tour, cross = crosstable, playing = playing)) } } @@ -114,7 +114,7 @@ object Round extends LilaController with TheftPrevention { case None => (pov.game.tournamentId ?? TournamentRepo.byId) zip Env.game.crosstableApi(pov.game) zip - Env.api.roundApi.watcher(pov, Env.api.version, tv = none) map { + Env.api.roundApi.watcher(pov, lila.api.MobileApi.currentVersion, tv = none) map { case ((tour, crosstable), data) => Ok(html.round.watcher(pov, data, tour, crosstable, userTv = userTv)) } @@ -124,7 +124,7 @@ object Round extends LilaController with TheftPrevention { private def join(pov: Pov)(implicit ctx: Context): Fu[Result] = GameRepo initialFen pov.game zip - Env.api.roundApi.player(pov, Env.api.version, otherPovs = Nil) zip + Env.api.roundApi.player(pov, lila.api.MobileApi.currentVersion, otherPovs = Nil) zip ((pov.player.userId orElse pov.opponent.userId) ?? UserRepo.byId) map { case ((fen, data), opponent) => Ok(html.setup.join( pov, data, opponent, Env.setup.friendConfigMemo get pov.game.id, fen)) diff --git a/app/controllers/Setup.scala b/app/controllers/Setup.scala index 9a6e43a2d1..a0509033b0 100644 --- a/app/controllers/Setup.scala +++ b/app/controllers/Setup.scala @@ -138,7 +138,7 @@ object Setup extends LilaController with TheftPrevention with play.api.http.Cont OptionFuResult(GameRepo pov fullId) { pov => pov.game.started.fold( Redirect(routes.Round.player(pov.fullId)).fuccess, - Env.api.roundApi.player(pov, Env.api.version, otherPovs = Nil) zip + Env.api.roundApi.player(pov, lila.api.MobileApi.currentVersion, otherPovs = Nil) zip (userId ?? UserRepo.named) flatMap { case (data, user) => PreventTheft(pov) { Ok(html.setup.await( diff --git a/app/controllers/Tv.scala b/app/controllers/Tv.scala index eaeb57bede..cdffea8e51 100644 --- a/app/controllers/Tv.scala +++ b/app/controllers/Tv.scala @@ -36,7 +36,7 @@ object Tv extends LilaController { private def lichessTv(implicit ctx: Context) = OptionFuResult(Env.tv.featured.one) { game => val flip = getBool("flip") val pov = flip.fold(Pov second game, Pov first game) - Env.api.roundApi.watcher(pov, Env.api.version, tv = flip.some) zip + Env.api.roundApi.watcher(pov, lila.api.MobileApi.currentVersion, tv = flip.some) zip (GameRepo onTv 10) zip Env.game.crosstableApi(game) zip Env.tv.streamsOnAir zip diff --git a/app/templating/Environment.scala b/app/templating/Environment.scala index 1147755ddf..ee1056b2b8 100644 --- a/app/templating/Environment.scala +++ b/app/templating/Environment.scala @@ -51,7 +51,7 @@ object Environment def isProd = apiEnv.isProd - def apiVersion = apiEnv.version + def apiVersion = lila.api.MobileApi.currentVersion lazy val siteMenu = new lila.app.ui.SiteMenu(trans) diff --git a/modules/api/src/main/Env.scala b/modules/api/src/main/Env.scala index 33b30a35d1..4653ceed2b 100644 --- a/modules/api/src/main/Env.scala +++ b/modules/api/src/main/Env.scala @@ -36,8 +36,6 @@ final class Env( val PrismicApiUrl = config getString "prismic.api_url" val EditorAnimationDuration = config duration "editor.animation.duration" - val version = config getInt "api.version" - object Accessibility { val blindCookieName = config getString "accessibility.blind.cookie.name" val blindCookieMaxAge = config getInt "accessibility.blind.cookie.max_age" diff --git a/modules/api/src/main/MobileApi.scala b/modules/api/src/main/MobileApi.scala new file mode 100644 index 0000000000..8ba721c67b --- /dev/null +++ b/modules/api/src/main/MobileApi.scala @@ -0,0 +1,24 @@ +package lila.api + +import org.joda.time.DateTime + +object MobileApi { + + case class Old( + version: Int, + // date when a newer version was released + deprecatedAt: DateTime, + // date when the server stops accepting requests + unsupportedAt: DateTime) + + def currentVersion = 1 + + def oldVersions: List[Old] = List( + // old version 0 is just an example, so the list is never empty :) + // nobody ever used version 0. + Old( + version = 0, + deprecatedAt = new DateTime("2014-08-01"), + unsupportedAt = new DateTime("2014-12-01")) + ) +}