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
2022-06-04 00:18:26 +00:00
import strutils, strformat, 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]
2021-10-02 08:13:56 +00:00
template respList*(list, timeline, title, vnode: typed) =
2021-12-30 22:47:31 +00:00
if list.id.len == 0 or list.name.len == 0:
2022-06-04 00:18:26 +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)
2022-06-04 00:18:26 +00:00
rss = &"""/i/lists/{@"id"}/rss"""
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
2022-06-04 00:18:26 +00:00
proc title*(list: List): string =
&"@{list.username}/{list.name}"
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:
2022-06-04 00:18:26 +00:00
resp Http404, showError(&"""List "{@"slug"}" not found""", cfg)
redirect(&"/i/lists/{list.id}")
2021-10-02 08:13:56 +00:00
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"))
timeline = await getGraphListTweets(list.id, getCursor())
2020-06-09 14:45:21 +00:00
vnode = renderTimelineTweets(timeline, prefs, request.path)
2022-06-04 00:18:26 +00:00
respList(list, timeline, list.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"))
members = await getGraphListMembers(list, getCursor())
2022-06-04 00:18:26 +00:00
respList(list, members, list.title, renderTimelineUsers(members, prefs, request.path))