no more redis

This commit is contained in:
Cynthia Foxwell 2025-02-11 14:04:53 -07:00
parent be4c83bfb0
commit 5e2d126aea
Signed by: Cynosphere
SSH key fingerprint: SHA256:H3SM8ufP/uxqLwKSH7xY89TDnbR9uOHzjLoBr0tlajk
6 changed files with 46 additions and 24 deletions

View file

@ -28,6 +28,7 @@ maintained by the community.
* Image zooming/carousel (requires JavaScript)
* Up to date Twitter features, e.g. Community Notes
* Embeds for chat services on-par with services like [FxTwitter](https://github.com/FixTweet/FxTwitter) and [vxTwitter](https://github.com/dylanpdx/BetterTwitFix)
* No dependency on Redis, as it has caused ratelimiting issues, but also forcably disables RSS
## Why use Nitter?

View file

@ -9,7 +9,7 @@ import jester
import types, config, prefs, formatters, redis_cache, http_pool
import views/[general, about]
import routes/[
preferences, timeline, status, media, search, rss, list, #debug,
preferences, timeline, status, media, search, list, #rss, debug,
unsupported, embed, resolver, router_utils, home, follow, twitter_api]
const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances"
@ -35,9 +35,9 @@ setMaxHttpConns(cfg.httpMaxConns)
setHttpProxy(cfg.proxy, cfg.proxyAuth)
initAboutPage(cfg.staticDir)
waitFor initRedisPool(cfg)
stdout.write &"Connected to Redis at {cfg.redisHost}:{cfg.redisPort}\n"
stdout.flushFile
#waitFor initRedisPool(cfg)
#stdout.write &"Connected to Redis at {cfg.redisHost}:{cfg.redisPort}\n"
#stdout.flushFile
createUnsupportedRouter(cfg)
createResolverRouter(cfg)
@ -48,7 +48,7 @@ createStatusRouter(cfg)
createSearchRouter(cfg)
createMediaRouter(cfg)
createEmbedRouter(cfg)
createRssRouter(cfg)
#createRssRouter(cfg)
#createDebugRouter(cfg)
createTwitterApiRouter(cfg)
@ -93,7 +93,7 @@ routes:
extend home, ""
extend follow, ""
extend rss, ""
#extend rss, ""
extend status, ""
extend search, ""
extend timeline, ""

View file

@ -1,6 +1,6 @@
import jester
import asyncdispatch, strutils, options, router_utils, timeline
import ".."/[prefs, types, utils, redis_cache]
import ".."/[prefs, types, utils]
import ../views/[general, home, search]
export home
@ -43,7 +43,7 @@ proc createHomeRouter*(cfg: Config) =
query.kind = userList
for name in names:
let prof = await getCachedUser(name)
let prof = await getGraphUser(name)
profs &= @[prof]
resp renderMain(renderFollowing(query, profs, prefs), request, cfg, prefs)

View file

@ -4,7 +4,7 @@ import strutils, strformat, uri
import jester
import router_utils
import ".."/[types, redis_cache, api]
import ".."/[types, api]
import ../views/[general, timeline, list]
template respList*(list, timeline, title, vnode: typed) =
@ -20,6 +20,14 @@ template respList*(list, timeline, title, vnode: typed) =
proc title*(list: List): string =
&"@{list.username}/{list.name}"
proc getList*(username=""; slug=""; id=""): Future[List] {.async.} =
if id.len > 0:
result = await getGraphList(id)
else:
result = await getGraphListBySlug(username, slug)
proc createListRouter*(cfg: Config) =
router list:
get "/@name/lists/@slug/?":
@ -28,7 +36,7 @@ proc createListRouter*(cfg: Config) =
cond @"slug" != "memberships"
let
slug = decodeUrl(@"slug")
list = await getCachedList(@"name", slug)
list = await getList(@"name", slug)
if list.id.len == 0:
resp Http404, showError(&"""List "{@"slug"}" not found""", cfg)
redirect(&"/i/lists/{list.id}")
@ -37,7 +45,7 @@ proc createListRouter*(cfg: Config) =
cond '.' notin @"id"
let
prefs = cookiePrefs()
list = await getCachedList(id=(@"id"))
list = await getList(id=(@"id"))
timeline = await getGraphListTweets(list.id, getCursor())
vnode = renderTimelineTweets(timeline, prefs, request.path)
respList(list, timeline, list.title, vnode)
@ -46,6 +54,6 @@ proc createListRouter*(cfg: Config) =
cond '.' notin @"id"
let
prefs = cookiePrefs()
list = await getCachedList(id=(@"id"))
list = await getList(id=(@"id"))
members = await getGraphListMembers(list, getCursor())
respList(list, members, list.title, renderTimelineUsers(members, prefs, request.path))

View file

@ -3,13 +3,13 @@ import asyncdispatch, strutils, sequtils, uri, options, times
import jester, karax/vdom
import router_utils
import ".."/[types, redis_cache, formatters, query, api]
import ".."/[types, formatters, query, api]
import ../views/[general, profile, timeline, status, search]
export vdom
export uri, sequtils
export router_utils
export redis_cache, formatters, query, api
export formatters, query, api
export profile, timeline, status
proc getQuery*(request: Request; tab, name: string): Query =
@ -28,6 +28,19 @@ template skipIf[T](cond: bool; default; body: Future[T]): Future[T] =
else:
body
proc getUserId(username: string): Future[string] {.async.} =
let user = await getGraphUser(username)
if user.suspended:
return "suspended"
else:
return user.id
proc getUsername*(userId: string): Future[string] {.async.} =
let user = await getGraphUserById(userId)
result = user.username
proc fetchProfile*(after: string; query: Query; cfg: Config; skipRail=false;
skipPinned=false): Future[Profile] {.async.} =
let
@ -48,9 +61,9 @@ proc fetchProfile*(after: string; query: Query; cfg: Config; skipRail=false;
let
rail =
skipIf(skipRail or query.kind == media, @[]):
getCachedPhotoRail(name)
getPhotoRail(name)
user = getCachedUser(name)
user = getGraphUser(name)
result =
case query.kind
@ -94,7 +107,7 @@ template respTimeline*(timeline: typed) =
template respUserId*() =
cond @"user_id".len > 0
let username = await getCachedUsername(@"user_id")
let username = await getUsername(@"user_id")
if username.len > 0:
redirect("/" & username)
else:

View file

@ -29,8 +29,8 @@ proc renderNavbar(cfg: Config; req: Request; rss, canonical: string): VNode =
tdiv(class="nav-item right"):
icon "search", title="Search", href="/search"
if cfg.enableRss and rss.len > 0:
icon "rss-feed", title="RSS Feed", href=rss
#if cfg.enableRss and rss.len > 0:
#icon "rss-feed", title="RSS Feed", href=rss
icon "bird", title="Open in Twitter", href=canonical
a(href="https://liberapay.com/zedeus"): verbatim lp
icon "info", title="About", href="/about"
@ -46,7 +46,7 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
let ogType =
if video.len > 0: "video.other"
elif rss.len > 0: "object"
#elif rss.len > 0: "object"
elif images.len > 0: "photo"
else: "article"
@ -73,8 +73,8 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
if canonical.len > 0:
link(rel="canonical", href=canonical)
if cfg.enableRss and rss.len > 0:
link(rel="alternate", type="application/rss+xml", href=rss, title="RSS feed")
#if cfg.enableRss and rss.len > 0:
#link(rel="alternate", type="application/rss+xml", href=rss, title="RSS feed")
if prefs.hlsPlayback:
script(src="/js/hls.light.min.js", `defer`="")
@ -128,8 +128,8 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
meta(property="og:image", content=image)
if video.len == 0:
meta(property="twitter:image:src", content=image)
if rss.len > 0:
meta(property="twitter:card", content="summary")
#if rss.len > 0:
#meta(property="twitter:card", content="summary")
elif video.len == 0:
meta(property="twitter:card", content="summary_large_image")
elif avatar.len > 0: