80 lines
2.4 KiB
Scala
80 lines
2.4 KiB
Scala
package controllers
|
|
|
|
import play.api.mvc._
|
|
import scala.collection.breakOut
|
|
|
|
import lila.api.Context
|
|
import lila.app._
|
|
import lila.pref.JsonView._
|
|
import play.api.libs.json._
|
|
|
|
object Dasher extends LilaController {
|
|
|
|
private def translations(implicit ctx: Context) = Env.i18n.jsDump.keysToObject(List(
|
|
Env.i18n.keys.profile,
|
|
Env.i18n.keys.inbox,
|
|
Env.i18n.keys.preferences,
|
|
Env.i18n.keys.logOut,
|
|
Env.i18n.keys.networkLagBetweenYouAndLichess,
|
|
Env.i18n.keys.timeToProcessAMoveOnLichessServer,
|
|
Env.i18n.keys.sound
|
|
), Env.i18n.pool lang ctx.req)
|
|
|
|
def get = Open { implicit ctx =>
|
|
negotiate(
|
|
html = notFound,
|
|
api = _ => ctx.me match {
|
|
case None => fuccess(unauthorizedApiResult)
|
|
case Some(me) => Env.pref.api.getPref(me) map { prefs =>
|
|
Ok {
|
|
Json.obj(
|
|
"user" -> lila.common.LightUser.lightUserWrites.writes(me.light),
|
|
"lang" -> Json.obj(
|
|
"current" -> Env.i18n.pool.lang(ctx.req).language.toString,
|
|
"accepted" -> (ctx.req.acceptLanguages.map(_.language.toString)(breakOut): List[String]).distinct
|
|
),
|
|
"sound" -> Json.obj(
|
|
"list" -> lila.pref.SoundSet.list.map { set =>
|
|
s"${set.key} ${set.name}"
|
|
}
|
|
),
|
|
"background" -> Json.obj(
|
|
"current" -> ctx.currentBg,
|
|
"image" -> ctx.bgImg
|
|
),
|
|
"board" -> Json.obj(
|
|
"is3d" -> ctx.is3d,
|
|
"zoom" -> ctx.zoom
|
|
),
|
|
"theme" -> Json.obj(
|
|
"d2" -> Json.obj(
|
|
"current" -> ctx.currentTheme.name,
|
|
"list" -> lila.pref.Theme.list.map(_.name)
|
|
),
|
|
"d3" -> Json.obj(
|
|
"current" -> ctx.currentTheme3d.name,
|
|
"list" -> lila.pref.Theme3d.list.map(_.name)
|
|
)
|
|
),
|
|
"piece" -> Json.obj(
|
|
"d2" -> Json.obj(
|
|
"current" -> ctx.currentPieceSet.name,
|
|
"list" -> lila.pref.PieceSet.list.map(_.name)
|
|
),
|
|
"d3" -> Json.obj(
|
|
"current" -> ctx.currentPieceSet3d.name,
|
|
"list" -> lila.pref.PieceSet3d.list.map(_.name)
|
|
)
|
|
),
|
|
"kid" -> me.kid,
|
|
"coach" -> isGranted(_.Coach),
|
|
"prefs" -> prefs,
|
|
"i18n" -> translations
|
|
)
|
|
}
|
|
}
|
|
}
|
|
)
|
|
}
|
|
}
|