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

draft branch for bin/deploy to testy. please ignore #16349

Draft
wants to merge 361 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
361 commits
Select commit Hold shift + click to select a range
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
39505c7
separate ask out from unrelated stuff in canary
schlawg Sep 25, 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
7af16a3
murge
schlawg Oct 22, 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
96f36fd
Merge remote-tracking branch 'upstream/master' into ask
schlawg Oct 27, 2024
2a09193
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Oct 27, 2024
f72060e
murge
schlawg Nov 6, 2024
e2dc93c
Merge remote-tracking branch 'upstream/master' into ask
schlawg Nov 6, 2024
f2a2d8c
Merge branch 'local-play' into testy-bot-studio
schlawg Nov 6, 2024
7983b26
prettier
schlawg Nov 6, 2024
9f13de3
make tsc promise rejection fatal
schlawg Nov 6, 2024
e647454
add french language to voice rec
schlawg Dec 7, 2024
da0f9ac
fix package.json
schlawg Dec 7, 2024
0dea52c
swap static image for paused video player
schlawg Dec 14, 2024
16f0d54
close button style tweaks
schlawg Dec 14, 2024
369a67e
remove Seq
schlawg Dec 15, 2024
72eaae1
merge pinned streamer change for preview on testy
schlawg Dec 16, 2024
8872b50
comment out "ongoing" requirement to facilitate testing
schlawg Dec 16, 2024
916b6e9
resolve branch conflict
schlawg Dec 16, 2024
767d723
aaarmstark ideas
schlawg Dec 18, 2024
53ac34e
neutral look
schlawg Dec 18, 2024
a05b380
slightly less hilite on hover
schlawg Dec 18, 2024
af6e51d
remove youtube play button
schlawg Dec 19, 2024
ecbc689
aaarmstarks play button masterpiece continues to evolve
schlawg Dec 20, 2024
ae0b359
aaarmstark's masterpiece continues to evolve
schlawg Dec 20, 2024
2d63d7b
murge
schlawg Dec 20, 2024
fca5ce9
murge
schlawg Dec 26, 2024
c88fa47
murge
schlawg Dec 30, 2024
cddeed1
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Dec 30, 2024
6cc9ff4
dasher polls
schlawg Dec 31, 2024
714f336
.
schlawg Dec 31, 2024
83e57ae
troubleshoot x-forwarded-for problem
schlawg Dec 31, 2024
74c4d03
murge
schlawg Dec 31, 2024
10762f7
murge
schlawg Dec 31, 2024
89f1555
revert forwarded-for debugging
schlawg Dec 31, 2024
50ddb48
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Jan 1, 2025
7e59297
analysis button fixes
schlawg Jan 1, 2025
5eb1f9c
murge
schlawg Jan 1, 2025
80c01a4
fix analyse board
schlawg Jan 1, 2025
ae32257
remove logging
schlawg Jan 2, 2025
c1e8a30
use container query for cosmetics
schlawg Jan 2, 2025
8f2b92b
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jan 2, 2025
a3ae587
zerofish 0.0.30
schlawg Jan 2, 2025
87472bd
zerofish 0.0.30
schlawg Jan 2, 2025
249404d
fix threefold, add json, add move tracing & reports
schlawg Jan 5, 2025
e4a8679
fix linked chessground
schlawg Jan 5, 2025
f4d5c8b
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Jan 5, 2025
ac74ec0
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Jan 5, 2025
a9dd575
combined filters WIP
schlawg Jan 5, 2025
293ad87
eradicate threefolds
schlawg Jan 6, 2025
c9387e3
bin/deploy wtf?
schlawg Jan 6, 2025
a50b48c
faceted filters (no db upgrade yet)
schlawg Jan 10, 2025
5619a95
split opening books by color
schlawg Jan 10, 2025
8ff0fd9
fix pgn crlf, add db migration
schlawg Jan 11, 2025
6c049fa
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Jan 11, 2025
242a9fa
fix migration issue
schlawg Jan 11, 2025
a2474f4
fix server build error, optimize folderSize, experimental _html
schlawg Jan 11, 2025
c8afba5
fix windows
schlawg Jan 12, 2025
8d03be4
save game progress & murge
schlawg Jan 15, 2025
9d99dd0
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Jan 15, 2025
94d37e9
troubleshoot iOS < 10 oauth button
schlawg Jan 15, 2025
d26c9d1
scalafmt
schlawg Jan 15, 2025
20379e4
fix init bug
schlawg Jan 15, 2025
2ab6a22
inline the oauth button script
schlawg Jan 15, 2025
49f6341
allow inline-only modules, use it for oauth button
schlawg Jan 15, 2025
56a2ed6
re-add 'unsafe-inline' and this time try it inlined
schlawg Jan 15, 2025
84f95a3
test inline oauth script
schlawg Jan 15, 2025
c5620b6
to be honest i have not idea what is in this commit
schlawg Jan 16, 2025
302beda
cosmedits
schlawg Jan 16, 2025
17db4e0
move localGame.ts to game and board hashing to chess
schlawg Jan 17, 2025
909ff8f
bugfixes and prepare for local.db
schlawg Jan 17, 2025
ee533a7
deps
schlawg Jan 17, 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
3 changes: 3 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 @@ -57,6 +58,7 @@ final class Env(
val tournament: lila.tournament.Env = wire[lila.tournament.Env]
val swiss: lila.swiss.Env = wire[lila.swiss.Env]
val mod: lila.mod.Env = wire[lila.mod.Env]
val ask: lila.ask.Env = wire[lila.ask.Env]
val team: lila.team.Env = wire[lila.team.Env]
val teamSearch: lila.teamSearch.Env = wire[lila.teamSearch.Env]
val forum: lila.forum.Env = wire[lila.forum.Env]
Expand Down Expand Up @@ -94,6 +96,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
2 changes: 2 additions & 0 deletions app/LilaComponents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ final class LilaComponents(
lazy val analyse: Analyse = wire[Analyse]
lazy val api: Api = wire[Api]
lazy val appealC: appeal.Appeal = wire[appeal.Appeal]
lazy val ask: Ask = wire[Ask]
lazy val auth: Auth = wire[Auth]
lazy val feed: Feed = wire[Feed]
lazy val playApi: PlayApi = wire[PlayApi]
Expand All @@ -126,6 +127,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
128 changes: 128 additions & 0 deletions app/controllers/Ask.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package controllers

import play.api.data.Form
import play.api.data.Forms.single
import views.*

import lila.app.{ given, * }
import lila.core.id.AskId
import lila.core.ask.Ask

final class Ask(env: Env) extends LilaController(env):

def view(aid: AskId, view: Option[String], tally: Boolean) = Open: _ ?=>
env.ask.repo.getAsync(aid).flatMap {
case Some(ask) => Ok.snip(views.askUi.renderOne(ask, intVec(view), tally))
case _ => fuccess(NotFound(s"Ask $aid not found"))
}

def picks(aid: AskId, picks: Option[String], view: Option[String], anon: Boolean) = OpenBody: _ ?=>
effectiveId(aid, anon).flatMap:
case Some(id) =>
val setPicks = () =>
env.ask.repo.setPicks(aid, id, intVec(picks)).map {
case Some(ask) => Ok.snip(views.askUi.renderOne(ask, intVec(view)))
case _ => NotFound(s"Ask $aid not found")
}
feedbackForm
.bindFromRequest()
.fold(
_ => setPicks(),
text =>
setPicks() >> env.ask.repo.setForm(aid, id, text.some).flatMap {
case Some(ask) => Ok.snip(views.askUi.renderOne(ask, intVec(view)))
case _ => NotFound(s"Ask $aid not found")
}
)
case _ => authenticationFailed

def form(aid: AskId, view: Option[String], anon: Boolean) = OpenBody: _ ?=>
effectiveId(aid, anon).flatMap:
case Some(id) =>
env.ask.repo.setForm(aid, id, feedbackForm.bindFromRequest().value).map {
case Some(ask) => Ok.snip(views.askUi.renderOne(ask, intVec(view)))
case _ => NotFound(s"Ask $aid not found")
}
case _ => authenticationFailed

def unset(aid: AskId, view: Option[String], anon: Boolean) = Open: _ ?=>
effectiveId(aid, anon).flatMap:
case Some(id) =>
env.ask.repo
.unset(aid, id)
.map:
case Some(ask) => Ok.snip(views.askUi.renderOne(ask, intVec(view)))
case _ => NotFound(s"Ask $aid not found")

case _ => authenticationFailed

def admin(aid: AskId) = Auth: _ ?=>
env.ask.repo
.getAsync(aid)
.map:
case Some(ask) => Ok.snip(views.askAdminUi.renderOne(ask))
case _ => NotFound(s"Ask $aid not found")

def byUser(username: UserStr) = Auth: _ ?=>
me ?=>
Ok.async:
for
user <- env.user.lightUser(username.id)
asks <- env.ask.repo.byUser(username.id)
if (me.is(user)) || isGranted(_.ModerateForum)
yield views.askAdminUi.show(asks, user.get)

def json(aid: AskId) = Auth: _ ?=>
me ?=>
env.ask.repo
.getAsync(aid)
.map:
case Some(ask) =>
if (me.is(ask.creator)) || isGranted(_.ModerateForum) then JsonOk(ask.toJson)
else JsonBadRequest(jsonError(s"Not authorized to view ask $aid"))
case _ => JsonBadRequest(jsonError(s"Ask $aid not found"))

def delete(aid: AskId) = Auth: _ ?=>
me ?=>
env.ask.repo
.getAsync(aid)
.map:
case Some(ask) =>
if (me.is(ask.creator)) || isGranted(_.ModerateForum) then
env.ask.repo.delete(aid)
Ok
else Unauthorized
case _ => NotFound(s"Ask id ${aid} not found")

def conclude(aid: AskId) = authorized(aid, env.ask.repo.conclude)

def reset(aid: AskId) = authorized(aid, env.ask.repo.reset)

private def effectiveId(aid: AskId, anon: Boolean)(using ctx: Context) =
ctx.myId match
case Some(u) => fuccess((if anon then Ask.anonHash(u.toString, aid) else u.toString).some)
case _ =>
env.ask.repo
.isOpen(aid)
.map:
case true => Ask.anonHash(ctx.ip.toString, aid).some
case false => none[String]

private def authorized(aid: AskId, action: AskId => Fu[Option[lila.core.ask.Ask]]) = Auth: _ ?=>
me ?=>
env.ask.repo
.getAsync(aid)
.flatMap:
case Some(ask) =>
if (me.is(ask.creator)) || isGranted(_.ModerateForum) then
action(ask._id).map:
case Some(newAsk) => Ok.snip(views.askUi.renderOne(newAsk))
case _ => NotFound(s"Ask id ${aid} not found")
else fuccess(Unauthorized)
case _ => fuccess(NotFound(s"Ask id $aid not found"))

private def intVec(param: Option[String]) =
param.map(_.split('-').filter(_.nonEmpty).map(_.toInt).toVector)

private val feedbackForm =
Form[String](single("text" -> lila.common.Form.cleanNonEmptyText(maxLength = 80)))
7 changes: 4 additions & 3 deletions app/controllers/Feed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ final class Feed(env: Env) extends LilaController(env):
Reasonable(page):
for
updates <- env.feed.paginator.recent(isGrantedOpt(_.Feed), page)
renderedPage <- renderPage(views.feed.index(updates))
hasAsks <- env.ask.repo.preload(updates.currentPageResults.map(_.content.value)*)
renderedPage <- renderPage(views.feed.index(updates, hasAsks))
yield Ok(renderedPage)

def createForm = Secure(_.Feed) { _ ?=> _ ?=>
Expand All @@ -29,12 +30,12 @@ final class Feed(env: Env) extends LilaController(env):
}

def edit(id: String) = Secure(_.Feed) { _ ?=> _ ?=>
Found(api.get(id)): up =>
Found(api.edit(id)): up =>
Ok.async(views.feed.edit(api.form(up.some), up))
}

def update(id: String) = SecureBody(_.Feed) { _ ?=> _ ?=>
Found(api.get(id)): from =>
Found(api.edit(id)): from =>
bindForm(api.form(from.some))(
err => BadRequest.async(views.feed.edit(err, from)),
data => api.set(data.toUpdate(from.id.some)).inject(Redirect(routes.Feed.edit(from.id)).flashSuccess)
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/ForumTopic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ final class ForumTopic(env: Env) extends LilaController(env) with ForumControlle
.soUse: _ ?=>
forms.postWithCaptcha(inOwnTeam).some
_ <- env.user.lightUserApi.preloadMany(posts.currentPageResults.flatMap(_.post.userId))
(_, hasAsks) <- env.user.lightUserApi
.preloadMany(posts.currentPageResults.flatMap(_.post.userId))
.zip(env.ask.repo.preload(posts.currentPageResults.map(_.post.text)*))
res <-
if canRead then
Ok.page(
views.forum.topic.show(categ, topic, posts, form, unsub, canModCateg, None, replyBlocked)
views.forum.topic
.show(categ, topic, posts, form, unsub, canModCateg, None, replyBlocked, hasAsks)
).map(_.withCanonical(routes.ForumTopic.show(categ.id, topic.slug, page)))
else notFound
yield res
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
Loading