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-10-21 03:19:00 +00:00
|
|
|
proc showRss*(name, hostname: string; query: Query): Future[string] {.async.} =
|
2019-12-04 04:58:18 +00:00
|
|
|
var profile: Profile
|
|
|
|
var timeline: Timeline
|
|
|
|
let names = getNames(name)
|
|
|
|
if names.len == 1:
|
|
|
|
(profile, timeline) =
|
|
|
|
await fetchSingleTimeline(names[0], "", getAgent(), query, media=false)
|
|
|
|
else:
|
|
|
|
timeline = await fetchMultiTimeline(names, "", getAgent(), query, media=false)
|
|
|
|
# this is kinda dumb
|
|
|
|
profile = Profile(
|
|
|
|
username: name,
|
|
|
|
fullname: names.join(" | "),
|
|
|
|
userpic: "https://abs.twimg.com/sticky/default_profile_images/default_profile.png"
|
|
|
|
)
|
2019-10-21 21:12:40 +00:00
|
|
|
|
2019-10-07 13:52:44 +00:00
|
|
|
if timeline != nil:
|
2019-12-04 04:58:18 +00:00
|
|
|
return renderTimelineRss(timeline, profile, hostname, multi=(names.len > 1))
|
2019-09-15 10:10:43 +00:00
|
|
|
|
|
|
|
template respRss*(rss: typed) =
|
|
|
|
if rss.len == 0:
|
2019-10-21 05:59:22 +00:00
|
|
|
resp Http404, showError("User \"" & @"name" & "\" not found", cfg)
|
2019-09-15 10:10:43 +00:00
|
|
|
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-10-21 03:19:00 +00:00
|
|
|
resp Http400, showError("Search input too long.", cfg)
|
2019-09-28 01:22:46 +00:00
|
|
|
|
|
|
|
let query = initQuery(params(request))
|
2019-10-08 11:54:20 +00:00
|
|
|
if query.kind != tweets:
|
2019-10-21 03:19:00 +00:00
|
|
|
resp Http400, showError("Only Tweet searches are allowed for RSS feeds.", cfg)
|
2019-09-28 01:22:46 +00:00
|
|
|
|
2019-10-21 21:12:40 +00:00
|
|
|
let tweets = await getSearch[Tweet](query, "", getAgent(), media=false)
|
2019-10-21 03:19:00 +00:00
|
|
|
respRss(renderSearchRss(tweets.content, query.text, genQueryUrl(query), cfg.hostname))
|
2019-09-28 01:22:46 +00:00
|
|
|
|
2019-09-15 10:10:43 +00:00
|
|
|
get "/@name/rss":
|
|
|
|
cond '.' notin @"name"
|
2019-10-21 03:19:00 +00:00
|
|
|
respRss(await showRss(@"name", cfg.hostname, Query()))
|
2019-09-15 10:10:43 +00:00
|
|
|
|
2019-10-07 15:46:16 +00:00
|
|
|
get "/@name/with_replies/rss":
|
2019-09-15 10:10:43 +00:00
|
|
|
cond '.' notin @"name"
|
2019-10-21 03:19:00 +00:00
|
|
|
respRss(await showRss(@"name", cfg.hostname, getReplyQuery(@"name")))
|
2019-09-15 10:10:43 +00:00
|
|
|
|
|
|
|
get "/@name/media/rss":
|
|
|
|
cond '.' notin @"name"
|
2019-10-21 03:19:00 +00:00
|
|
|
respRss(await showRss(@"name", cfg.hostname, getMediaQuery(@"name")))
|
2019-09-20 01:35:27 +00:00
|
|
|
|
|
|
|
get "/@name/search/rss":
|
|
|
|
cond '.' notin @"name"
|
2019-10-21 03:19:00 +00:00
|
|
|
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)
|
2019-10-21 03:19:00 +00:00
|
|
|
respRss(renderListRss(list.content, @"name", @"list", cfg.hostname))
|