all modules compile - but not the app
parent
40e71ecc31
commit
bac44b3cb3
55
build.sbt
55
build.sbt
|
@ -1,7 +1,7 @@
|
|||
import com.typesafe.sbt.packager.Keys.scriptClasspath
|
||||
import com.typesafe.sbt.web.SbtWeb.autoImport._
|
||||
import play.twirl.sbt.Import._
|
||||
import play.sbt.PlayImport._
|
||||
import play.twirl.sbt.Import._
|
||||
import PlayKeys._
|
||||
|
||||
import BuildSettings._
|
||||
|
@ -76,8 +76,9 @@ lazy val moduleCPDeps = moduleRefs map { new sbt.ClasspathDependency(_, None) }
|
|||
lazy val api = module("api", moduleCPDeps)
|
||||
.settings(
|
||||
libraryDependencies ++= provided(
|
||||
play.api, hasher, typesafeConfig, findbugs,
|
||||
play.api, play.iteratee, play.jodaJson, hasher,
|
||||
reactivemongo.driver, reactivemongo.iteratees,
|
||||
typesafeConfig, findbugs,
|
||||
kamon.core, kamon.influxdb
|
||||
)
|
||||
) aggregate (moduleRefs: _*)
|
||||
|
@ -135,7 +136,7 @@ lazy val rating = module("rating", Seq(common, db)).settings(
|
|||
)
|
||||
|
||||
lazy val perfStat = module("perfStat", Seq(common, db, user, game, rating)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.jodaJson, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val history = module("history", Seq(common, db, memo, game, user)).settings(
|
||||
|
@ -159,7 +160,7 @@ lazy val chat = module("chat", Seq(common, db, user, security, i18n, socket)).se
|
|||
)
|
||||
|
||||
lazy val timeline = module("timeline", Seq(common, db, game, user, hub, security, relation)).settings(
|
||||
libraryDependencies ++= provided(play.api, play.test, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.jodaJson, play.test, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val event = module("event", Seq(common, db, memo)).settings(
|
||||
|
@ -168,7 +169,7 @@ lazy val event = module("event", Seq(common, db, memo)).settings(
|
|||
|
||||
lazy val mod = module("mod", Seq(common, db, user, hub, security, tournament, simul, game, analyse, evaluation,
|
||||
report, notifyModule, history)).settings(
|
||||
libraryDependencies ++= provided(play.api, play.test, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.jodaJson, play.test, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val user = module("user", Seq(common, memo, db, hub, rating)).settings(
|
||||
|
@ -181,7 +182,7 @@ lazy val game = module("game", Seq(common, memo, db, hub, user, chat)).settings(
|
|||
|
||||
lazy val gameSearch = module("gameSearch", Seq(common, hub, search, game)).settings(
|
||||
libraryDependencies ++= provided(
|
||||
play.api, reactivemongo.driver, reactivemongo.iteratees
|
||||
play.api, play.iteratee, play.jodaJson, reactivemongo.driver, reactivemongo.iteratees
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -190,14 +191,14 @@ lazy val tv = module("tv", Seq(common, db, hub, socket, game, user)).settings(
|
|||
)
|
||||
|
||||
lazy val analyse = module("analyse", Seq(common, hub, game, user, notifyModule, evalCache)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.iteratee, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val round = module("round", Seq(
|
||||
common, db, memo, hub, socket, game, user,
|
||||
i18n, fishnet, pref, chat, history, playban
|
||||
)).settings(
|
||||
libraryDependencies ++= provided(play.api, hasher, kamon.core,
|
||||
libraryDependencies ++= provided(play.api, play.iteratee, play.jodaJson, hasher, kamon.core,
|
||||
reactivemongo.driver, reactivemongo.iteratees)
|
||||
)
|
||||
|
||||
|
@ -213,7 +214,7 @@ lazy val lobby = module("lobby", Seq(
|
|||
common, db, memo, hub, socket, game, user,
|
||||
round, timeline, relation, playban, security, pool
|
||||
)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.iteratee, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val setup = module("setup", Seq(
|
||||
|
@ -231,7 +232,7 @@ lazy val insight = module(
|
|||
Seq(common, game, user, analyse, relation, pref, socket, round, security)
|
||||
).settings(
|
||||
libraryDependencies ++= provided(
|
||||
play.api, reactivemongo.driver, reactivemongo.iteratees
|
||||
play.api, play.iteratee, reactivemongo.driver, reactivemongo.iteratees
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -239,14 +240,14 @@ lazy val tournament = module("tournament", Seq(
|
|||
common, hub, socket, game, round, security, chat, memo, quote, history, notifyModule, i18n
|
||||
)).settings(
|
||||
libraryDependencies ++= provided(
|
||||
play.api, reactivemongo.driver, reactivemongo.iteratees
|
||||
play.api, play.iteratee, play.jodaJson, reactivemongo.driver, reactivemongo.iteratees
|
||||
)
|
||||
)
|
||||
|
||||
lazy val simul = module("simul", Seq(
|
||||
common, hub, socket, game, round, chat, memo, quote
|
||||
)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.iteratee, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val fishnet = module("fishnet", Seq(common, game, analyse, db)).settings(
|
||||
|
@ -254,7 +255,7 @@ lazy val fishnet = module("fishnet", Seq(common, game, analyse, db)).settings(
|
|||
)
|
||||
|
||||
lazy val irwin = module("irwin", Seq(common, db, user, game, tournament, mod)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.iteratee, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val security = module("security", Seq(common, hub, db, user, i18n)).settings(
|
||||
|
@ -266,24 +267,23 @@ lazy val shutup = module("shutup", Seq(common, db, hub, game, relation)).setting
|
|||
)
|
||||
|
||||
lazy val challenge = module("challenge", Seq(common, db, hub, setup, game, relation, pref)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.iteratee, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val study = module("study", Seq(
|
||||
common, db, hub, socket, game, round, importer, notifyModule, relation, evalCache
|
||||
)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.iteratee, play.jodaJson, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val studySearch = module("studySearch", Seq(common, hub, study, search)).settings(
|
||||
libraryDependencies ++= provided(
|
||||
play.api,
|
||||
reactivemongo.driver, reactivemongo.iteratees
|
||||
play.api, play.iteratee, reactivemongo.driver, reactivemongo.iteratees
|
||||
)
|
||||
)
|
||||
|
||||
lazy val learn = module("learn", Seq(common, db, user)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.jodaJson, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val evalCache = module("evalCache", Seq(common, db, user, security, socket, tree)).settings(
|
||||
|
@ -319,7 +319,7 @@ lazy val pref = module("pref", Seq(common, db, user)).settings(
|
|||
)
|
||||
|
||||
lazy val message = module("message", Seq(common, db, user, hub, relation, security, notifyModule)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.jodaJson, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val forum = module("forum", Seq(common, db, user, security, hub, mod, notifyModule)).settings(
|
||||
|
@ -328,8 +328,7 @@ lazy val forum = module("forum", Seq(common, db, user, security, hub, mod, notif
|
|||
|
||||
lazy val forumSearch = module("forumSearch", Seq(common, hub, forum, search)).settings(
|
||||
libraryDependencies ++= provided(
|
||||
play.api,
|
||||
reactivemongo.driver, reactivemongo.iteratees
|
||||
play.api, play.iteratee, play.jodaJson, reactivemongo.driver, reactivemongo.iteratees
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -339,8 +338,7 @@ lazy val team = module("team", Seq(common, memo, db, user, forum, security, hub,
|
|||
|
||||
lazy val teamSearch = module("teamSearch", Seq(common, hub, team, search)).settings(
|
||||
libraryDependencies ++= provided(
|
||||
play.api,
|
||||
reactivemongo.driver, reactivemongo.iteratees
|
||||
play.api, play.iteratee, reactivemongo.driver, reactivemongo.iteratees
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -363,24 +361,21 @@ lazy val bookmark = module("bookmark", Seq(common, memo, db, hub, user, game)).s
|
|||
)
|
||||
|
||||
lazy val report = module("report", Seq(common, db, user, game, security)).settings(
|
||||
libraryDependencies ++= provided(
|
||||
play.api, reactivemongo.driver
|
||||
)
|
||||
libraryDependencies ++= provided(play.api, play.jodaJson, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val explorer = module("explorer", Seq(common, db, game)).settings(
|
||||
libraryDependencies ++= provided(
|
||||
play.api,
|
||||
reactivemongo.driver, reactivemongo.iteratees
|
||||
play.api, play.iteratee, reactivemongo.driver, reactivemongo.iteratees
|
||||
)
|
||||
)
|
||||
|
||||
lazy val notifyModule = module("notify", Seq(common, db, game, user, hub, relation)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
libraryDependencies ++= provided(play.api, play.jodaJson, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val site = module("site", Seq(common, socket)).settings(
|
||||
libraryDependencies ++= provided(play.api)
|
||||
libraryDependencies ++= provided(play.api, play.iteratee)
|
||||
)
|
||||
|
||||
lazy val tree = module("tree", Seq(common)).settings(
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila.api
|
|||
|
||||
import org.joda.time.DateTime
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
import reactivemongo.api.ReadPreference
|
||||
import reactivemongo.bson._
|
||||
import scala.concurrent.duration._
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package lila.api
|
||||
|
||||
import akka.actor._
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
|
||||
import lila.hub.actorApi.{ DeployPre, DeployPost }
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lila.api
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
|
||||
import chess.format.Forsyth
|
||||
import lila.common.LightUser
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila.blog
|
|||
|
||||
import io.prismic._
|
||||
import scala.concurrent.duration._
|
||||
import play.api.libs.ws.StandaloneWSClient
|
||||
|
||||
final class BlogApi(
|
||||
asyncCache: lila.memo.AsyncCache.Builder,
|
||||
|
@ -9,15 +10,22 @@ final class BlogApi(
|
|||
collection: String
|
||||
) {
|
||||
|
||||
implicit val httpClient: StandaloneWSClient = new StandaloneWSClient {
|
||||
import old.play.api.libs.ws.WS
|
||||
def underlying[T] = WS.asInstanceOf[T]
|
||||
def url(url: String) = WS.url(url)
|
||||
def close() = {}
|
||||
}
|
||||
|
||||
def recent(api: Api, ref: Option[String], nb: Int): Fu[Option[Response]] =
|
||||
api.forms(collection).ref(resolveRef(api)(ref) | api.master.ref)
|
||||
.orderings(s"[my.$collection.date desc]")
|
||||
.pageSize(nb).page(1).submit().fold(_ => none, some _)
|
||||
.pageSize(nb).page(1).submit.fold(_ => none, some _)
|
||||
|
||||
def one(api: Api, ref: Option[String], id: String) =
|
||||
api.forms(collection)
|
||||
.query(s"""[[:d = at(document.id, "$id")]]""")
|
||||
.ref(resolveRef(api)(ref) | api.master.ref).submit() map (_.results.headOption)
|
||||
.ref(resolveRef(api)(ref) | api.master.ref).submit map (_.results.headOption)
|
||||
|
||||
// -- Build a Prismic context
|
||||
def context(refName: Option[String])(implicit linkResolver: (Api, Option[String]) => DocumentLinkResolver) =
|
||||
|
|
|
@ -12,7 +12,7 @@ private[blog] final class Notifier(
|
|||
|
||||
def apply(prismicId: String): Funit =
|
||||
blogApi.prismicApi flatMap { prismicApi =>
|
||||
blogApi.one(prismicApi, none, prismicId) flatten
|
||||
blogApi.one(prismicApi, none, prismicId) err
|
||||
s"No such document: $prismicId" flatMap doSend
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,23 @@ final class JsonView(
|
|||
"socketVersion" -> socketVersion
|
||||
)
|
||||
|
||||
private def iconChar(c: Challenge) =
|
||||
if (c.variant == chess.variant.FromPosition) '*'
|
||||
else c.perfType.iconChar
|
||||
|
||||
private implicit val RegisteredWrites = OWrites[Registered] { r =>
|
||||
val light = getLightUser(r.id)
|
||||
Json.obj(
|
||||
"id" -> r.id,
|
||||
"name" -> light.fold(r.id)(_.name),
|
||||
"title" -> light.map(_.title),
|
||||
"rating" -> r.rating.int
|
||||
).add("provisional" -> r.rating.provisional)
|
||||
.add("patron" -> light.??(_.isPatron))
|
||||
.add("online" -> isOnline(r.id))
|
||||
.add("lag" -> UserLagCache.getLagRating(r.id))
|
||||
}
|
||||
|
||||
private def apply(direction: Option[Direction])(c: Challenge): JsObject = Json.obj(
|
||||
"id" -> c.id,
|
||||
"direction" -> direction.map(_.name),
|
||||
|
@ -58,23 +75,6 @@ final class JsonView(
|
|||
)
|
||||
)
|
||||
|
||||
private def iconChar(c: Challenge) =
|
||||
if (c.variant == chess.variant.FromPosition) '*'
|
||||
else c.perfType.iconChar
|
||||
|
||||
private implicit val RegisteredWrites = OWrites[Registered] { r =>
|
||||
val light = getLightUser(r.id)
|
||||
Json.obj(
|
||||
"id" -> r.id,
|
||||
"name" -> light.fold(r.id)(_.name),
|
||||
"title" -> light.map(_.title),
|
||||
"rating" -> r.rating.int
|
||||
).add("provisional" -> r.rating.provisional)
|
||||
.add("patron" -> light.??(_.isPatron))
|
||||
.add("online" -> isOnline(r.id))
|
||||
.add("lag" -> UserLagCache.getLagRating(r.id))
|
||||
}
|
||||
|
||||
private def translations(lang: Lang) = lila.i18n.JsDump.keysToObject(List(
|
||||
trans.rated,
|
||||
trans.casual,
|
||||
|
|
|
@ -47,6 +47,6 @@ object CoachProfileForm {
|
|||
|
||||
import CoachProfile.RichText
|
||||
|
||||
private def richText = of[RichText]
|
||||
private implicit val richTextFormat = lila.common.Form.formatter.stringFormatter[RichText](_.value, RichText.apply)
|
||||
private def richText = of[RichText]
|
||||
}
|
||||
|
|
|
@ -12,17 +12,17 @@ private final class Photographer(coll: Coll) {
|
|||
private def pictureId(id: Coach.Id) = s"coach:${id.value}:picture"
|
||||
|
||||
def apply(coachId: Coach.Id, uploaded: Photographer.Uploaded): Fu[DbImage] =
|
||||
if (uploaded.ref.file.length > uploadMaxBytes)
|
||||
if (uploaded.ref.path.toFile.length > uploadMaxBytes)
|
||||
fufail(s"File size must not exceed ${uploadMaxMb}MB.")
|
||||
else {
|
||||
|
||||
process(uploaded.ref.file)
|
||||
process(uploaded.ref.path.toFile)
|
||||
|
||||
val image = DbImage.make(
|
||||
id = pictureId(coachId),
|
||||
name = sanitizeName(uploaded.filename),
|
||||
contentType = uploaded.contentType,
|
||||
file = uploaded.ref.file
|
||||
file = uploaded.ref.path.toFile
|
||||
)
|
||||
|
||||
coll.update($id(image.id), image, upsert = true) inject image
|
||||
|
|
|
@ -3,7 +3,6 @@ package lila.common
|
|||
import play.api.i18n.Lang
|
||||
import play.api.libs.json._
|
||||
import old.play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
|
||||
// http://detectlanguage.com
|
||||
final class DetectLanguage(url: String, key: String) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import play.api.inject.guice.GuiceApplicationBuilder
|
|||
import play.api.inject.Injector
|
||||
import play.api.libs.ws.WSClient
|
||||
import play.api.Mode
|
||||
import play.api.mvc.{ SessionCookieBaker, ActionBuilder, DefaultActionBuilder }
|
||||
|
||||
import scala.concurrent.ExecutionContext
|
||||
|
||||
|
@ -30,9 +31,11 @@ object Env {
|
|||
lazy val mode: Mode = application.mode
|
||||
lazy val scheduler: Scheduler = actorSystem.scheduler
|
||||
lazy val injector: Injector = application.injector
|
||||
lazy val defaultContext: ExecutionContext = injector.instanceOf(classOf[ExecutionContext])
|
||||
lazy val environment: Environment = injector.instanceOf(classOf[Environment])
|
||||
lazy val WS: WSClient = injector.instanceOf(classOf[WSClient])
|
||||
lazy val defaultContext: ExecutionContext = injector.instanceOf[ExecutionContext]
|
||||
lazy val environment: Environment = injector.instanceOf[Environment]
|
||||
lazy val WS: WSClient = injector.instanceOf[WSClient]
|
||||
lazy val cookieBaker: SessionCookieBaker = injector.instanceOf[SessionCookieBaker]
|
||||
lazy val actionBuilder: DefaultActionBuilder = injector.instanceOf[DefaultActionBuilder]
|
||||
// lazy val cache: CacheApi = injector.instanceOf(classOf[CacheApi])
|
||||
// lazy val procNbr = Runtime.getRuntime.availableProcessors()
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.regex.Matcher.quoteReplacement
|
|||
|
||||
import ornicar.scalalib.Random
|
||||
import play.api.mvc.{ Cookie, Session, RequestHeader }
|
||||
import old.play.Env.cookieBaker
|
||||
|
||||
object LilaCookie {
|
||||
|
||||
|
@ -23,17 +24,17 @@ object LilaCookie {
|
|||
def newSession(implicit req: RequestHeader): Cookie = withSession(identity)
|
||||
|
||||
def withSession(op: Session => Session)(implicit req: RequestHeader): Cookie = cookie(
|
||||
Session.COOKIE_NAME,
|
||||
Session.encode(Session.serialize(op(req.session)))
|
||||
cookieBaker.COOKIE_NAME,
|
||||
Session.encode(cookieBaker.serialize(op(req.session)))
|
||||
)
|
||||
|
||||
def cookie(name: String, value: String, maxAge: Option[Int] = None, httpOnly: Option[Boolean] = None)(implicit req: RequestHeader): Cookie = Cookie(
|
||||
name,
|
||||
value,
|
||||
maxAge orElse Session.maxAge orElse 86400.some,
|
||||
maxAge orElse cookieBaker.maxAge orElse 86400.some,
|
||||
"/",
|
||||
domain(req).some,
|
||||
Session.secure || req.headers.get("X-Forwarded-Proto").contains("https"),
|
||||
httpOnly | Session.httpOnly
|
||||
cookieBaker.secure || req.headers.get("X-Forwarded-Proto").contains("https"),
|
||||
httpOnly | cookieBaker.httpOnly
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package lila
|
||||
|
||||
import play.api.libs.concurrent.Execution.Implicits._
|
||||
import old.play.api.libs.concurrent.Execution.Implicits._
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.{ Future, ExecutionContext }
|
||||
|
||||
|
@ -50,8 +50,9 @@ object PimpedFuture {
|
|||
def logFailure(logger: => lila.log.Logger): Fu[A] = logFailure(logger, _.toString)
|
||||
|
||||
def addFailureEffect(effect: Exception => Unit) = {
|
||||
fua onFailure {
|
||||
case e: Exception => effect(e)
|
||||
fua onComplete {
|
||||
case scala.util.Failure(e: Exception) => effect(e)
|
||||
case _ =>
|
||||
}
|
||||
fua
|
||||
}
|
||||
|
|
|
@ -24,8 +24,7 @@ final class Env(
|
|||
}
|
||||
|
||||
def fetchPgn(id: String): Fu[Option[String]] = {
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
WS.url(s"$InternalEndpoint/master/pgn/$id").get() map {
|
||||
case res if res.status == 200 => res.body.some
|
||||
case _ => None
|
||||
|
|
|
@ -6,8 +6,7 @@ import scala.util.{ Try, Success, Failure }
|
|||
import org.joda.time.DateTime
|
||||
import org.joda.time.format.DateTimeFormat
|
||||
import play.api.libs.iteratee._
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
|
||||
import lila.db.dsl._
|
||||
import lila.game.BSONHandlers.gameBSONHandler
|
||||
|
|
|
@ -163,7 +163,7 @@ final class FishnetApi(
|
|||
|
||||
private[fishnet] def setClientSkill(key: Client.Key, skill: String) =
|
||||
Client.Skill.byKey(skill).fold(fufail[Unit](s"Invalid skill $skill")) { sk =>
|
||||
repo getClient key flatten s"No client with key $key" flatMap { client =>
|
||||
repo getClient key err s"No client with key $key" flatMap { client =>
|
||||
repo updateClient client.copy(skill = sk)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ final class Env(
|
|||
val CollectionTopic = config getString "collection.topic"
|
||||
val CollectionPost = config getString "collection.post"
|
||||
import scala.collection.JavaConverters._
|
||||
val PublicCategIds = (config getStringList "public_categ_ids").toList
|
||||
val PublicCategIds = (config getStringList "public_categ_ids").asScala.toList
|
||||
}
|
||||
import settings._
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import lila.forum.{ Post, PostView, PostLiteView, PostApi, PostRepo }
|
|||
import lila.search._
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
|
||||
final class ForumSearchApi(
|
||||
client: ESClient,
|
||||
|
|
|
@ -35,9 +35,7 @@ private final class Captcher extends Actor {
|
|||
|
||||
def current = challenges.head
|
||||
|
||||
def refresh = createFromDb onSuccess {
|
||||
case Some(captcha) => add(captcha)
|
||||
}
|
||||
def refresh = createFromDb foreach { _ ?? add }
|
||||
|
||||
// Private stuff
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ final class Env(
|
|||
system: ActorSystem,
|
||||
hub: lila.hub.Env,
|
||||
getLightUser: lila.common.LightUser.GetterSync,
|
||||
appPath: String,
|
||||
isProd: Boolean,
|
||||
asyncCache: lila.memo.AsyncCache.Builder,
|
||||
scheduler: lila.common.Scheduler
|
||||
|
@ -105,7 +104,6 @@ object Env {
|
|||
system = old.play.Env.actorSystem,
|
||||
hub = lila.hub.Env.current,
|
||||
getLightUser = lila.user.Env.current.lightUserSync,
|
||||
appPath = play.api.Play.current.path.getCanonicalPath,
|
||||
isProd = lila.common.PlayApp.isProd,
|
||||
asyncCache = lila.memo.Env.current.asyncCache,
|
||||
scheduler = lila.common.PlayApp.scheduler
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package lila.game
|
||||
|
||||
import play.api.libs.iteratee._
|
||||
import akka.stream.scaladsl.{ Source => StreamSource }
|
||||
import akka.util.ByteString
|
||||
import old.play.api.libs.ws.WS
|
||||
|
||||
import chess.format.{ Forsyth, FEN }
|
||||
|
||||
final class PngExport(url: String, size: Int) {
|
||||
|
||||
def fromGame(game: Game): Fu[Enumerator[Array[Byte]]] = apply(
|
||||
def fromGame(game: Game): Fu[StreamSource[ByteString, _]] = apply(
|
||||
fen = FEN(Forsyth >> game.toChess),
|
||||
lastMove = game.castleLastMoveTime.lastMoveString,
|
||||
check = game.toChess.situation.checkSquare,
|
||||
|
@ -21,7 +22,7 @@ final class PngExport(url: String, size: Int) {
|
|||
check: Option[chess.Pos],
|
||||
orientation: Option[chess.Color],
|
||||
logHint: => String
|
||||
): Fu[Enumerator[Array[Byte]]] = {
|
||||
): Fu[StreamSource[ByteString, _]] = {
|
||||
|
||||
val queryString = List(
|
||||
"fen" -> fen.value.takeWhile(' ' !=),
|
||||
|
@ -32,11 +33,11 @@ final class PngExport(url: String, size: Int) {
|
|||
orientation.map { "orientation" -> _.name }
|
||||
).flatten
|
||||
|
||||
WS.url(url).withQueryString(queryString: _*).withMethod("GET").stream() flatMap {
|
||||
case (res, body) if res.status != 200 =>
|
||||
WS.url(url).addQueryStringParameters(queryString: _*).stream() flatMap {
|
||||
case (res) if res.status != 200 =>
|
||||
logger.warn(s"PgnExport $logHint ${fen.value} ${res.status}")
|
||||
fufail(res.status.toString)
|
||||
case (_, body) => fuccess(body)
|
||||
case res => fuccess(res.bodyAsSource)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ object Query {
|
|||
|
||||
import lila.common.Form._
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
|
||||
import Range.rangeJsonWriter
|
||||
private implicit val sortingJsonWriter = Json.writes[Sorting]
|
||||
|
|
|
@ -5,12 +5,13 @@ import play.api.mvc._
|
|||
import play.api.mvc.Results.MovedPermanently
|
||||
|
||||
import lila.common.HTTPRequest
|
||||
import old.play.Env.actionBuilder
|
||||
|
||||
final class SubdomainKiller(domain: String) {
|
||||
|
||||
def apply(req: RequestHeader): Option[Handler] =
|
||||
if (appliesTo(req) && !allowMobileEn(req))
|
||||
Some(Action(MovedPermanently {
|
||||
Some(actionBuilder(MovedPermanently {
|
||||
val protocol = s"http${if (req.secure) "s" else ""}"
|
||||
s"$protocol://$domain${req.uri}"
|
||||
}))
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila.learn
|
|||
|
||||
import lila.common.PimpedJson._
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
|
||||
object JSONHandlers {
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ private[lobby] object Biter {
|
|||
}
|
||||
|
||||
private def join(seek: Seek, lobbyUser: LobbyUser): Fu[JoinSeek] = for {
|
||||
user ← UserRepo byId lobbyUser.id flatten s"No such user: ${lobbyUser.id}"
|
||||
owner ← UserRepo byId seek.user.id flatten s"No such user: ${seek.user.id}"
|
||||
user ← UserRepo byId lobbyUser.id err s"No such user: ${lobbyUser.id}"
|
||||
owner ← UserRepo byId seek.user.id err s"No such user: ${seek.user.id}"
|
||||
creatorColor <- assignCreatorColor(owner.some, user.some, seek.realColor)
|
||||
game = blame(
|
||||
!creatorColor, user.some,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lila.message
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
import play.api.mvc.Result
|
||||
import play.api.mvc.Results._
|
||||
|
||||
|
|
|
@ -201,6 +201,6 @@ final class AssessApi(
|
|||
}
|
||||
|
||||
private def withUser[A](username: String)(op: User => Fu[A]): Fu[A] =
|
||||
UserRepo named username flatten "[mod] missing user " + username flatMap op
|
||||
UserRepo named username err s"[mod] missing user $username" flatMap op
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@ final class Gamify(
|
|||
|
||||
import Gamify._
|
||||
|
||||
private implicit val modMixedBSONHandler = Macros.handler[ModMixed]
|
||||
private implicit val historyMonthBSONHandler = Macros.handler[HistoryMonth]
|
||||
|
||||
def history(orCompute: Boolean = true): Fu[List[HistoryMonth]] = {
|
||||
val until = DateTime.now minusMonths 1 withDayOfMonth 1
|
||||
val lastId = HistoryMonth.makeId(until.getYear, until.getMonthOfYear)
|
||||
|
@ -33,9 +36,6 @@ final class Gamify(
|
|||
}
|
||||
}
|
||||
|
||||
private implicit val modMixedBSONHandler = Macros.handler[ModMixed]
|
||||
private implicit val historyMonthBSONHandler = Macros.handler[HistoryMonth]
|
||||
|
||||
private def buildHistoryAfter(afterYear: Int, afterMonth: Int, until: DateTime): Funit =
|
||||
(afterYear to until.getYear).flatMap { year =>
|
||||
((year == afterYear).fold(afterMonth + 1, 1) to
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lila.mod
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
|
||||
import chess.format.FEN
|
||||
import lila.common.PimpedJson._
|
||||
|
@ -15,30 +16,6 @@ final class JsonView(
|
|||
userJson: lila.user.JsonView
|
||||
) {
|
||||
|
||||
def apply(user: User): Fu[Option[JsObject]] =
|
||||
assessApi.getPlayerAggregateAssessmentWithGames(user.id) flatMap {
|
||||
_ ?? {
|
||||
case PlayerAggregateAssessment.WithGames(pag, games) => for {
|
||||
gamesWithFen <- GameRepo withInitialFens games.filter(_.clockHistory.isDefined)
|
||||
moreGames <- GameRepo.extraGamesForIrwin(user.id, 25) map {
|
||||
_.filter { g => !games.exists(_.id == g.id) } take 20
|
||||
}
|
||||
moreGamesWithFen <- GameRepo withInitialFens moreGames
|
||||
allGamesWithFen = gamesWithFen ::: moreGamesWithFen
|
||||
} yield Json.obj(
|
||||
"user" -> userJson(user),
|
||||
"assessment" -> pag,
|
||||
"games" -> JsObject(allGamesWithFen.map { g =>
|
||||
g._1.id -> {
|
||||
gameWithFenWrites.writes(g) ++ Json.obj(
|
||||
"color" -> g._1.player(user).map(_.color.name)
|
||||
)
|
||||
}
|
||||
})
|
||||
).some
|
||||
}
|
||||
}
|
||||
|
||||
import lila.user.JsonView.modWrites
|
||||
|
||||
private implicit val playerFlagsWrites = OWrites[PlayerFlags] { f =>
|
||||
|
@ -70,6 +47,30 @@ final class JsonView(
|
|||
)
|
||||
).noNull
|
||||
}
|
||||
|
||||
def apply(user: User): Fu[Option[JsObject]] =
|
||||
assessApi.getPlayerAggregateAssessmentWithGames(user.id) flatMap {
|
||||
_ ?? {
|
||||
case PlayerAggregateAssessment.WithGames(pag, games) => for {
|
||||
gamesWithFen <- GameRepo withInitialFens games.filter(_.clockHistory.isDefined)
|
||||
moreGames <- GameRepo.extraGamesForIrwin(user.id, 25) map {
|
||||
_.filter { g => !games.exists(_.id == g.id) } take 20
|
||||
}
|
||||
moreGamesWithFen <- GameRepo withInitialFens moreGames
|
||||
allGamesWithFen = gamesWithFen ::: moreGamesWithFen
|
||||
} yield Json.obj(
|
||||
"user" -> userJson(user),
|
||||
"assessment" -> pag,
|
||||
"games" -> JsObject(allGamesWithFen.map { g =>
|
||||
g._1.id -> {
|
||||
gameWithFenWrites.writes(g) ++ Json.obj(
|
||||
"color" -> g._1.player(user).map(_.color.name)
|
||||
)
|
||||
}
|
||||
})
|
||||
).some
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object JsonView {
|
||||
|
|
|
@ -135,6 +135,6 @@ final class ModApi(
|
|||
}
|
||||
|
||||
private def withUser[A](username: String)(op: User => Fu[A]): Fu[A] =
|
||||
UserRepo named username flatten "[mod] missing user " + username flatMap op
|
||||
UserRepo named username err "[mod] missing user $username" flatMap op
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila.notify
|
|||
|
||||
import lila.common.LightUser
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
|
||||
final class JSONHandlers(getLightUser: LightUser.GetterSync) {
|
||||
|
||||
|
|
|
@ -7,28 +7,12 @@ import lila.user.User
|
|||
import org.joda.time.DateTime
|
||||
import org.joda.time.format.ISODateTimeFormat
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
|
||||
final class JsonView(getLightUser: LightUser.GetterSync) {
|
||||
|
||||
import JsonView._
|
||||
|
||||
def apply(
|
||||
user: User,
|
||||
stat: PerfStat,
|
||||
rank: Option[Int],
|
||||
ratingDistribution: Option[List[Int]]
|
||||
) = Json.obj(
|
||||
"user" -> user,
|
||||
"perf" -> user.perfs(stat.perfType),
|
||||
"rank" -> rank,
|
||||
"percentile" -> ratingDistribution.map { distrib =>
|
||||
lila.user.Stat.percentile(distrib, user.perfs(stat.perfType).intRating) match {
|
||||
case (under, sum) => Math.round(under * 1000.0 / sum) / 10.0
|
||||
}
|
||||
},
|
||||
"stat" -> stat.copy(playStreak = stat.playStreak.checkCurrent)
|
||||
)
|
||||
|
||||
private implicit val userIdWriter: OWrites[UserId] = OWrites { u =>
|
||||
val light = getLightUser(u.value)
|
||||
Json.obj(
|
||||
|
@ -47,6 +31,23 @@ final class JsonView(getLightUser: LightUser.GetterSync) {
|
|||
implicit val resultStreakWrites = Json.writes[ResultStreak]
|
||||
implicit val countWrites = Json.writes[Count]
|
||||
implicit val perfStatWrites = Json.writes[PerfStat]
|
||||
|
||||
def apply(
|
||||
user: User,
|
||||
stat: PerfStat,
|
||||
rank: Option[Int],
|
||||
ratingDistribution: Option[List[Int]]
|
||||
) = Json.obj(
|
||||
"user" -> user,
|
||||
"perf" -> user.perfs(stat.perfType),
|
||||
"rank" -> rank,
|
||||
"percentile" -> ratingDistribution.map { distrib =>
|
||||
lila.user.Stat.percentile(distrib, user.perfs(stat.perfType).intRating) match {
|
||||
case (under, sum) => Math.round(under * 1000.0 / sum) / 10.0
|
||||
}
|
||||
},
|
||||
"stat" -> stat.copy(playStreak = stat.playStreak.checkCurrent)
|
||||
)
|
||||
}
|
||||
|
||||
object JsonView {
|
||||
|
|
|
@ -72,7 +72,7 @@ final class PlanApi(
|
|||
funit
|
||||
case Some(patron) =>
|
||||
logger.info(s"Charged $charge $patron")
|
||||
UserRepo byId patron.userId flatten s"Missing user for $patron" flatMap { user =>
|
||||
UserRepo byId patron.userId err s"Missing user for $patron" flatMap { user =>
|
||||
val p2 = patron.copy(
|
||||
stripe = Patron.Stripe(stripeCharge.customer).some
|
||||
).levelUpIfPossible
|
||||
|
@ -148,7 +148,7 @@ final class PlanApi(
|
|||
logger.warn(s"Deleted subscription of unknown patron $sub")
|
||||
funit
|
||||
case Some(patron) =>
|
||||
UserRepo byId patron.userId flatten s"Missing user for $patron" flatMap { user =>
|
||||
UserRepo byId patron.userId err s"Missing user for $patron" flatMap { user =>
|
||||
setDbUserPlan(user, user.plan.disable) >>
|
||||
patronColl.update($id(user.id), patron.removeStripe).void >>
|
||||
notifier.onExpire(user) >>-
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package lila.plan
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.ws.{ WS, WSResponse }
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
import play.api.libs.ws.WSResponse
|
||||
|
||||
import lila.user.User
|
||||
|
||||
|
@ -120,7 +120,7 @@ private final class StripeClient(config: StripeClient.Config) {
|
|||
|
||||
private def get[A: Reads](url: String, queryString: Seq[(Symbol, Any)]): Fu[A] = {
|
||||
logger.info(s"GET $url ${debugInput(queryString)}")
|
||||
request(url).withQueryString(fixInput(queryString): _*).get() flatMap response[A]
|
||||
request(url).addQueryStringParameters(fixInput(queryString): _*).get() flatMap response[A]
|
||||
}
|
||||
|
||||
private def post[A: Reads](url: String, data: Seq[(Symbol, Any)]): Fu[A] = {
|
||||
|
@ -130,11 +130,11 @@ private final class StripeClient(config: StripeClient.Config) {
|
|||
|
||||
private def delete[A: Reads](url: String, data: Seq[(Symbol, Any)]): Fu[A] = {
|
||||
logger.info(s"DELETE $url ${debugInput(data)}")
|
||||
request(url).withQueryString(fixInput(data): _*).delete() flatMap response[A]
|
||||
request(url).addQueryStringParameters(fixInput(data): _*).delete() flatMap response[A]
|
||||
}
|
||||
|
||||
private def request(url: String) =
|
||||
WS.url(s"${config.endpoint}/$url").withHeaders("Authorization" -> s"Bearer ${config.secretKey}")
|
||||
WS.url(s"${config.endpoint}/$url").addHttpHeaders("Authorization" -> s"Bearer ${config.secretKey}")
|
||||
|
||||
private def response[A: Reads](res: WSResponse): Fu[A] = res.status match {
|
||||
case 200 => (implicitly[Reads[A]] reads res.json).fold(
|
||||
|
|
|
@ -13,14 +13,6 @@ final class PrefApi(
|
|||
asyncCache: lila.memo.AsyncCache.Builder,
|
||||
cacheTtl: FiniteDuration
|
||||
) {
|
||||
|
||||
private def fetchPref(id: String): Fu[Option[Pref]] = coll.find($id(id)).uno[Pref]
|
||||
private val cache = asyncCache.multi(
|
||||
name = "pref.fetchPref",
|
||||
f = fetchPref,
|
||||
expireAfter = _.ExpireAfterAccess(cacheTtl)
|
||||
)
|
||||
|
||||
private implicit val prefBSONHandler = new BSON[Pref] {
|
||||
|
||||
import lila.db.BSON.MapValue.{ MapReader, MapWriter }
|
||||
|
@ -110,6 +102,14 @@ final class PrefApi(
|
|||
)
|
||||
}
|
||||
|
||||
private def fetchPref(id: String): Fu[Option[Pref]] = coll.find($id(id)).uno[Pref]
|
||||
private val cache = asyncCache.multi(
|
||||
name = "pref.fetchPref",
|
||||
f = fetchPref,
|
||||
expireAfter = _.ExpireAfterAccess(cacheTtl)
|
||||
)
|
||||
|
||||
|
||||
def saveTag(user: User, name: String, value: String) =
|
||||
coll.update(
|
||||
$id(user.id),
|
||||
|
@ -156,6 +156,6 @@ final class PrefApi(
|
|||
getPref(userId) map change flatMap { setPref(_, notifyChange) }
|
||||
|
||||
def setPrefString(user: User, name: String, value: String, notifyChange: Boolean): Funit =
|
||||
getPref(user) map { _.set(name, value) } flatten
|
||||
getPref(user) map { _.set(name, value) } err
|
||||
s"Bad pref ${user.id} $name -> $value" flatMap { setPref(_, notifyChange) }
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package lila.push
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
|
||||
private final class GooglePush(
|
||||
getDevice: String => Fu[Option[Device]],
|
||||
|
@ -14,7 +13,7 @@ private final class GooglePush(
|
|||
getDevice(userId) flatMap {
|
||||
_ ?? { device =>
|
||||
WS.url(url)
|
||||
.withHeaders(
|
||||
.addHttpHeaders(
|
||||
"Authorization" -> s"key=$key",
|
||||
"Accept" -> "application/json",
|
||||
"Content-type" -> "application/json"
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package lila.push
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
|
||||
private final class OneSignalPush(
|
||||
getDevices: String => Fu[List[Device]],
|
||||
|
@ -16,7 +15,7 @@ private final class OneSignalPush(
|
|||
case Nil => funit
|
||||
case devices =>
|
||||
WS.url(url)
|
||||
.withHeaders(
|
||||
.addHttpHeaders(
|
||||
"Authorization" -> s"key=$key",
|
||||
"Accept" -> "application/json",
|
||||
"Content-type" -> "application/json"
|
||||
|
|
|
@ -25,7 +25,7 @@ private final class GameJson(
|
|||
|
||||
def generate(ck: CacheKey): Fu[JsObject] = ck match {
|
||||
case CacheKey(gameId, plies) => for {
|
||||
game <- (GameRepo game gameId).flatten(s"Missing puzzle game $gameId!")
|
||||
game <- GameRepo game gameId err s"Missing puzzle game $gameId!"
|
||||
_ <- lightUserApi preloadMany game.userIds
|
||||
perfType = lila.rating.PerfType orDefault PerfPicker.key(game)
|
||||
tree = TreeBuilder(game, plies)
|
||||
|
|
|
@ -34,7 +34,7 @@ private[puzzle] final class Selector(
|
|||
}
|
||||
}
|
||||
}
|
||||
}.mon(_.puzzle.selector.time) flatten "No puzzles available" addEffect { puzzle =>
|
||||
}.mon(_.puzzle.selector.time) err "No puzzles available" addEffect { puzzle =>
|
||||
lila.mon.puzzle.selector.vote(puzzle.vote.sum)
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ object PerfType {
|
|||
key = "chess960",
|
||||
name = chess.variant.Chess960.name,
|
||||
title = "Chess960 variant",
|
||||
iconChar = '''
|
||||
iconChar = '\''
|
||||
)
|
||||
|
||||
case object KingOfTheHill extends PerfType(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lila.report
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
import lila.common.PimpedJson._
|
||||
|
||||
object JsonView {
|
||||
|
|
|
@ -316,7 +316,7 @@ final class ReportApi(
|
|||
def ofModId(modId: User.ID): Fu[Option[Report]] = coll.uno[Report]($doc("inquiry.mod" -> modId))
|
||||
|
||||
def toggle(mod: User, id: String): Fu[Option[Report]] = for {
|
||||
report <- coll.byId[Report](id) flatten s"No report $id found"
|
||||
report <- coll.byId[Report](id) err s"No report $id found"
|
||||
current <- ofModId(mod.id)
|
||||
_ <- current ?? cancel(mod)
|
||||
isSame = current.exists(_.id == report.id)
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila.round
|
|||
|
||||
import org.joda.time.DateTime
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
|
||||
import chess.format.Uci
|
||||
import chess.Move
|
||||
|
|
|
@ -72,7 +72,7 @@ final class PerfsUpdater(
|
|||
}
|
||||
}
|
||||
|
||||
private final case class Ratings(
|
||||
private case class Ratings(
|
||||
chess960: Rating,
|
||||
kingOfTheHill: Rating,
|
||||
threeCheck: Rating,
|
||||
|
|
|
@ -262,17 +262,17 @@ private[round] final class Round(
|
|||
handlePov(proxy pov color)(op)
|
||||
|
||||
private def handlePov(pov: Fu[Option[Pov]])(op: Pov => Fu[Events]): Funit = publish {
|
||||
pov flatten "pov not found" flatMap { p =>
|
||||
pov err "pov not found" flatMap { p =>
|
||||
if (p.player.isAi) fufail(s"player $p can't play AI") else op(p)
|
||||
}
|
||||
} recover errorHandler("handlePov")
|
||||
|
||||
private def handleAi(game: Fu[Option[Game]])(op: Pov => Fu[Events]): Funit = publish {
|
||||
game.map(_.flatMap(_.aiPov)) flatten "pov not found" flatMap op
|
||||
game.map(_.flatMap(_.aiPov)) err "pov not found" flatMap op
|
||||
} recover errorHandler("handleAi")
|
||||
|
||||
private def handleGame(game: Fu[Option[Game]])(op: Game => Fu[Events]): Funit = publish {
|
||||
game flatten "game not found" flatMap op
|
||||
game err "game not found" flatMap op
|
||||
} recover errorHandler("handleGame")
|
||||
|
||||
private def publish[A](op: Fu[Events]): Funit = op.map { events =>
|
||||
|
|
|
@ -61,18 +61,14 @@ private[round] final class SocketHandler(
|
|||
case ("move", o) => parseMove(o) foreach {
|
||||
case (move, blur, lag) =>
|
||||
val promise = Promise[Unit]
|
||||
promise.future onFailure {
|
||||
case _: Exception => socket ! Resync(uid.value)
|
||||
}
|
||||
promise.future addFailureEffect { _ => socket ! Resync(uid.value) }
|
||||
send(HumanPlay(playerId, move, blur, lag, promise.some))
|
||||
member push ackEvent
|
||||
}
|
||||
case ("drop", o) => parseDrop(o) foreach {
|
||||
case (drop, blur, lag) =>
|
||||
val promise = Promise[Unit]
|
||||
promise.future onFailure {
|
||||
case _: Exception => socket ! Resync(uid.value)
|
||||
}
|
||||
promise.future addFailureEffect { _ => socket ! Resync(uid.value) }
|
||||
send(HumanPlay(playerId, drop, blur, lag, promise.some))
|
||||
member push ackEvent
|
||||
}
|
||||
|
|
|
@ -22,8 +22,7 @@ final class ESClientHttp(
|
|||
val index: Index,
|
||||
writeable: Boolean
|
||||
) extends ESClient {
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
|
||||
def store(id: Id, doc: JsObject) = writeable ?? monitor("store") {
|
||||
HTTP(s"store/${index.name}/${id.value}", doc)
|
||||
|
|
|
@ -6,7 +6,6 @@ import akka.actor.ActorSystem
|
|||
import play.api.i18n.Lang
|
||||
import old.play.api.libs.ws.WS
|
||||
import play.api.libs.ws.WSAuthScheme
|
||||
import play.api.Play.current
|
||||
import play.twirl.api.Html
|
||||
|
||||
import lila.common.EmailAddress
|
||||
|
|
|
@ -86,7 +86,7 @@ final class SimulApi(
|
|||
repo.findCreated(simulId) flatMap {
|
||||
_ ?? { simul =>
|
||||
simul.start ?? { started =>
|
||||
UserRepo byId started.hostId flatten s"No such host: ${simul.hostId}" flatMap { host =>
|
||||
UserRepo byId started.hostId err s"No such host: ${simul.hostId}" flatMap { host =>
|
||||
started.pairings.map(makeGame(started, host)).sequenceFu map { games =>
|
||||
games.headOption foreach {
|
||||
case (game, _) => sendTo(simul.id, actorApi.StartSimul(game, simul.hostId))
|
||||
|
@ -171,7 +171,7 @@ final class SimulApi(
|
|||
repo find id map2 { (simul: Simul) => simul.fullName }
|
||||
|
||||
private def makeGame(simul: Simul, host: User)(pairing: SimulPairing): Fu[(Game, chess.Color)] = for {
|
||||
user ← UserRepo byId pairing.player.user flatten s"No user with id ${pairing.player.user}"
|
||||
user ← UserRepo byId pairing.player.user err s"No user with id ${pairing.player.user}"
|
||||
hostColor = simul.hostColor
|
||||
whiteUser = hostColor.fold(host, user)
|
||||
blackUser = hostColor.fold(user, host)
|
||||
|
|
|
@ -2,7 +2,6 @@ package lila.site
|
|||
|
||||
import akka.actor._
|
||||
import com.typesafe.config.Config
|
||||
import play.api.libs.concurrent.Akka.system
|
||||
|
||||
import lila.common.PimpedConfig._
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package lila.slack
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
|
||||
import lila.common.PimpedJson._
|
||||
|
||||
|
|
|
@ -139,6 +139,24 @@ object BSONHandlers {
|
|||
def write(x: Glyphs) = BSONArray(x.toList.map(_.id).map(BSONInteger.apply))
|
||||
}
|
||||
|
||||
implicit val ChildrenBSONHandler = new BSONHandler[Barr, Node.Children] {
|
||||
private val nodesHandler = bsonArrayToVectorHandler[Node]
|
||||
def read(b: Barr) = try {
|
||||
Node.Children(nodesHandler read b)
|
||||
} catch {
|
||||
case e: StackOverflowError =>
|
||||
println(s"study handler ${e.toString}")
|
||||
Node.emptyChildren
|
||||
}
|
||||
def write(x: Node.Children) = try {
|
||||
nodesHandler write x.nodes
|
||||
} catch {
|
||||
case e: StackOverflowError =>
|
||||
println(s"study handler ${e.toString}")
|
||||
$arr()
|
||||
}
|
||||
}
|
||||
|
||||
private implicit def NodeBSONHandler: BSON[Node] = new BSON[Node] {
|
||||
def reads(r: Reader) = Node(
|
||||
id = r.get[UciCharPair]("i"),
|
||||
|
@ -197,23 +215,6 @@ object BSONHandlers {
|
|||
"n" -> s.children
|
||||
)
|
||||
}
|
||||
implicit val ChildrenBSONHandler = new BSONHandler[Barr, Node.Children] {
|
||||
private val nodesHandler = bsonArrayToVectorHandler[Node]
|
||||
def read(b: Barr) = try {
|
||||
Node.Children(nodesHandler read b)
|
||||
} catch {
|
||||
case e: StackOverflowError =>
|
||||
println(s"study handler ${e.toString}")
|
||||
Node.emptyChildren
|
||||
}
|
||||
def write(x: Node.Children) = try {
|
||||
nodesHandler write x.nodes
|
||||
} catch {
|
||||
case e: StackOverflowError =>
|
||||
println(s"study handler ${e.toString}")
|
||||
$arr()
|
||||
}
|
||||
}
|
||||
|
||||
implicit val PathBSONHandler = new BSONHandler[BSONString, Path] {
|
||||
def read(b: BSONString): Path = Path(b.value)
|
||||
|
|
|
@ -3,6 +3,7 @@ package lila.study
|
|||
import chess.format.{ Uci, UciCharPair, FEN }
|
||||
import chess.Pos
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
|
||||
import lila.common.LightUser
|
||||
import lila.common.PimpedJson._
|
||||
|
|
|
@ -13,7 +13,6 @@ private object MoveOpts {
|
|||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.functional.syntax._
|
||||
import play.api.data.validation.{ ValidationError => Err }
|
||||
import lila.common.PimpedJson._
|
||||
|
||||
private val default = MoveOpts(
|
||||
|
@ -28,10 +27,10 @@ private object MoveOpts {
|
|||
implicit val clockReader = Reads[Centis] {
|
||||
case JsNumber(centis) => JsSuccess(Centis(centis.toInt))
|
||||
case JsString(str) => CommentParser.readCentis(str) match {
|
||||
case None => JsError(Err(s"Cannot parse clock from $str"))
|
||||
case None => JsError(JsonValidationError(s"Cannot parse clock from $str"))
|
||||
case Some(centis) => JsSuccess(centis)
|
||||
}
|
||||
case x => JsError(Err(s"Cannot read clock from $x"))
|
||||
case x => JsError(JsonValidationError(s"Cannot read clock from $x"))
|
||||
}
|
||||
|
||||
private implicit val moveOptsReader: Reads[MoveOpts] = (
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package lila.study
|
||||
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
|
||||
private final class PgnFetch {
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import play.api.libs.json._
|
|||
|
||||
import chess.format.FEN
|
||||
import chess.format.pgn.Glyph
|
||||
import lila.chat.Chat
|
||||
import lila.common.PimpedJson._
|
||||
import lila.hub.actorApi.map._
|
||||
import lila.socket.actorApi.{ Connected => _, _ }
|
||||
|
@ -17,7 +18,6 @@ import lila.socket.Socket.Uid
|
|||
import lila.socket.{ Handler, AnaMove, AnaDrop, AnaAny }
|
||||
import lila.tree.Node.{ Shape, Shapes, Comment, Gamebook }
|
||||
import lila.user.User
|
||||
import lila.chat.Chat
|
||||
import makeTimeout.short
|
||||
|
||||
private[study] final class SocketHandler(
|
||||
|
@ -62,6 +62,27 @@ private[study] final class SocketHandler(
|
|||
}
|
||||
}
|
||||
|
||||
private def reading[A](o: JsValue)(f: A => Unit)(implicit reader: Reads[A]): Unit =
|
||||
o obj "d" flatMap { d => reader.reads(d).asOpt } foreach f
|
||||
|
||||
private implicit val chapterIdReader = stringIsoReader(Chapter.idIso)
|
||||
private case class AtPosition(path: String, chapterId: Chapter.Id) {
|
||||
def ref = Position.Ref(chapterId, Path(path))
|
||||
}
|
||||
private implicit val atPositionReader = (
|
||||
(__ \ "path").read[String] and
|
||||
(__ \ "ch").read[Chapter.Id]
|
||||
)(AtPosition.apply _)
|
||||
private case class SetRole(userId: String, role: String)
|
||||
private implicit val chapterNameReader = stringIsoReader(Chapter.nameIso)
|
||||
private implicit val setRoleReader = Json.reads[SetRole]
|
||||
private implicit val chapterDataReader = Json.reads[ChapterMaker.Data]
|
||||
private implicit val chapterEditDataReader = Json.reads[ChapterMaker.EditData]
|
||||
private implicit val chapterDescDataReader = Json.reads[ChapterMaker.DescData]
|
||||
private implicit val studyDataReader = Json.reads[Study.Data]
|
||||
private implicit val setTagReader = Json.reads[actorApi.SetTag]
|
||||
private implicit val gamebookReader = Json.reads[Gamebook]
|
||||
|
||||
private def controller(
|
||||
socket: ActorRef,
|
||||
studyId: Study.Id,
|
||||
|
@ -240,27 +261,6 @@ private[study] final class SocketHandler(
|
|||
canTimeout = Some(() => user.?? { u => api.isContributor(studyId, u.id) })
|
||||
)
|
||||
|
||||
private def reading[A](o: JsValue)(f: A => Unit)(implicit reader: Reads[A]): Unit =
|
||||
o obj "d" flatMap { d => reader.reads(d).asOpt } foreach f
|
||||
|
||||
private case class AtPosition(path: String, chapterId: Chapter.Id) {
|
||||
def ref = Position.Ref(chapterId, Path(path))
|
||||
}
|
||||
private implicit val chapterIdReader = stringIsoReader(Chapter.idIso)
|
||||
private implicit val chapterNameReader = stringIsoReader(Chapter.nameIso)
|
||||
private implicit val atPositionReader = (
|
||||
(__ \ "path").read[String] and
|
||||
(__ \ "ch").read[Chapter.Id]
|
||||
)(AtPosition.apply _)
|
||||
private case class SetRole(userId: String, role: String)
|
||||
private implicit val SetRoleReader = Json.reads[SetRole]
|
||||
private implicit val ChapterDataReader = Json.reads[ChapterMaker.Data]
|
||||
private implicit val ChapterEditDataReader = Json.reads[ChapterMaker.EditData]
|
||||
private implicit val ChapterDescDataReader = Json.reads[ChapterMaker.DescData]
|
||||
private implicit val StudyDataReader = Json.reads[Study.Data]
|
||||
private implicit val setTagReader = Json.reads[actorApi.SetTag]
|
||||
private implicit val gamebookReader = Json.reads[Gamebook]
|
||||
|
||||
def join(
|
||||
studyId: Study.Id,
|
||||
uid: Uid,
|
||||
|
|
|
@ -22,8 +22,8 @@ private final class StudyInvite(
|
|||
def apply(byUserId: User.ID, study: Study, invitedUsername: String, socket: ActorRef): Funit = for {
|
||||
_ <- !study.isOwner(byUserId) ?? fufail[Unit]("Only study owner can invite")
|
||||
_ <- (study.nbMembers >= maxMembers) ?? fufail[Unit](s"Max study members reached: $maxMembers")
|
||||
inviter <- UserRepo.named(byUserId) flatten "No such inviter"
|
||||
invited <- UserRepo.named(invitedUsername) flatten "No such invited"
|
||||
inviter <- UserRepo.named(byUserId) err "No such inviter"
|
||||
invited <- UserRepo.named(invitedUsername) err "No such invited"
|
||||
_ <- study.members.contains(invited) ?? fufail[Unit]("Already a member")
|
||||
relation <- getRelation(invited.id, byUserId)
|
||||
_ <- relation.has(Block) ?? fufail[Unit]("This user does not want to join")
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila.timeline
|
|||
|
||||
import org.joda.time.DateTime
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
import reactivemongo.bson._
|
||||
import scala.util.{ Try, Success, Failure }
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package lila.tournament
|
|||
import org.joda.time.DateTime
|
||||
import org.joda.time.format.ISODateTimeFormat
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
import play.api.i18n.Lang
|
||||
import scala.concurrent.duration._
|
||||
|
||||
|
@ -178,7 +179,7 @@ final class JsonView(
|
|||
|
||||
private val firstPageCache = asyncCache.clearable[String, JsObject](
|
||||
name = "tournament.firstPage",
|
||||
id => TournamentRepo byId id flatten s"No such tournament: $id" flatMap { computeStanding(_, 1) },
|
||||
id => TournamentRepo byId id err s"No such tournament: $id" flatMap { computeStanding(_, 1) },
|
||||
expireAfter = _.ExpireAfterWrite(1 second)
|
||||
)
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ object PlayerRepo {
|
|||
coll.find(selectTourUser(tourId, userId)).uno[Player]
|
||||
|
||||
def update(tourId: String, userId: String)(f: Player => Fu[Player]) =
|
||||
find(tourId, userId) flatten s"No such player: $tourId/$userId" flatMap f flatMap { player =>
|
||||
find(tourId, userId) err s"No such player: $tourId/$userId" flatMap f flatMap { player =>
|
||||
coll.update(selectId(player._id), player).void
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lila.tournament
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.json.JodaWrites._
|
||||
|
||||
import lila.common.LightUser
|
||||
import lila.common.PimpedJson._
|
||||
|
|
|
@ -24,7 +24,7 @@ final class StreamerList(
|
|||
}
|
||||
|
||||
private[tv] def validate(text: String): (List[Streamer], List[Exception]) = Try {
|
||||
ConfigFactory.parseString(text).getConfigList("streamers").toList.map { c =>
|
||||
ConfigFactory.parseString(text).getConfigList("streamers").asScala.toList.map { c =>
|
||||
Try {
|
||||
Streamer(
|
||||
service = c getString "service" match {
|
||||
|
|
|
@ -3,8 +3,7 @@ package lila.tv
|
|||
import akka.actor._
|
||||
import akka.pattern.{ ask, pipe }
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
|
||||
private final class Streaming(
|
||||
system: ActorSystem,
|
||||
|
@ -72,8 +71,8 @@ private final class Streaming(
|
|||
case Search => streamerList.get.map(_.filter(_.featured)).foreach { streamers =>
|
||||
val max = 5
|
||||
val twitch = WS.url("https://api.twitch.tv/kraken/streams")
|
||||
.withQueryString("channel" -> streamers.filter(_.twitch).map(_.streamerName).mkString(","))
|
||||
.withHeaders(
|
||||
.addQueryStringParameters("channel" -> streamers.filter(_.twitch).map(_.streamerName).mkString(","))
|
||||
.addHttpHeaders(
|
||||
"Accept" -> "application/vnd.twitchtv.v3+json",
|
||||
"Client-ID" -> twitchClientId
|
||||
)
|
||||
|
@ -86,7 +85,7 @@ private final class Streaming(
|
|||
}
|
||||
}
|
||||
val youtube = googleApiKey.nonEmpty ?? {
|
||||
WS.url("https://www.googleapis.com/youtube/v3/search").withQueryString(
|
||||
WS.url("https://www.googleapis.com/youtube/v3/search").addQueryStringParameters(
|
||||
"part" -> "snippet",
|
||||
"type" -> "video",
|
||||
"eventType" -> "live",
|
||||
|
|
|
@ -71,7 +71,7 @@ private[tv] final class TvActor(
|
|||
}
|
||||
)))
|
||||
if (channel == Tv.Channel.Best)
|
||||
rendererActor ? actorApi.RenderFeaturedJs(game) onSuccess {
|
||||
rendererActor ? actorApi.RenderFeaturedJs(game) foreach {
|
||||
case html: play.twirl.api.Html =>
|
||||
val event = lila.hub.actorApi.game.ChangeFeatured(
|
||||
game.id,
|
||||
|
|
|
@ -2,8 +2,7 @@ package lila.video
|
|||
|
||||
import org.joda.time.DateTime
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
|
||||
private[video] final class Sheet(
|
||||
url: String,
|
||||
|
|
|
@ -2,8 +2,7 @@ package lila.video
|
|||
|
||||
import org.joda.time.DateTime
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.Play.current
|
||||
import old.play.api.libs.ws.WS
|
||||
|
||||
private[video] final class Youtube(
|
||||
url: String,
|
||||
|
@ -39,7 +38,7 @@ private[video] final class Youtube(
|
|||
}
|
||||
|
||||
private def fetch: Fu[List[Entry]] = api.video.allIds flatMap { ids =>
|
||||
WS.url(url).withQueryString(
|
||||
WS.url(url).addQueryStringParameters(
|
||||
"id" -> scala.util.Random.shuffle(ids).take(max).mkString(","),
|
||||
"part" -> "id,statistics,snippet,contentDetails",
|
||||
"key" -> apiKey
|
||||
|
|
Loading…
Reference in New Issue