2019-04-15 04:07:12 -06:00
|
|
|
package lila.app
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import play.api.mvc.RequestHeader
|
2019-12-07 13:45:01 -07:00
|
|
|
import play.api.i18n.Lang
|
2019-04-15 04:07:12 -06:00
|
|
|
|
2019-12-07 13:45:01 -07:00
|
|
|
import lila.common.Nonce
|
2019-04-15 04:07:12 -06:00
|
|
|
|
2021-07-03 01:05:36 -06:00
|
|
|
case class EmbedConfig(
|
|
|
|
bg: String,
|
|
|
|
board: String,
|
|
|
|
pieceSet: lila.pref.PieceSet,
|
|
|
|
lang: Lang,
|
|
|
|
req: RequestHeader,
|
|
|
|
nonce: Nonce
|
|
|
|
)
|
2019-04-15 04:07:12 -06:00
|
|
|
|
|
|
|
object EmbedConfig {
|
|
|
|
|
|
|
|
object implicits {
|
2019-12-13 07:30:20 -07:00
|
|
|
implicit def configLang(implicit config: EmbedConfig): Lang = config.lang
|
2019-04-15 04:07:12 -06:00
|
|
|
implicit def configReq(implicit config: EmbedConfig): RequestHeader = config.req
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:11:15 -06:00
|
|
|
def apply(req: RequestHeader): EmbedConfig =
|
|
|
|
EmbedConfig(
|
|
|
|
bg = get("bg", req).filterNot("auto".==) | "light",
|
|
|
|
board = lila.pref.Theme(~get("theme", req)).cssClass,
|
2021-06-30 08:02:39 -06:00
|
|
|
pieceSet = lila.pref.PieceSet(~get("pieceSet", req)),
|
2020-05-05 22:11:15 -06:00
|
|
|
lang = lila.i18n.I18nLangPicker(req, none),
|
|
|
|
req = req,
|
|
|
|
nonce = Nonce.random
|
|
|
|
)
|
2019-04-15 04:07:12 -06:00
|
|
|
|
|
|
|
private def get(name: String, req: RequestHeader): Option[String] =
|
|
|
|
req.queryString get name flatMap (_.headOption) filter (_.nonEmpty)
|
|
|
|
}
|