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
|
2019-09-20 23:08:30 +00:00
|
|
|
import ".."/[query, types, api, agents]
|
2019-09-13 20:24:58 +00:00
|
|
|
import ../views/[general, search]
|
|
|
|
|
|
|
|
export search
|
|
|
|
|
|
|
|
proc createSearchRouter*(cfg: Config) =
|
|
|
|
router search:
|
2019-09-28 01:22:46 +00:00
|
|
|
get "/search/?":
|
2019-09-30 20:24:01 +00:00
|
|
|
if @"q".len > 200:
|
2019-10-21 03:19:00 +00:00
|
|
|
resp Http400, showError("Search input too long.", cfg)
|
2019-09-13 21:28:20 +00:00
|
|
|
|
2019-09-19 04:15:21 +00:00
|
|
|
let prefs = cookiePrefs()
|
2019-09-18 23:01:47 +00:00
|
|
|
let query = initQuery(params(request))
|
2019-09-13 20:24:58 +00:00
|
|
|
|
|
|
|
case query.kind
|
2019-10-08 11:45:47 +00:00
|
|
|
of users:
|
2019-09-30 20:24:01 +00:00
|
|
|
if "," in @"q":
|
|
|
|
redirect("/" & @"q")
|
2019-10-08 13:15:47 +00:00
|
|
|
let users = await getSearch[Profile](query, @"max_position", getAgent())
|
2019-10-21 03:19:00 +00:00
|
|
|
resp renderMain(renderUserSearch(users, prefs), request, cfg)
|
2019-10-08 11:54:20 +00:00
|
|
|
of tweets:
|
2019-10-08 13:15:47 +00:00
|
|
|
let tweets = await getSearch[Tweet](query, @"max_position", getAgent())
|
2019-09-28 01:22:46 +00:00
|
|
|
let rss = "/search/rss?" & genQueryUrl(query)
|
2019-10-21 03:19:00 +00:00
|
|
|
resp renderMain(renderTweetSearch(tweets, prefs, getPath()),
|
|
|
|
request, cfg, rss=rss)
|
2019-09-13 20:24:58 +00:00
|
|
|
else:
|
2019-10-21 05:59:22 +00:00
|
|
|
resp Http404, showError("Invalid search", cfg)
|
2019-09-23 14:12:20 +00:00
|
|
|
|
|
|
|
get "/hashtag/@hash":
|
2019-09-30 20:24:01 +00:00
|
|
|
redirect("/search?q=" & encodeUrl("#" & @"hash"))
|