moving event stream to api
parent
8c8d91aa90
commit
efb84fa1f8
|
@ -274,6 +274,16 @@ object Api extends LilaController {
|
|||
}
|
||||
}
|
||||
|
||||
def eventStream = Scoped() { req => me =>
|
||||
RequireHttp11(req) {
|
||||
lila.game.GameRepo.urgentGames(me) flatMap { povs =>
|
||||
Env.challenge.api.createdByDestId(me.id) map { challenges =>
|
||||
Ok.chunked(Env.api.eventStream(me, povs.map(_.game), challenges))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def activity(name: String) = ApiRequest { implicit ctx =>
|
||||
val cost = 50
|
||||
UserRateLimit(cost = cost) {
|
||||
|
|
|
@ -28,16 +28,6 @@ object Bot extends LilaController {
|
|||
}
|
||||
}
|
||||
|
||||
def eventStream = Scoped(_.Bot.Play) { req => me =>
|
||||
RequireHttp11(req) {
|
||||
lila.game.GameRepo.urgentGames(me) flatMap { povs =>
|
||||
Env.challenge.api.createdByDestId(me.id) map { challenges =>
|
||||
Ok.chunked(Env.bot.eventStream(me, povs.map(_.game), challenges))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def command(cmd: String) = Scoped(_.Bot.Play) { _ => me =>
|
||||
cmd.split('/') match {
|
||||
case Array("account", "upgrade") =>
|
||||
|
|
|
@ -497,14 +497,14 @@ GET /api/tournament controllers.Api.currentTournaments
|
|||
GET /api/tournament/:id controllers.Api.tournament(id: String)
|
||||
GET /api/status controllers.Api.status
|
||||
GET /api/socket controllers.Main.apiWebsocket
|
||||
POST /api/game-stream controllers.Api.gameStream
|
||||
GET /api/users/status controllers.Api.usersStatus
|
||||
GET /api/crosstable/:u1/:u2 controllers.Api.crosstable(u1: String, u2: String)
|
||||
POST /api/stream/game controllers.Api.gameStream
|
||||
GET /api/stream/event controllers.Api.eventStream
|
||||
|
||||
# Bot API
|
||||
GET /bot/stream/event controllers.Bot.eventStream
|
||||
GET /bot/stream/game/:id controllers.Bot.gameStream(id: String)
|
||||
POST /bot/move/:id/:uci controllers.Bot.move(id: String, uci: String)
|
||||
GET /bot/game/stream/:id controllers.Bot.gameStream(id: String)
|
||||
POST /bot/game/:id/move/:uci controllers.Bot.move(id: String, uci: String)
|
||||
# /bot/account/upgrade
|
||||
POST /bot/*cmd controllers.Bot.command(cmd: String)
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ final class Env(
|
|||
isStreaming: lila.user.User.ID => Boolean,
|
||||
isPlaying: lila.user.User.ID => Boolean,
|
||||
pools: List[lila.pool.PoolConfig],
|
||||
challengeJsonView: lila.challenge.JsonView,
|
||||
val isProd: Boolean
|
||||
) {
|
||||
|
||||
|
@ -134,6 +135,8 @@ final class Env(
|
|||
pools = pools
|
||||
)
|
||||
|
||||
lazy val eventStream = new EventStream(system, challengeJsonView)
|
||||
|
||||
private def makeUrl(path: String): String = s"${Net.BaseUrl}/$path"
|
||||
|
||||
lazy val cli = new Cli(system.lilaBus)
|
||||
|
@ -177,6 +180,7 @@ object Env {
|
|||
isStreaming = lila.streamer.Env.current.liveStreamApi.isStreaming,
|
||||
isPlaying = lila.relation.Env.current.online.isPlaying,
|
||||
pools = lila.pool.Env.current.api.configs,
|
||||
challengeJsonView = lila.challenge.Env.current.jsonView,
|
||||
isProd = lila.common.PlayApp.isProd
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package lila.bot
|
||||
package lila.api
|
||||
|
||||
import akka.actor._
|
||||
import play.api.libs.iteratee._
|
||||
|
@ -9,12 +9,12 @@ import lila.game.Game
|
|||
import lila.user.User
|
||||
import lila.challenge.Challenge
|
||||
|
||||
final class BotEventStream(
|
||||
final class EventStream(
|
||||
system: ActorSystem,
|
||||
challengeJsonView: lila.challenge.JsonView
|
||||
) {
|
||||
|
||||
import BotStream._
|
||||
import lila.common.HttpStream._
|
||||
|
||||
def apply(me: User, gamesInProgress: List[Game], challenges: List[Challenge]): Enumerator[String] = {
|
||||
|
|
@ -5,7 +5,6 @@ import akka.actor._
|
|||
final class Env(
|
||||
system: ActorSystem,
|
||||
hub: lila.hub.Env,
|
||||
challengeJsonView: lila.challenge.JsonView,
|
||||
lightUserApi: lila.user.LightUserApi
|
||||
) {
|
||||
|
||||
|
@ -13,8 +12,6 @@ final class Env(
|
|||
|
||||
lazy val gameStateStream = new GameStateStream(system, jsonView)
|
||||
|
||||
lazy val eventStream = new BotEventStream(system, challengeJsonView)
|
||||
|
||||
lazy val player = new BotPlayer(
|
||||
roundMap = hub.actor.roundMap
|
||||
)
|
||||
|
@ -25,7 +22,6 @@ object Env {
|
|||
lazy val current: Env = "bot" boot new Env(
|
||||
system = lila.common.PlayApp.system,
|
||||
hub = lila.hub.Env.current,
|
||||
challengeJsonView = lila.challenge.Env.current.jsonView,
|
||||
lightUserApi = lila.user.Env.current.lightUserApi
|
||||
)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ final class GameStateStream(
|
|||
jsonView: BotJsonView
|
||||
) {
|
||||
|
||||
import BotStream._
|
||||
import lila.common.HttpStream._
|
||||
|
||||
def apply(init: Game.WithInitialFen): Enumerator[String] = {
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package lila.bot
|
||||
package lila.common
|
||||
|
||||
import akka.actor._
|
||||
import play.api.libs.iteratee._
|
||||
import play.api.libs.json._
|
||||
|
||||
private object BotStream {
|
||||
object HttpStream {
|
||||
|
||||
val stringify =
|
||||
Enumeratee.map[JsObject].apply[String] { js =>
|
Loading…
Reference in New Issue