nitter/src/routes/list.nim

48 lines
1.4 KiB
Nim
Raw Normal View History

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