nitter/src/routes/list.nim

46 lines
1.4 KiB
Nim
Raw Normal View History

2019-09-20 23:08:30 +00:00
import strutils
import jester
import router_utils
2020-06-01 00:22:56 +00:00
import ".."/[query, types, redis_cache, api]
2019-09-20 23:08:30 +00:00
import ../views/[general, timeline, list]
2020-06-01 00:22:56 +00:00
export getListTimeline, getGraphList
2019-09-20 23:08:30 +00:00
2020-06-01 00:22:56 +00:00
template respList*(list, timeline, vnode: typed) =
if list.id.len == 0:
2019-10-21 05:59:22 +00:00
resp Http404, showError("List \"" & @"list" & "\" not found", cfg)
2020-06-01 00:22:56 +00:00
let
html = renderList(vnode, timeline.query, list)
rss = "/$1/lists/$2/rss" % [@"name", @"list"]
resp renderMain(html, request, cfg, rss=rss)
2019-09-20 23:08:30 +00:00
proc createListRouter*(cfg: Config) =
router list:
get "/@name/lists/@list/?":
2019-09-20 23:08:30 +00:00
cond '.' notin @"name"
2020-06-01 00:22:56 +00:00
cond @"name" != "i"
let
list = await getCachedList(@"name", @"list")
timeline = await getListTimeline(list.id, getCursor())
vnode = renderTimelineTweets(timeline, cookiePrefs(), request.path)
respList(list, timeline, vnode)
2019-09-20 23:08:30 +00:00
get "/@name/lists/@list/members":
cond '.' notin @"name"
2020-06-01 00:22:56 +00:00
cond @"name" != "i"
let
list = await getCachedList(@"name", @"list")
members = await getListMembers(list)
respList(list, members, renderTimelineUsers(members, cookiePrefs(), request.path))
get "/i/lists/@id/?":
2020-06-01 00:22:56 +00:00
cond '.' notin @"id"
let list = await getCachedList(id=(@"id"))
if list.id.len == 0:
resp Http404
2020-06-02 20:36:02 +00:00
await cache(list)
2020-06-01 00:22:56 +00:00
redirect("/" & list.username & "/lists/" & list.name)