nitter/src/routes/rss.nim

56 lines
1.8 KiB
Nim
Raw Normal View History

import asyncdispatch, strutils
import jester
import router_utils, timeline
2019-09-13 21:28:20 +00:00
import ".."/[cache, agents, query]
import ../views/general
include "../views/rss.nimf"
proc showRss*(name, hostname: string; query: Query): Future[string] {.async.} =
let (profile, timeline) =
await fetchSingleTimeline(name, "", getAgent(), query, media=false)
if timeline != nil:
return renderTimelineRss(timeline, profile, hostname)
template respRss*(rss: typed) =
if rss.len == 0:
2019-10-21 05:59:22 +00:00
resp Http404, showError("User \"" & @"name" & "\" not found", cfg)
resp rss, "application/rss+xml;charset=utf-8"
proc createRssRouter*(cfg: Config) =
router rss:
get "/search/rss":
if @"q".len > 200:
resp Http400, showError("Search input too long.", cfg)
let query = initQuery(params(request))
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))
get "/@name/rss":
cond '.' notin @"name"
respRss(await showRss(@"name", cfg.hostname, Query()))
get "/@name/with_replies/rss":
cond '.' notin @"name"
respRss(await showRss(@"name", cfg.hostname, getReplyQuery(@"name")))
get "/@name/media/rss":
cond '.' notin @"name"
respRss(await showRss(@"name", cfg.hostname, getMediaQuery(@"name")))
2019-09-20 01:35:27 +00:00
get "/@name/search/rss":
cond '.' notin @"name"
respRss(await showRss(@"name", cfg.hostname, initQuery(params(request), name=(@"name"))))
2019-09-20 23:08:30 +00:00
get "/@name/lists/@list/rss":
cond '.' notin @"name"
2019-10-23 07:03:15 +00:00
let list = await getListTimeline(@"name", @"list", "", getAgent(), media=false)
respRss(renderListRss(list.content, @"name", @"list", cfg.hostname))