Skip to content

Commit

Permalink
official broadcasters can use lichess as a broadcast source
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jun 26, 2024
1 parent 3490931 commit aa6034d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions modules/relay/src/main/RelayRoundForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ final class RelayRoundForm(using mode: Mode):
)

private def lccIsComplete(url: Upstream.Url) =
url.isLcc || !url.url.host.toString.contains("livechesscloud.com")
url.isLcc || !url.url.host.toString.endsWith("livechesscloud.com")

val roundMapping =
def roundMapping(using Me) =
mapping(
"name" -> cleanText(minLength = 3, maxLength = 80).into[RelayRound.Name],
"caption" -> optional(cleanText(minLength = 3, maxLength = 80).into[RelayRound.Caption]),
"syncSource" -> optional(stringIn(sourceTypes.map(_._1).toSet)),
"syncUrl" -> optional(
of[Upstream.Url]
.verifying("LCC URLs must end with /{round-number}, e.g. /5 for round 5", lccIsComplete)
.verifying(
"Invalid source URL",
u => !u.url.host.toString.endsWith("lichess.org") || Granter(_.Relay)
)
),
"syncUrls" -> optional(of[Upstream.Urls]),
"syncIds" -> optional(of[Upstream.Ids]),
Expand All @@ -67,19 +71,20 @@ final class RelayRoundForm(using mode: Mode):
.transform[List[RelayGame.Slice]](RelayGame.Slices.parse, RelayGame.Slices.show)
)(Data.apply)(unapply)

def create(trs: RelayTour.WithRounds) = Form(
def create(trs: RelayTour.WithRounds)(using Me) = Form(
roundMapping
.verifying(
s"Maximum rounds per tournament: ${RelayTour.maxRelays}",
_ => trs.rounds.sizeIs < RelayTour.maxRelays
)
).fill(fillFromPrevRounds(trs.rounds))

def edit(r: RelayRound) = Form(
roundMapping.verifying(
"The round source cannot be itself",
d => d.syncSource.forall(_ != "url") || d.syncUrl.forall(_.roundId.forall(_ != r.id))
)
def edit(r: RelayRound)(using Me) = Form(
roundMapping
.verifying(
"The round source cannot be itself",
d => d.syncSource.forall(_ != "url") || d.syncUrl.forall(_.roundId.forall(_ != r.id))
)
).fill(Data.make(r))

object RelayRoundForm:
Expand Down Expand Up @@ -176,7 +181,6 @@ object RelayRoundForm:
"twitch.com",
"youtube.com",
"youtu.be",
"lichess.org",
"google.com",
"vk.com",
"chess-results.com",
Expand Down

0 comments on commit aa6034d

Please sign in to comment.