nitter/src/routes/list.nim

52 lines
1.6 KiB
Nim
Raw Normal View History

2021-12-27 01:37:38 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
2021-10-02 08:13:56 +00:00
import strutils, uri
2019-09-20 23:08:30 +00:00
import jester
import router_utils
2021-12-20 02:11:12 +00:00
import ".."/[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
2021-10-02 08:13:56 +00:00
template respList*(list, timeline, title, vnode: typed) =
2020-06-01 00:22:56 +00:00
if list.id.len == 0:
2021-10-02 08:13:56 +00:00
resp Http404, showError("List \"" & @"id" & "\" not found", cfg)
2020-06-01 00:22:56 +00:00
let
html = renderList(vnode, timeline.query, list)
2021-10-02 08:13:56 +00:00
rss = "/i/lists/$1/rss" % [@"id"]
2020-06-01 00:22:56 +00:00
2021-10-02 08:13:56 +00:00
resp renderMain(html, request, cfg, prefs, titleText=title, rss=rss, banner=list.banner)
2019-09-20 23:08:30 +00:00
proc createListRouter*(cfg: Config) =
router list:
2021-10-02 08:13:56 +00:00
get "/@name/lists/@slug/?":
2019-09-20 23:08:30 +00:00
cond '.' notin @"name"
2020-06-01 00:22:56 +00:00
cond @"name" != "i"
2021-10-02 08:13:56 +00:00
cond @"slug" != "memberships"
let
slug = decodeUrl(@"slug")
list = await getCachedList(@"name", slug)
if list.id.len == 0:
resp Http404, showError("List \"" & @"slug" & "\" not found", cfg)
redirect("/i/lists/" & list.id)
get "/i/lists/@id/?":
cond '.' notin @"id"
2020-06-01 00:22:56 +00:00
let
2020-06-09 14:45:21 +00:00
prefs = cookiePrefs()
2021-10-02 08:13:56 +00:00
list = await getCachedList(id=(@"id"))
title = "@" & list.username & "/" & list.name
2020-06-01 00:22:56 +00:00
timeline = await getListTimeline(list.id, getCursor())
2020-06-09 14:45:21 +00:00
vnode = renderTimelineTweets(timeline, prefs, request.path)
2021-10-02 08:13:56 +00:00
respList(list, timeline, title, vnode)
2019-09-20 23:08:30 +00:00
2021-10-02 08:13:56 +00:00
get "/i/lists/@id/members":
cond '.' notin @"id"
2020-06-01 00:22:56 +00:00
let
2020-06-09 14:45:21 +00:00
prefs = cookiePrefs()
2021-10-02 08:13:56 +00:00
list = await getCachedList(id=(@"id"))
title = "@" & list.username & "/" & list.name
members = await getListMembers(list, getCursor())
2021-10-02 08:13:56 +00:00
respList(list, members, title, renderTimelineUsers(members, prefs, request.path))