Skip to content

Commit

Permalink
quick mod user search
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jul 1, 2024
1 parent b25db91 commit c04bf4c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/controllers/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ final class User(
apiGames(u, GameFilter.All.name, 1)
)

def search(term: String) = Open: _ ?=>
UserStr.read(term) match
case Some(username) => Redirect(routes.User.show(username)).toFuccess
case _ if isGrantedOpt(_.UserSearch) => Redirect(s"${routes.Mod.search}?q=$term").toFuccess
case _ => notFound

private def renderShow(u: UserModel, status: Results.Status = Results.Ok)(using Context): Fu[Result] =
if HTTPRequest.isSynchronousHttp(ctx.req)
then
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ GET /@/:username/:filterName controllers.User.games(username: UserStr,
GET /@/:username controllers.User.show(username: UserStr)
GET /player/myself controllers.User.myself
GET /player/opponents controllers.User.opponents
GET /player/search/:term controllers.User.search(term: String)
GET /player controllers.User.list
GET /player/top/:nb/:perfKey controllers.User.topNb(nb: Int, perfKey: PerfKey)
GET /api/player/top/:nb/:perfKey controllers.User.topNbApi(nb: Int, perfKey: PerfKey)
Expand Down
3 changes: 2 additions & 1 deletion ui/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function execute(q: string) {
// 5kr1/p1p2p2/2b2Q2/3q2r1/2p4p/2P4P/P2P1PP1/1R1K3R b - - 1 23
if (q.match(/^([1-8pnbrqk]+\/){7}.*/i))
return (location.href = '/analysis/standard/' + q.replace(/ /g, '_'));
location.href = '/@/' + q;
if (q.match(/^[a-zA-Z0-9_-]{2,30}$/)) location.href = '/@/' + q;
else location.href = '/player/search/' + q;
}

function command(q: string) {
Expand Down

0 comments on commit c04bf4c

Please sign in to comment.