add /tv/channels API endpoint

pull/3969/head
Thibault Duplessis 2018-01-07 20:55:11 -05:00
parent e79409db2f
commit 784e8257a2
4 changed files with 11 additions and 2 deletions

View File

@ -28,6 +28,14 @@ object Tv extends LilaController {
}
}
def channels = Action.async {
import play.api.libs.json._
implicit val championWrites = Json.writes[lila.tv.Tv.Champion]
Env.tv.tv.getChampions map {
_.channels map { case (chan, champ) => chan.name -> champ }
} map { Json.toJson(_) } map { Ok(_) }
}
private def lichessTv(channel: lila.tv.Tv.Channel)(implicit ctx: Context) =
OptionFuResult(Env.tv.tv getGameAndHistory channel) {
case (game, history) =>

View File

@ -23,6 +23,7 @@ GET /tv controllers.Tv.index
GET /tv/embed controllers.Tv.embed
GET /tv/frame controllers.Tv.frame
GET /tv/feed controllers.Tv.feed
GET /tv/channels controllers.Tv.channels
GET /tv/:chanKey controllers.Tv.onChannel(chanKey: String)
GET /tv/:chanKey/$gameId<\w{8}>/$color<white|black>/sides controllers.Tv.sides(chanKey: String, gameId: String, color: String)
GET /games controllers.Tv.games

View File

@ -52,7 +52,7 @@ object Tv {
import chess.{ Speed => S, variant => V }
import lila.rating.{ PerfType => P }
case class Champion(user: LightUser, rating: Int)
case class Champion(user: LightUser, rating: Int, gameId: Game.ID)
case class Champions(channels: Map[Channel, Champion]) {
def get = channels.get _
}

View File

@ -56,7 +56,7 @@ private[tv] final class TvActor(
val player = game.firstPlayer
val user = player.userId flatMap lightUser
(user |@| player.rating) apply {
case (u, r) => channelChampions += (channel -> Tv.Champion(u, r))
case (u, r) => channelChampions += (channel -> Tv.Champion(u, r, game.id))
}
selectChannel ! lila.socket.Channel.Publish(makeMessage("tvSelect", Json.obj(
"channel" -> channel.key,