nitter/src/routes/search.nim

47 lines
1.3 KiB
Nim
Raw Normal View History

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":
2019-09-13 21:28:20 +00:00
if @"text".len > 200:
resp Http400, showError("Search input too long.", cfg.title)
2019-09-17 19:01:44 +00:00
let kind = parseEnum[QueryKind](@"kind", custom)
var query = Query(kind: kind, text: @"text")
if @"retweets".len == 0:
query.excludes.add "nativeretweets"
else:
query.includes.add "nativeretweets"
if @"replies".len == 0:
query.excludes.add "replies"
else:
query.includes.add "replies"
2019-09-13 20:24:58 +00:00
2019-09-17 19:01:44 +00:00
for f in validFilters:
if "f-" & f in params(request):
query.filters.add f
if "e-" & f in params(request):
query.excludes.add f
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())
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:
2019-09-17 19:01:44 +00:00
resp Http404, showError("Invalid search.", cfg.title)