nitter/src/routes/search.nim

36 lines
1.1 KiB
Nim
Raw Normal View History

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:
get "/search/?":
if @"q".len > 200:
2019-09-13 21:28:20 +00:00
resp Http400, showError("Search input too long.", cfg.title)
2019-09-19 04:15:21 +00:00
let prefs = cookiePrefs()
let query = initQuery(params(request))
2019-09-13 20:24:58 +00:00
case query.kind
2019-09-20 23:08:30 +00:00
of userSearch:
if "," in @"q":
redirect("/" & @"q")
2019-09-13 20:24:58 +00:00
let users = await getSearch[Profile](query, @"after", getAgent())
2019-09-20 20:56:27 +00:00
resp renderMain(renderUserSearch(users, prefs), request, cfg.title)
2019-09-13 20:24:58 +00:00
of custom:
let tweets = await getSearch[Tweet](query, @"after", getAgent())
let rss = "/search/rss?" & genQueryUrl(query)
resp renderMain(renderTweetSearch(tweets, prefs, getPath()), request,
cfg.title, rss=rss)
2019-09-13 20:24:58 +00:00
else:
halt Http404, showError("Invalid search", cfg.title)
2019-09-23 14:12:20 +00:00
get "/hashtag/@hash":
redirect("/search?q=" & encodeUrl("#" & @"hash"))