2019-09-15 10:10:43 +00:00
|
|
|
import asyncdispatch, strutils
|
|
|
|
|
|
|
|
import jester
|
|
|
|
|
|
|
|
import router_utils, timeline
|
2019-09-13 21:28:20 +00:00
|
|
|
import ".."/[cache, agents, query]
|
2019-09-15 10:10:43 +00:00
|
|
|
import ../views/general
|
|
|
|
|
|
|
|
include "../views/rss.nimf"
|
|
|
|
|
2019-09-19 00:23:22 +00:00
|
|
|
proc showRss*(name: string; query: Query): Future[string] {.async.} =
|
2019-09-15 10:10:43 +00:00
|
|
|
let (profile, timeline, _) = await fetchSingleTimeline(name, "", getAgent(), query)
|
|
|
|
return renderTimelineRss(timeline.content, profile)
|
|
|
|
|
|
|
|
template respRss*(rss: typed) =
|
|
|
|
if rss.len == 0:
|
|
|
|
resp Http404, showError("User \"" & @"name" & "\" not found", cfg.title)
|
|
|
|
resp rss, "application/rss+xml;charset=utf-8"
|
|
|
|
|
|
|
|
proc createRssRouter*(cfg: Config) =
|
|
|
|
router rss:
|
2019-09-28 01:22:46 +00:00
|
|
|
get "/search/rss":
|
2019-09-30 20:24:01 +00:00
|
|
|
if @"q".len > 200:
|
2019-09-28 01:22:46 +00:00
|
|
|
resp Http400, showError("Search input too long.", cfg.title)
|
|
|
|
|
|
|
|
let query = initQuery(params(request))
|
|
|
|
if query.kind != custom:
|
|
|
|
resp Http400, showError("Only Tweet searches are allowed for RSS feeds.", cfg.title)
|
|
|
|
|
|
|
|
let tweets = await getSearch[Tweet](query, "", getAgent())
|
|
|
|
respRss(renderSearchRss(tweets.content, query.text, genQueryUrl(query)))
|
|
|
|
|
2019-09-15 10:10:43 +00:00
|
|
|
get "/@name/rss":
|
|
|
|
cond '.' notin @"name"
|
2019-09-19 00:23:22 +00:00
|
|
|
respRss(await showRss(@"name", Query()))
|
2019-09-15 10:10:43 +00:00
|
|
|
|
|
|
|
get "/@name/replies/rss":
|
|
|
|
cond '.' notin @"name"
|
2019-09-19 00:23:22 +00:00
|
|
|
respRss(await showRss(@"name", getReplyQuery(@"name")))
|
2019-09-15 10:10:43 +00:00
|
|
|
|
|
|
|
get "/@name/media/rss":
|
|
|
|
cond '.' notin @"name"
|
2019-09-19 00:23:22 +00:00
|
|
|
respRss(await showRss(@"name", getMediaQuery(@"name")))
|
2019-09-20 01:35:27 +00:00
|
|
|
|
|
|
|
get "/@name/search/rss":
|
|
|
|
cond '.' notin @"name"
|
|
|
|
respRss(await showRss(@"name", initQuery(params(request), name=(@"name"))))
|
2019-09-20 23:08:30 +00:00
|
|
|
|
|
|
|
get "/@name/lists/@list/rss":
|
|
|
|
cond '.' notin @"name"
|
|
|
|
let list = await getListTimeline(@"name", @"list", getAgent(), "")
|
|
|
|
respRss(renderListRss(list.content, @"name", @"list"))
|