Support max_position for RSS feeds
This commit is contained in:
parent
9f491eee70
commit
f3aa28709a
|
@ -8,15 +8,19 @@ import ../views/general
|
|||
|
||||
include "../views/rss.nimf"
|
||||
|
||||
proc showRss*(name, hostname: string; query: Query): Future[string] {.async.} =
|
||||
proc showRss*(req: Request; hostname: string; query: Query): Future[(string, string)] {.async.} =
|
||||
var profile: Profile
|
||||
var timeline: Timeline
|
||||
let names = getNames(name)
|
||||
let
|
||||
name = req.params.getOrDefault("name")
|
||||
after = req.params.getOrDefault("max_position")
|
||||
names = getNames(name)
|
||||
|
||||
if names.len == 1:
|
||||
(profile, timeline) =
|
||||
await fetchSingleTimeline(names[0], "", getAgent(), query, media=false)
|
||||
await fetchSingleTimeline(names[0], after, getAgent(), query, media=false)
|
||||
else:
|
||||
timeline = await fetchMultiTimeline(names, "", getAgent(), query, media=false)
|
||||
timeline = await fetchMultiTimeline(names, after, getAgent(), query, media=false)
|
||||
# this is kinda dumb
|
||||
profile = Profile(
|
||||
username: name,
|
||||
|
@ -25,12 +29,14 @@ proc showRss*(name, hostname: string; query: Query): Future[string] {.async.} =
|
|||
)
|
||||
|
||||
if timeline != nil:
|
||||
return renderTimelineRss(timeline, profile, hostname, multi=(names.len > 1))
|
||||
let rss = renderTimelineRss(timeline, profile, hostname, multi=(names.len > 1))
|
||||
return (rss, timeline.minId)
|
||||
|
||||
template respRss*(rss: typed) =
|
||||
template respRss*(rss, minId) =
|
||||
if rss.len == 0:
|
||||
resp Http404, showError("User \"" & @"name" & "\" not found", cfg)
|
||||
resp rss, "application/rss+xml;charset=utf-8"
|
||||
let headers = {"Content-Type": "application/rss+xml;charset=utf-8", "Min-Id": minId}
|
||||
resp Http200, headers, rss
|
||||
|
||||
proc createRssRouter*(cfg: Config) =
|
||||
router rss:
|
||||
|
@ -42,26 +48,29 @@ proc createRssRouter*(cfg: Config) =
|
|||
if query.kind != tweets:
|
||||
resp Http400, showError("Only Tweet searches are allowed for RSS feeds.", cfg)
|
||||
|
||||
let tweets = await getSearch[Tweet](query, "", getAgent(), media=false)
|
||||
respRss(renderSearchRss(tweets.content, query.text, genQueryUrl(query), cfg.hostname))
|
||||
let tweets = await getSearch[Tweet](query, @"max_position", getAgent(), media=false)
|
||||
let rss = renderSearchRss(tweets.content, query.text, genQueryUrl(query), cfg.hostname)
|
||||
respRss(rss, tweets.minId)
|
||||
|
||||
get "/@name/rss":
|
||||
cond '.' notin @"name"
|
||||
respRss(await showRss(@"name", cfg.hostname, Query()))
|
||||
let (rss, minId) = await showRss(request, cfg.hostname, Query())
|
||||
respRss(rss, minId)
|
||||
|
||||
get "/@name/with_replies/rss":
|
||||
get "/@name/@tab/rss":
|
||||
cond '.' notin @"name"
|
||||
respRss(await showRss(@"name", cfg.hostname, getReplyQuery(@"name")))
|
||||
let query =
|
||||
case @"tab"
|
||||
of "with_replies": getReplyQuery(@"name")
|
||||
of "media": getMediaQuery(@"name")
|
||||
of "search": initQuery(params(request), name=(@"name"))
|
||||
else: Query()
|
||||
|
||||
get "/@name/media/rss":
|
||||
cond '.' notin @"name"
|
||||
respRss(await showRss(@"name", cfg.hostname, getMediaQuery(@"name")))
|
||||
|
||||
get "/@name/search/rss":
|
||||
cond '.' notin @"name"
|
||||
respRss(await showRss(@"name", cfg.hostname, initQuery(params(request), name=(@"name"))))
|
||||
let (rss, minId) = await showRss(request, cfg.hostname, query)
|
||||
respRss(rss, minId)
|
||||
|
||||
get "/@name/lists/@list/rss":
|
||||
cond '.' notin @"name"
|
||||
let list = await getListTimeline(@"name", @"list", "", getAgent(), media=false)
|
||||
respRss(renderListRss(list.content, @"name", @"list", cfg.hostname))
|
||||
let list = await getListTimeline(@"name", @"list", @"max_position", getAgent(), media=false)
|
||||
let rss = renderListRss(list.content, @"name", @"list", cfg.hostname)
|
||||
respRss(rss, list.minId)
|
||||
|
|
Loading…
Reference in New Issue