2019-09-18 23:01:47 +00:00
|
|
|
import strutils, sequtils, uri
|
2019-09-13 20:24:58 +00:00
|
|
|
|
|
|
|
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":
|
2019-09-13 21:28:20 +00:00
|
|
|
if @"text".len > 200:
|
|
|
|
resp Http400, showError("Search input too long.", cfg.title)
|
|
|
|
|
2019-09-19 02:51:17 +00:00
|
|
|
let prefs = Prefs()
|
2019-09-18 23:01:47 +00:00
|
|
|
let query = initQuery(params(request))
|
2019-09-13 20:24:58 +00:00
|
|
|
|
|
|
|
case query.kind
|
|
|
|
of users:
|
2019-09-17 19:01:44 +00:00
|
|
|
if "," in @"text":
|
|
|
|
redirect("/" & @"text")
|
2019-09-13 20:24:58 +00:00
|
|
|
let users = await getSearch[Profile](query, @"after", getAgent())
|
2019-09-19 02:51:17 +00:00
|
|
|
resp renderMain(renderUserSearch(users, prefs), prefs, cfg.title, path=getPath())
|
2019-09-13 20:24:58 +00:00
|
|
|
of custom:
|
|
|
|
let tweets = await getSearch[Tweet](query, @"after", getAgent())
|
2019-09-19 02:51:17 +00:00
|
|
|
resp renderMain(renderTweetSearch(tweets, prefs, getPath()), prefs, cfg.title, path=getPath())
|
2019-09-13 20:24:58 +00:00
|
|
|
else:
|
2019-09-17 19:01:44 +00:00
|
|
|
resp Http404, showError("Invalid search.", cfg.title)
|