Add user search
This commit is contained in:
30
src/routes/search.nim
Normal file
30
src/routes/search.nim
Normal file
@@ -0,0 +1,30 @@
|
||||
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)
|
||||
|
||||
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
|
||||
@@ -3,14 +3,14 @@ import asyncdispatch, strutils, sequtils, uri
|
||||
import jester
|
||||
|
||||
import router_utils
|
||||
import ".."/[api, prefs, types, utils, cache, formatters, agents, search]
|
||||
import ../views/[general, profile, timeline, status]
|
||||
import ".."/[api, prefs, types, utils, cache, formatters, agents, query]
|
||||
import ../views/[general, profile, timeline, status, search]
|
||||
|
||||
include "../views/rss.nimf"
|
||||
|
||||
export uri, sequtils
|
||||
export router_utils
|
||||
export api, cache, formatters, search, agents
|
||||
export api, cache, formatters, query, agents
|
||||
export profile, timeline, status
|
||||
|
||||
type ProfileTimeline = (Profile, Timeline, seq[GalleryPhoto])
|
||||
@@ -33,7 +33,7 @@ proc fetchSingleTimeline*(name, after, agent: string;
|
||||
(profile, timeline) = await getProfileAndTimeline(name, agent, after)
|
||||
cache(profile)
|
||||
else:
|
||||
var timelineFut = getTimelineSearch(get(query), after, agent)
|
||||
var timelineFut = getSearch[Tweet](get(query), after, agent)
|
||||
if cachedProfile.isNone:
|
||||
profile = await getCachedProfile(name, agent)
|
||||
timeline = await timelineFut
|
||||
@@ -49,7 +49,7 @@ proc fetchMultiTimeline*(names: seq[string]; after, agent: string;
|
||||
else:
|
||||
q = some(Query(kind: multi, fromUser: names, excludes: @["replies"]))
|
||||
|
||||
return await getTimelineSearch(get(q), after, agent)
|
||||
return await getSearch[Tweet](get(q), after, agent)
|
||||
|
||||
proc showTimeline*(name, after: string; query: Option[Query];
|
||||
prefs: Prefs; path, title, rss: string): Future[string] {.async.} =
|
||||
|
||||
Reference in New Issue
Block a user