nitter/src/routes/list.nim

48 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"]
2020-06-09 14:45:21 +00:00
resp renderMain(html, request, cfg, prefs, 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
2020-06-09 14:45:21 +00:00
prefs = cookiePrefs()
2020-06-01 00:22:56 +00:00
list = await getCachedList(@"name", @"list")
timeline = await getListTimeline(list.id, getCursor())
2020-06-09 14:45:21 +00:00
vnode = renderTimelineTweets(timeline, prefs, request.path)
2020-06-01 00:22:56 +00:00
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
2020-06-09 14:45:21 +00:00
prefs = cookiePrefs()
2020-06-01 00:22:56 +00:00
list = await getCachedList(@"name", @"list")
members = await getListMembers(list, getCursor())
2020-06-09 14:45:21 +00:00
respList(list, members, renderTimelineUsers(members, prefs, request.path))
2020-06-01 00:22:56 +00:00
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)