streak wip

tramadol
Thibault Duplessis 2021-03-26 21:19:18 +01:00
parent 68536afe29
commit fa3ef2c3df
4 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,75 @@
package controllers
import play.api.mvc._
import views._
import lila.api.Context
import lila.app._
final class Storm(env: Env)(implicit mat: akka.stream.Materializer) extends LilaController(env) {
def home =
Open { implicit ctx =>
NoBot {
env.storm.selector.apply flatMap { puzzles =>
ctx.userId.?? { u => env.storm.highApi.get(u) dmap some } map { high =>
NoCache {
Ok(
views.html.storm.home(
env.storm.json(puzzles, ctx.me),
env.storm.json.pref(ctx.pref),
high
)
)
}
}
}
}
}
def record =
OpenBody { implicit ctx =>
NoBot {
implicit val req = ctx.body
env.storm.forms.run
.bindFromRequest()
.fold(
_ => fuccess(none),
data => env.storm.dayApi.addRun(data, ctx.me)
) map env.storm.json.newHigh map JsonOk
}
}
def dashboard(page: Int) =
Auth { implicit ctx => me =>
renderDashboardOf(me, page)
}
def dashboardOf(username: String, page: Int) =
Open { implicit ctx =>
env.user.repo.enabledNamed(username).flatMap {
_ ?? {
renderDashboardOf(_, page)
}
}
}
private def renderDashboardOf(user: lila.user.User, page: Int)(implicit ctx: Context): Fu[Result] =
env.storm.dayApi.history(user.id, page) flatMap { history =>
env.storm.highApi.get(user.id) map { high =>
Ok(views.html.storm.dashboard(user, history, high))
}
}
def apiDashboardOf(username: String, days: Int) =
Open { implicit ctx =>
lila.user.User.validateId(username) ?? { userId =>
if (days < 0 || days > 365) notFoundJson("Invalid days parameter")
else
((days > 0) ?? env.storm.dayApi.apiHistory(userId, days)) zip env.storm.highApi.get(userId) map {
case (history, high) =>
Ok(env.storm.json.apiDashboard(high, history))
}
}
}
}

View File

@ -122,6 +122,8 @@ GET /racer/:id controllers.Racer.show(id: String)
GET /racer/:id/rematch controllers.Racer.rematch(id: String)
POST /racer/lobby controllers.Racer.lobby
GET /streak controllers.Streak.home
# User Analysis
GET /analysis/help controllers.UserAnalysis.help
GET /analysis/*something controllers.UserAnalysis.parseArg(something: String)

View File

@ -0,0 +1,29 @@
{
"name": "racer",
"version": "2.0.0",
"private": true,
"description": "lichess.org puzzle streak",
"keywords": [
"chess",
"lichess",
"puzzle",
"streak"
],
"author": "Thibault Duplessis",
"license": "AGPL-3.0-or-later",
"devDependencies": {
"@build/rollupProject": "2.0.0",
"@types/lichess": "2.0.0"
},
"dependencies": {
"chessops": "^0.8.1",
"chessground": "^7.11.1",
"snabbdom": "^0.7.4",
"common": "2.0.0",
"puz": "2.0.0"
},
"scripts": {
"dev": "rollup --config",
"prod": "rollup --config --config-prod"
}
}

View File

@ -0,0 +1,9 @@
import { rollupProject } from '@build/rollupProject';
export default rollupProject({
main: {
name: 'LichessStreak',
input: 'src/main.ts',
output: 'streak',
},
});