2019-09-13 20:24:58 +00:00
|
|
|
import strutils, uri
|
|
|
|
|
|
|
|
import jester
|
|
|
|
|
|
|
|
import router_utils
|
|
|
|
import ".."/[query, types, utils, api, agents]
|
|
|
|
import ../views/[general, search]
|
|
|
|
|
|
|
|
export search
|
|
|
|
|
|
|
|
proc createSearchRouter*(cfg: Config) =
|
|
|
|
router search:
|
|
|
|
get "/search":
|
|
|
|
if @"text".len == 0 or "." in @"text":
|
|
|
|
resp Http404, showError("Please enter a valid username.", cfg.title)
|
|
|
|
|
2019-09-13 21:28:20 +00:00
|
|
|
if @"text".len > 200:
|
|
|
|
resp Http400, showError("Search input too long.", cfg.title)
|
|
|
|
|
2019-09-13 20:24:58 +00:00
|
|
|
if "," in @"text":
|
|
|
|
redirect("/" & @"text")
|
|
|
|
|
|
|
|
let query = Query(kind: parseEnum[QueryKind](@"kind", custom), text: @"text")
|
|
|
|
|
|
|
|
case query.kind
|
|
|
|
of users:
|
|
|
|
let users = await getSearch[Profile](query, @"after", getAgent())
|
|
|
|
resp renderMain(renderUserSearch(users, Prefs()), Prefs(), path=getPath())
|
|
|
|
of custom:
|
|
|
|
let tweets = await getSearch[Tweet](query, @"after", getAgent())
|
|
|
|
resp renderMain(renderTweetSearch(tweets, Prefs(), getPath()), Prefs(), path=getPath())
|
|
|
|
else:
|
|
|
|
resp Http404
|