report current app version in api/status

This commit is contained in:
Thibault Duplessis 2015-01-24 11:36:05 +01:00
parent 75dfb1bcd7
commit c1d6bceb3a
10 changed files with 63 additions and 50 deletions

View file

@ -70,7 +70,7 @@ object Analyse extends LilaController {
else fuccess(GameResults(None, None))
assessResults flatMap {
results =>
Env.api.roundApi.watcher(pov, lila.api.MobileApi.currentVersion, tv = none, analysis.map(pgn -> _), initialFen = initialFen.some) map { data => {
Env.api.roundApi.watcher(pov, lila.api.Mobile.Api.currentVersion, tv = none, analysis.map(pgn -> _), initialFen = initialFen.some) map { data => {
Ok(html.analyse.replay(
pov,
data,

View file

@ -11,15 +11,20 @@ object Api extends LilaController {
private val gameApi = Env.api.gameApi
def status = Action { req =>
val api = lila.api.MobileApi
val api = lila.api.Mobile.Api
val app = lila.api.Mobile.App
Ok(Json.obj(
"current" -> api.currentVersion,
"olds" -> api.oldVersions.map { old =>
Json.obj(
"version" -> old.version,
"deprecatedAt" -> old.deprecatedAt,
"unsupportedAt" -> old.unsupportedAt)
}
"api" -> Json.obj(
"current" -> api.currentVersion,
"olds" -> api.oldVersions.map { old =>
Json.obj(
"version" -> old.version,
"deprecatedAt" -> old.deprecatedAt,
"unsupportedAt" -> old.unsupportedAt)
}),
"app" -> Json.obj(
"current" -> app.currentVersion
)
)) as JSON
}

View file

@ -18,7 +18,7 @@ object Auth extends LilaController {
implicit val req = ctx.req
u.ipBan.fold(
Env.security.firewall.blockIp(req.remoteAddress) inject BadRequest("blocked by firewall"),
api.saveAuthentication(u.id, lila.api.MobileApi.requestApiVersion(ctx.req)) flatMap { sessionId =>
api.saveAuthentication(u.id, lila.api.Mobile.Api.requestVersion(ctx.req)) flatMap { sessionId =>
negotiate(
html = Redirect {
get("referrer").filter(_.nonEmpty) orElse req.session.get(api.AccessUri) getOrElse routes.Lobby.home.url
@ -81,7 +81,7 @@ object Auth extends LilaController {
data => Firewall {
UserRepo.create(data.username, data.password, ctx.blindMode) flatMap { userOption =>
val user = userOption err "No user could be created for %s".format(data.username)
api.saveAuthentication(user.id, lila.api.MobileApi.requestApiVersion(ctx.req)) map { sessionId =>
api.saveAuthentication(user.id, lila.api.Mobile.Api.requestVersion(ctx.req)) map { sessionId =>
Redirect(routes.User.show(user.username)) withCookies LilaCookie.session("sessionId", sessionId)
}
}

View file

@ -202,7 +202,7 @@ private[controllers] trait LilaController
Forbidden("no permission")
protected def negotiate(html: => Fu[Result], api: Int => Fu[Result])(implicit ctx: Context): Fu[Result] =
(lila.api.MobileApi.requestApiVersion(ctx.req) match {
(lila.api.Mobile.Api.requestVersion(ctx.req) match {
case Some(1) => api(1) map (_ as JSON)
case _ => html
}) map (_.withHeaders("Vary" -> "Accept"))

View file

@ -64,7 +64,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, lila.api.MobileApi.currentVersion, playing) map { data =>
Env.api.roundApi.player(pov, lila.api.Mobile.Api.currentVersion, playing) map { data =>
Ok(html.round.player(pov, data, tour = tour, cross = crosstable, playing = playing))
}
}
@ -123,7 +123,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, lila.api.MobileApi.currentVersion, tv = none) map {
Env.api.roundApi.watcher(pov, lila.api.Mobile.Api.currentVersion, tv = none) map {
case ((tour, crosstable), data) =>
Ok(html.round.watcher(pov, data, tour, crosstable, userTv = userTv))
}
@ -133,7 +133,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, lila.api.MobileApi.currentVersion, otherPovs = Nil) zip
Env.api.roundApi.player(pov, lila.api.Mobile.Api.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))

View file

@ -149,7 +149,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, lila.api.MobileApi.currentVersion, otherPovs = Nil) zip
Env.api.roundApi.player(pov, lila.api.Mobile.Api.currentVersion, otherPovs = Nil) zip
(userId ?? UserRepo.named) flatMap {
case (data, user) => PreventTheft(pov) {
Ok(html.setup.await(

View file

@ -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, lila.api.MobileApi.currentVersion, tv = flip.some) zip
Env.api.roundApi.watcher(pov, lila.api.Mobile.Api.currentVersion, tv = flip.some) zip
(GameRepo onTv 10) zip
Env.game.crosstableApi(game) zip
Env.tv.streamsOnAir zip

View file

@ -51,7 +51,7 @@ object Environment
def isProd = apiEnv.isProd
def apiVersion = lila.api.MobileApi.currentVersion
def apiVersion = lila.api.Mobile.Api.currentVersion
lazy val siteMenu = new lila.app.ui.SiteMenu(trans)

View file

@ -0,0 +1,40 @@
package lila.api
import org.joda.time.DateTime
import play.api.http.HeaderNames
import play.api.mvc.RequestHeader
object Mobile {
object Api {
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"))
)
def requestVersion(req: RequestHeader): Option[Int] = {
val accepts = ~req.headers.get(HeaderNames.ACCEPT)
if (accepts contains "application/vnd.lichess.v1+json") some(1)
else none
}
}
object App {
def currentVersion = "1.0.0"
}
}

View file

@ -1,32 +0,0 @@
package lila.api
import org.joda.time.DateTime
import play.api.http.HeaderNames
import play.api.mvc.RequestHeader
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"))
)
def requestApiVersion(req: RequestHeader): Option[Int] = {
val accepts = ~req.headers.get(HeaderNames.ACCEPT)
if (accepts contains "application/vnd.lichess.v1+json") some(1)
else none
}
}