Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schlawg/local-play #15667

Draft
wants to merge 301 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
301 commits
Select commit Hold shift + click to select a range
1c8999a
gah
schlawg Aug 26, 2023
fec9b9d
build hack to disable delayed css caching
schlawg Aug 27, 2023
c63b0e6
gah
schlawg Aug 28, 2023
ac9eb12
gah
schlawg Aug 28, 2023
2c143f9
gah
schlawg Aug 29, 2023
ee859d9
gah
schlawg Aug 29, 2023
22bda18
gah
schlawg Aug 30, 2023
b9c631f
.
schlawg Aug 31, 2023
d5ccd15
maybe they wont notice yellow ones
schlawg Aug 29, 2023
bed27fd
Merge remote-tracking branch 'origin/local-play' into local-play
schlawg Aug 31, 2023
86417a2
.
schlawg Aug 31, 2023
25c51c3
Merge branch 'ui-analysis-navigation-patch' into local-play
schlawg Aug 31, 2023
fdb1fc9
.
schlawg Sep 1, 2023
246e84d
.
schlawg Sep 1, 2023
72f5925
.
schlawg Sep 1, 2023
8bb6b5b
.
schlawg Sep 2, 2023
4aadde9
.
schlawg Sep 2, 2023
0232cbb
merge
schlawg Sep 2, 2023
e65ab09
gah
schlawg Sep 2, 2023
e9e99fa
.
schlawg Sep 2, 2023
05c7a49
Merge remote-tracking branch 'origin/local-play' into local-play
schlawg Sep 2, 2023
7bec94b
.
schlawg Sep 4, 2023
0909d4b
.
schlawg Sep 5, 2023
52ae825
.
schlawg Sep 6, 2023
58040b0
.
schlawg Sep 6, 2023
c95481b
.
schlawg Sep 6, 2023
0d0cbb6
merge
schlawg Sep 7, 2023
861a961
merge
schlawg Sep 7, 2023
df9fae5
merge
schlawg Sep 7, 2023
c60addb
merge
schlawg Sep 7, 2023
c4fe143
Merge remote-tracking branch 'origin/ui-licon-scss' into local-play
schlawg Sep 7, 2023
8ac757a
.
schlawg Sep 7, 2023
ff1e6fa
.
schlawg Sep 7, 2023
c449414
.
schlawg Sep 7, 2023
e5edcab
gah
schlawg Sep 8, 2023
30529d5
gah
schlawg Sep 8, 2023
631e578
Merge branch 'ui-html-dialog-element' into local-play
schlawg Sep 9, 2023
c96cbd1
gah
schlawg Nov 1, 2023
5ac91f9
gah
schlawg Nov 1, 2023
d19dde9
fishes
schlawg Nov 2, 2023
1e0ba9c
gah
schlawg Nov 3, 2023
44397f7
gah
schlawg Nov 3, 2023
c88edb5
stockfish web testing
schlawg Nov 6, 2023
030dc64
merge
schlawg Nov 10, 2023
cbe0d49
gah
schlawg Nov 11, 2023
560df8b
gah
schlawg Nov 11, 2023
628e799
refacterz
schlawg Nov 12, 2023
a734243
gfx
schlawg Nov 13, 2023
195f180
.
schlawg Nov 13, 2023
36e03de
merge
schlawg Nov 14, 2023
062adac
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Nov 15, 2023
2d917e0
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Nov 15, 2023
506f694
.
schlawg Nov 16, 2023
e435990
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Nov 16, 2023
2a20f27
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Nov 17, 2023
298aba7
gah
schlawg Nov 18, 2023
198435c
merge
schlawg Nov 20, 2023
51a135a
gah
schlawg Nov 22, 2023
53c7947
gah
schlawg Nov 23, 2023
8b6869a
gah
schlawg Nov 24, 2023
5c11843
merge
schlawg Nov 25, 2023
48f311b
Merge remote-tracking branch 'origin/ui-persistent-logging' into loca…
schlawg Nov 27, 2023
e903f77
merge
schlawg Nov 27, 2023
56f7611
merge
schlawg Nov 28, 2023
0c76831
merge
schlawg Nov 28, 2023
83a3421
merge
schlawg Nov 29, 2023
5251374
gah
schlawg Nov 29, 2023
ef5d876
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Nov 30, 2023
f1e8b9b
Merge branch 'improved-persistent-logging' into local-play
schlawg Nov 30, 2023
a2222ec
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Nov 30, 2023
a32ff21
gah
schlawg Dec 1, 2023
cda72b8
gah
schlawg Dec 3, 2023
a8f2cc4
murge
schlawg Dec 29, 2023
358ea04
murge
schlawg Dec 29, 2023
29465d5
gah
schlawg Dec 30, 2023
92a28b1
gah
schlawg Jan 1, 2024
a6f899b
fix logging
schlawg Jan 2, 2024
8a8e8e8
gah
schlawg Jan 2, 2024
8828051
gah
schlawg Jan 2, 2024
f90be35
Merge remote-tracking branch 'origin/local-play' into local-play
schlawg Jan 2, 2024
b2a64d8
need to find out why ui/build takes 4x as long on this branch...
schlawg Mar 16, 2024
076344c
wtf, builds are 3x slower this branch
schlawg Mar 16, 2024
5779776
running out of ideas i never had
schlawg Mar 16, 2024
14ee685
is it the lockfile?
schlawg Mar 16, 2024
d426f08
at long last snabbdom 3.6 is slain and the kingdom is saved
schlawg Mar 16, 2024
ee29ce9
wip
schlawg Apr 17, 2024
f63a89d
wip
schlawg Apr 17, 2024
9c2eee4
merge from ui-improve-dasher
schlawg Apr 17, 2024
eab8e25
wip
schlawg Apr 22, 2024
a65c26e
move around the things
schlawg Apr 22, 2024
926f698
gah
schlawg Apr 23, 2024
bf55188
gah
schlawg Apr 24, 2024
36dcf13
less broken than local-canary
schlawg May 4, 2024
4183d2c
latest from master
schlawg May 13, 2024
4bcf888
wip
schlawg May 14, 2024
6deea38
haw haw
schlawg May 15, 2024
bfd2700
gah
schlawg May 17, 2024
bd72933
Merge remote-tracking branch 'upstream/master' into local-play
schlawg May 17, 2024
35ce607
gah
schlawg May 18, 2024
45d1fef
gah
schlawg May 18, 2024
0e8b530
gah
schlawg May 20, 2024
2c89b0a
Merge remote-tracking branch 'upstream/master' into local-play
schlawg May 20, 2024
c73315e
Merge branch 'mismatched-asset-urls' into local-play
schlawg May 21, 2024
57444bc
Merge branch 'sortablejs' into local-play
schlawg May 21, 2024
366e98d
gah
schlawg May 21, 2024
16cffe6
prior to adding bot ranking
schlawg May 26, 2024
d21f414
Merge remote-tracking branch 'upstream/master' into local-play
schlawg May 26, 2024
a688b3d
backup
schlawg May 29, 2024
14b824d
goness
schlawg May 29, 2024
3ea3338
Merge remote-tracking branch 'upstream/master' into local-play
schlawg May 30, 2024
4dbc4f1
gah
schlawg May 30, 2024
078b837
wip
schlawg Jun 1, 2024
db69506
merge
schlawg Jun 2, 2024
472de34
wip
schlawg Jun 11, 2024
d1e6cf7
wip
schlawg Jun 11, 2024
96c7756
wip
schlawg Jun 12, 2024
4363631
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jun 12, 2024
3277ecd
gah
schlawg Jun 15, 2024
2d20c0e
gah
schlawg Jun 15, 2024
a1afd51
gah
schlawg Jun 18, 2024
c6a2f84
merge
schlawg Jun 21, 2024
eff6c89
wip
schlawg Jun 21, 2024
2b74e32
.gitignore
schlawg Jun 21, 2024
506f0ad
gah
schlawg Jun 22, 2024
ca63538
gah
schlawg Jun 22, 2024
5256796
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jun 22, 2024
9061953
this f*cking dialog will kill me one day
schlawg Jun 23, 2024
20711ed
gah
schlawg Jun 27, 2024
7f6aec2
gah
schlawg Jun 27, 2024
ef3e6c3
code splitting obviates site.dialog
schlawg Jun 27, 2024
076d1ee
gah
schlawg Jun 27, 2024
4560d2b
wip
schlawg Jul 3, 2024
b29fe43
wip
schlawg Jul 4, 2024
1e02047
gah
schlawg Jul 4, 2024
dba0028
gah
schlawg Jul 4, 2024
f175720
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jul 5, 2024
7d1c937
gah
schlawg Jul 5, 2024
3b1fe12
gah
schlawg Jul 5, 2024
61e9090
refacterz
schlawg Jul 6, 2024
8376463
wip
schlawg Jul 11, 2024
1b30799
merge prior to typescript 5.5
schlawg Jul 11, 2024
a0fe79c
wip
schlawg Jul 11, 2024
130b4ba
dunno whats in this
schlawg Jul 12, 2024
54fdb57
gah
schlawg Jul 12, 2024
b9bb035
add hash linked assets
schlawg Jul 14, 2024
e2b8301
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jul 14, 2024
a489916
we jammin
schlawg Jul 14, 2024
dc0f473
merge
schlawg Jul 15, 2024
f0c5704
testing add-hooks
schlawg Jul 16, 2024
4fc0b4f
try pre-push again
schlawg Jul 16, 2024
106a830
pre-merge
schlawg Jul 17, 2024
069c14c
apply allan joseph ci build fix
schlawg Jul 17, 2024
b964fa5
wip
schlawg Jul 21, 2024
81051be
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jul 21, 2024
830cb6c
bot editor fixup
schlawg Jul 22, 2024
29bd788
add export study to libot
schlawg Jul 22, 2024
0ab17e2
gah
schlawg Jul 26, 2024
dc8dfa9
wip
schlawg Jul 26, 2024
4bc72d1
mobile
schlawg Jul 28, 2024
2844a5b
bot & asset crud for bot dev
schlawg Jul 29, 2024
f42bb9c
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jul 29, 2024
c0caed9
wip
schlawg Aug 1, 2024
4a8de4f
gah
schlawg Aug 2, 2024
d274168
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 2, 2024
b5da6bb
ui fuckery
schlawg Aug 2, 2024
e2925c1
gah
schlawg Aug 5, 2024
d66d35c
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 5, 2024
6a25e87
gah
schlawg Aug 7, 2024
e58fe6e
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 7, 2024
a115ba5
wip
schlawg Aug 13, 2024
3af006e
merge
schlawg Aug 13, 2024
244676c
move isolatedDeclarations to tsconfig.base.json, and clean up all the…
schlawg Aug 13, 2024
73e9e52
remove accidental files
schlawg Aug 13, 2024
4d46b16
wip
schlawg Aug 16, 2024
029fd25
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 16, 2024
14cc315
just need history dialog and we ready
schlawg Aug 17, 2024
69a2151
gah
schlawg Aug 19, 2024
7758ebe
gah
schlawg Aug 19, 2024
5e6e972
private play branch for testy
schlawg Aug 19, 2024
db8e8ca
remove cruft
schlawg Aug 19, 2024
d6c1e51
gah
schlawg Aug 19, 2024
953c92c
fix bin/deploy
schlawg Aug 19, 2024
0ab238e
gah
schlawg Aug 19, 2024
fcb8b41
moar bin/deploy
schlawg Aug 19, 2024
c6dd3fc
moar bin/deploy
schlawg Aug 19, 2024
ba76393
remove http request to self
schlawg Aug 19, 2024
f03409f
sanity check
schlawg Aug 19, 2024
b8b85c8
fix bin/deploy again
schlawg Aug 19, 2024
139cc1f
round/ctrl.ts better handles clock changes
schlawg Aug 20, 2024
63840c1
isolatedDeclarations related tweaks. also preload opening books and s…
schlawg Aug 21, 2024
39a4ada
murge
schlawg Aug 21, 2024
b6fe651
refacterz and add stuff i realized we need while making video
schlawg Aug 24, 2024
9894b3c
get rid of outdated build cruft
schlawg Aug 24, 2024
fcfbcf5
for video
schlawg Aug 24, 2024
85d6614
fix zerofish link
schlawg Aug 24, 2024
b08b93b
murge new purtier
schlawg Aug 24, 2024
d44a727
comment out button in gui
schlawg Aug 24, 2024
e236388
fix bugs found making video
schlawg Aug 25, 2024
1c8bdd0
fix style issue
schlawg Aug 25, 2024
b73cf67
push labels out to right on lhs card spreads
schlawg Aug 28, 2024
6d10c6d
handOfCards ugly right now, will fix after video
schlawg Aug 28, 2024
2edfe01
murge
schlawg Aug 28, 2024
f17de0d
minor fixes to cards & new bot dialog
schlawg Aug 29, 2024
2f17bda
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 29, 2024
0a00071
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 30, 2024
7190b3c
take eslint update from ui-assorted-improvements
schlawg Aug 30, 2024
d0fbc61
murge
schlawg Sep 2, 2024
38bb375
murge
schlawg Sep 5, 2024
bc8c1da
fix lint
schlawg Sep 5, 2024
2a82881
gah
schlawg Sep 5, 2024
11c4d99
murge
schlawg Sep 12, 2024
2ccbb62
add boteditor permission
schlawg Sep 12, 2024
cbb1929
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Sep 12, 2024
029ebf5
eslint
schlawg Sep 12, 2024
5d6d430
fix iterator error due to CI typings mismatch
schlawg Sep 12, 2024
cce0d12
murge
schlawg Sep 13, 2024
e3f4f6c
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Sep 13, 2024
cc300eb
merge from master
schlawg Sep 16, 2024
bdbba68
murge
schlawg Sep 18, 2024
a4de350
merge socket-test updates
schlawg Sep 18, 2024
9bd632e
Merge branch 'scala-esm-interop-cleanup' into local-play
schlawg Sep 18, 2024
67df2c7
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Sep 18, 2024
c22bd17
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Sep 19, 2024
42d9247
murge and also let everyone play with bot dev, only require BotEditor…
schlawg Sep 28, 2024
4c161c4
updates from master
schlawg Oct 5, 2024
498c84d
prettier
schlawg Oct 5, 2024
23d44c3
fix time controls on prototype setup dialog
schlawg Oct 7, 2024
c062914
no move confirm on private play
schlawg Oct 7, 2024
ac4979c
preload images on slow connections
schlawg Oct 8, 2024
6ea18eb
properly wait on preloaded images
schlawg Oct 8, 2024
170197f
rename selector -> switch
schlawg Oct 8, 2024
da3429d
fix animation glitch on first draw
schlawg Oct 8, 2024
da567c5
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Oct 9, 2024
3ce47b2
murge from master
schlawg Oct 16, 2024
8e3e82c
murge
schlawg Oct 23, 2024
0529bce
prepare for multideck
schlawg Oct 24, 2024
113d9b3
buh
schlawg Oct 26, 2024
44ad966
gah
schlawg Oct 26, 2024
f049732
murge
schlawg Oct 26, 2024
c3f4143
murge
schlawg Oct 27, 2024
2a09193
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Oct 27, 2024
f72060e
murge
schlawg Nov 6, 2024
2d63d7b
murge
schlawg Dec 20, 2024
5eb1f9c
murge
schlawg Jan 1, 2025
8f2b92b
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jan 2, 2025
a3ae587
zerofish 0.0.30
schlawg Jan 2, 2025
61281a9
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jan 5, 2025
b105edf
updates from testy: dont 3fold, tracing reports
schlawg Jan 5, 2025
da881d0
merge faceted filters, conditional books, bugfixes
schlawg Jan 11, 2025
1a9a666
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jan 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class Env(
given translator: lila.core.i18n.Translator = lila.i18n.Translator
given scheduler: Scheduler = system.scheduler
given lila.core.config.RateLimit = net.rateLimit
given getFile: (String => java.io.File) = environment.getFile

// wire all the lila modules in the right order
val i18n: lila.i18n.Env.type = lila.i18n.Env
Expand Down Expand Up @@ -94,6 +95,7 @@ final class Env(
val bot: lila.bot.Env = wire[lila.bot.Env]
val storm: lila.storm.Env = wire[lila.storm.Env]
val racer: lila.racer.Env = wire[lila.racer.Env]
val local: lila.local.Env = wire[lila.local.Env]
val opening: lila.opening.Env = wire[lila.opening.Env]
val tutor: lila.tutor.Env = wire[lila.tutor.Env]
val recap: lila.recap.Env = wire[lila.recap.Env]
Expand Down
1 change: 1 addition & 0 deletions app/LilaComponents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ final class LilaComponents(
lazy val irwin: Irwin = wire[Irwin]
lazy val learn: Learn = wire[Learn]
lazy val lobby: Lobby = wire[Lobby]
lazy val localPlay: Local = wire[Local]
lazy val main: Main = wire[Main]
lazy val msg: Msg = wire[Msg]
lazy val mod: Mod = wire[Mod]
Expand Down
138 changes: 138 additions & 0 deletions app/controllers/Local.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package controllers

import play.api.libs.json.*
import play.api.i18n.Lang
import play.api.mvc.*
import play.api.data.*
import play.api.data.Forms.*
import views.*

import lila.app.{ given, * }
import lila.common.Json.given
import lila.user.User
import lila.rating.{ Perf, PerfType }
import lila.security.Permission
import lila.local.{ GameSetup, AssetType }

final class Local(env: Env) extends LilaController(env):
def index(
white: Option[String],
black: Option[String],
fen: Option[String],
time: Option[String],
go: Option[String]
) = Open:
val initial = time.map(_.toFloat)
val increment = time.flatMap(_.split('+').drop(1).headOption.map(_.toFloat))
val setup =
if white.isDefined || black.isDefined || fen.isDefined || time.isDefined then
GameSetup(white, black, fen, initial, increment, optTrue(go)).some
else none
for
bots <- env.local.repo.getLatestBots()
page <- renderPage(indexPage(setup, bots, none))
yield Ok(page).enforceCrossSiteIsolation.withHeaders("Service-Worker-Allowed" -> "/")

def bots = Open:
env.local.repo
.getLatestBots()
.map: bots =>
JsonOk(Json.obj("bots" -> bots))

def assetKeys = Open: // for service worker
JsonOk(env.local.api.assetKeys)

def devIndex = Auth: _ ?=>
for
bots <- env.local.repo.getLatestBots()
assets <- getDevAssets
page <- renderPage(indexPage(none, bots, assets.some))
yield Ok(page).enforceCrossSiteIsolation.withHeaders("Service-Worker-Allowed" -> "/")

def devAssets = Auth: ctx ?=>
getDevAssets.map(JsonOk)

def devBotHistory(botId: Option[String]) = Auth: _ ?=>
env.local.repo
.getVersions(botId.map(UserId.apply))
.map: history =>
JsonOk(Json.obj("bots" -> history))

def devPostBot = SecureBody(parse.json)(_.BotEditor) { ctx ?=> me ?=>
ctx.body.body
.validate[JsObject]
.fold(
err => BadRequest(Json.obj("error" -> err.toString)),
bot =>
env.local.repo
.putBot(bot, me.userId)
.map: updatedBot =>
JsonOk(updatedBot)
)
}

def devNameAsset(key: String, name: String) = Secure(_.BotEditor): _ ?=>
env.local.repo
.nameAsset(none, key, name, none)
.flatMap(_ => getDevAssets.map(JsonOk))

def devDeleteAsset(key: String) = Secure(_.BotEditor): _ ?=>
env.local.repo
.deleteAsset(key)
.flatMap(_ => getDevAssets.map(JsonOk))

def devPostAsset(notAString: String, key: String) = SecureBody(parse.multipartFormData)(_.BotEditor) {
ctx ?=>
val tpe: AssetType = notAString.asInstanceOf[AssetType]
val author: Option[String] = ctx.body.body.dataParts.get("author").flatMap(_.headOption)
val name = ctx.body.body.dataParts.get("name").flatMap(_.headOption).getOrElse(key)
ctx.body.body
.file("file")
.map: file =>
env.local.api
.storeAsset(tpe, key, file)
.flatMap:
case Left(error) => InternalServerError(Json.obj("error" -> error.toString)).as(JSON)
case Right(assets) =>
env.local.repo
.nameAsset(tpe.some, key, name, author)
.flatMap(_ => (JsonOk(Json.obj("key" -> key, "name" -> name))))
.getOrElse(fuccess(BadRequest(Json.obj("error" -> "missing file")).as(JSON)))
}

private def indexPage(setup: Option[GameSetup], bots: JsArray, devAssets: Option[JsObject] = none)(using
ctx: Context
) =
given setupFormat: Format[GameSetup] = Json.format[GameSetup]
views.local.index(
Json
.obj("pref" -> pref, "bots" -> bots)
.add("setup", setup)
.add("assets", devAssets)
.add("userId", ctx.me.map(_.userId))
.add("username", ctx.me.map(_.username))
.add("canPost", isGrantedOpt(_.BotEditor)),
if devAssets.isDefined then "local.dev" else "local"
)

private def getDevAssets =
env.local.repo.getAssets.map: m =>
JsObject:
env.local.api.assetKeys
.as[JsObject]
.fields
.collect:
case (category, JsArray(keys)) =>
category -> JsArray:
keys.collect:
case JsString(key) if m.contains(key) =>
Json.obj("key" -> key, "name" -> m(key))

private def pref(using ctx: Context) =
lila.pref.JsonView
.write(ctx.pref, false)
.add("animationDuration", ctx.pref.animationMillis.some)
.add("enablePremove", ctx.pref.premove.some)

private def optTrue(s: Option[String]) =
s.exists(v => v == "" || v == "1" || v == "true")
2 changes: 1 addition & 1 deletion app/controllers/Push.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class Push(env: Env) extends LilaController(env):

def webSubscribe = AuthBody(parse.json) { ctx ?=> me ?=>
val currentSessionId = ~env.security.api.reqSessionId(ctx.req)
ctx.body.body
ctx.body.body.pp
.validate[WebSubscription]
.fold(
err => BadRequest(err.toString),
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/Round.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class Round(
jsChat <- chat.flatMap(_.game).map(_.chat).soFu(lila.chat.JsonView.asyncLines)
yield Ok(data.add("chat", jsChat)).noCache
)
yield res
yield res.enforceCrossSiteIsolation

def player(fullId: GameFullId) = Open:
env.round.proxyRepo
Expand Down
2 changes: 2 additions & 0 deletions app/views/ui.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ val challenge = lila.challenge.ui.ChallengeUi(helpers)

val dev = lila.web.ui.DevUi(helpers)(mod.ui.menu)

val local = lila.local.ui.LocalUi(helpers)

def mobile(p: lila.cms.CmsPage.Render)(using Context) =
lila.web.ui.mobile(helpers)(cms.render(p))

Expand Down
3 changes: 1 addition & 2 deletions bin/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ PROFILES = {
"manta-assets": asset_profile("[email protected]", deploy_dir="/home/lichess"),
}


class DeployError(Exception):
pass

Expand Down Expand Up @@ -313,7 +312,7 @@ def deploy_script(profile, session, run, url):
]
else:
commands += [
f'echo "{artifact_unzipped}/d/{symlink} -> {deploy_dir}/{symlink}";ln -f --no-target-directory -s {artifact_unzipped}/d/{symlink} {deploy_dir}/{symlink}'
f'echo "{artifact_unzipped}/d/{symlink} -> {deploy_dir}/{symlink}"; ln -f --no-target-directory -s {artifact_unzipped}/d/{symlink} {deploy_dir}/{symlink}'
for symlink in profile["symlinks"]
] + [f"chmod -f +x {deploy_dir}/bin/lila || true"]

Expand Down
7 changes: 6 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ lazy val modules = Seq(
pool, lobby, relation, tv, coordinate, feed, history, recap,
shutup, appeal, irc, explorer, learn, event, coach,
practice, evalCache, irwin, bot, racer, cms, i18n,
socket, bookmark, studySearch, gameSearch, forumSearch, teamSearch,
socket, bookmark, studySearch, gameSearch, forumSearch, teamSearch, local
)

lazy val moduleRefs = modules map projectToRef
Expand Down Expand Up @@ -150,6 +150,11 @@ lazy val racer = module("racer",
Seq()
)

lazy val local = module("local",
Seq(db, memo, ui, pref),
Seq()
)

lazy val video = module("video",
Seq(memo, ui),
macwire.bundle
Expand Down
1 change: 1 addition & 0 deletions conf/base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ insight {
learn {
collection.progress = learn_progress
}
local.asset_path = "public/lifat/bots"
kaladin.enabled = false
zulip {
domain = ""
Expand Down
12 changes: 12 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,18 @@ GET /streamer/:username controllers.Streamer.show(username: UserS
GET /streamer/:username/redirect controllers.Streamer.redirect(username: UserStr)
POST /streamer/:username/check controllers.Streamer.checkOnline(username: UserStr)

# Private Play

GET /local controllers.Local.index(white: Option[String], black: Option[String], fen: Option[String], time: Option[String], go: Option[String])
GET /local/bots controllers.Local.bots
GET /local/assets controllers.Local.assetKeys
GET /local/dev controllers.Local.devIndex
GET /local/dev/history controllers.Local.devBotHistory(id: Option[String])
POST /local/dev/bot controllers.Local.devPostBot
GET /local/dev/assets controllers.Local.devAssets
POST /local/dev/asset/$tpe<sound|image|book>/$key<\w{12}(\.\w{2,4})?> controllers.Local.devPostAsset(tpe: String, key: String)
POST /local/dev/asset/mv/$key<\w{12}(\.\w{2,4})?>/:name controllers.Local.devNameAsset(key: String, name: String)

# Round
GET /$gameId<\w{8}> controllers.Round.watcher(gameId: GameId, color: Color = Color.white)
GET /$gameId<\w{8}>/$color<white|black> controllers.Round.watcher(gameId: GameId, color: Color)
Expand Down
4 changes: 3 additions & 1 deletion modules/core/src/main/perm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ enum Permission(val key: String, val alsoGrants: List[Permission], val name: Str
case ApiHog extends Permission("API_HOG", "API hog")
case ApiChallengeAdmin extends Permission("API_CHALLENGE_ADMIN", "API Challenge admin")
case LichessTeam extends Permission("LICHESS_TEAM", List(Beta), "Lichess team")
case BotEditor extends Permission("BOT_EDITOR", "Bot editor")
case TimeoutMod
extends Permission(
"TIMEOUT_MOD",
Expand Down Expand Up @@ -188,6 +189,7 @@ enum Permission(val key: String, val alsoGrants: List[Permission], val name: Str
extends Permission(
"ADMIN",
List(
BotEditor,
LichessTeam,
UserSearch,
PrizeBan,
Expand Down Expand Up @@ -243,7 +245,7 @@ object Permission:
val all: Set[Permission] = values.toSet

val nonModPermissions: Set[Permission] =
Set(Beta, Coach, Teacher, Developer, Verified, ContentTeam, BroadcastTeam, ApiHog)
Set(Beta, Coach, Teacher, Developer, Verified, ContentTeam, BroadcastTeam, ApiHog, BotEditor)

val modPermissions: Set[Permission] = all.diff(nonModPermissions)

Expand Down
28 changes: 28 additions & 0 deletions modules/local/src/main/Env.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package lila.local

import com.softwaremill.macwire.*
import play.api.Configuration

import lila.common.autoconfig.{ *, given }
import lila.core.config.*

@Module
final private class LocalConfig(
@ConfigName("asset_path") val assetPath: String
)

@Module
final class Env(
appConfig: Configuration,
db: lila.db.Db,
getFile: (String => java.io.File)
)(using
Executor,
akka.stream.Materializer
)(using mode: play.api.Mode, scheduler: Scheduler):

private val config: LocalConfig = appConfig.get[LocalConfig]("local")(AutoConfig.loader)

val repo = LocalRepo(db(CollName("local_bots")), db(CollName("local_assets")))

val api: LocalApi = wire[LocalApi]
56 changes: 56 additions & 0 deletions modules/local/src/main/LocalApi.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package lila.local

import java.nio.file.{ Files as NioFiles, Paths }
import play.api.libs.json.*
import play.api.libs.Files
import play.api.mvc.*
import akka.stream.scaladsl.{ FileIO, Source }
import akka.util.ByteString

// this stuff is for bot devs

final private class LocalApi(config: LocalConfig, repo: LocalRepo, getFile: (String => java.io.File))(using
Executor,
akka.stream.Materializer
):

@volatile private var cachedAssets: Option[JsObject] = None

def storeAsset(
tpe: "image" | "book" | "sound",
name: String,
file: MultipartFormData.FilePart[Files.TemporaryFile]
): Fu[Either[String, JsObject]] =
FileIO
.fromPath(file.ref.path)
.runWith(FileIO.toPath(getFile(s"public/lifat/bots/${tpe}/$name").toPath))
.map: result =>
if result.wasSuccessful then Right(updateAssets)
else Left(s"Error uploading asset $tpe $name")
.recover:
case e: Exception => Left(s"Exception: ${e.getMessage}")

def assetKeys: JsObject = cachedAssets.getOrElse(updateAssets)

private def listFiles(tpe: String): List[String] =
val path = getFile(s"public/lifat/bots/${tpe}")
if !path.exists() then
NioFiles.createDirectories(path.toPath)
Nil
else
path
.listFiles()
.toList
.map(_.getName)

def updateAssets: JsObject =
val newAssets = Json.obj(
"image" -> listFiles("image"),
"net" -> listFiles("net"),
"sound" -> listFiles("sound"),
"book" -> listFiles("book")
.filter(_.endsWith(".bin"))
.map(_.dropRight(4))
)
cachedAssets = newAssets.some
newAssets
Loading
Loading