From 2edf54d5b37095536c3426d4b5227da5c700aa89 Mon Sep 17 00:00:00 2001 From: Timothy Bautista Date: Sat, 2 Oct 2021 13:15:52 -0600 Subject: [PATCH] Add enableRSS setting in config file Useful for instance owners who want to disable the RSS endpoint for reasons such as abuse and not enough server resources to handle heavy network traffic through that endpoint. Resolves #437 --- nitter.conf | 1 + src/config.nim | 1 + src/nitter.nim | 3 ++- src/types.nim | 3 ++- src/views/general.nim | 10 +++++----- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/nitter.conf b/nitter.conf index aa27a65..1ef8760 100644 --- a/nitter.conf +++ b/nitter.conf @@ -28,6 +28,7 @@ tokenCount = 10 # the limit gets reset every 15 minutes, and the pool is filled up so there's # always at least $tokenCount usable tokens. again, only increase this if # you receive major bursts all the time +enableRSS = true # set this to false to disable RSS feeds # Change default preferences here, see src/prefs_impl.nim for a complete list [Preferences] diff --git a/src/config.nim b/src/config.nim index 9a04e41..f21ee4a 100644 --- a/src/config.nim +++ b/src/config.nim @@ -25,6 +25,7 @@ proc getConfig*(path: string): (Config, parseCfg.Config) = hmacKey: cfg.get("Config", "hmacKey", "secretkey"), base64Media: cfg.get("Config", "base64Media", false), minTokens: cfg.get("Config", "tokenCount", 10), + enableRSS: cfg.get("Config", "enableRSS", true), listCacheTime: cfg.get("Cache", "listMinutes", 120), rssCacheTime: cfg.get("Cache", "rssMinutes", 10), diff --git a/src/nitter.nim b/src/nitter.nim index 20cf8df..e580552 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -46,7 +46,8 @@ createStatusRouter(cfg) createSearchRouter(cfg) createMediaRouter(cfg) createEmbedRouter(cfg) -createRssRouter(cfg) +if cfg.enableRSS: + createRssRouter(cfg) settings: port = Port(cfg.port) diff --git a/src/types.nim b/src/types.nim index d405e26..63634b2 100644 --- a/src/types.nim +++ b/src/types.nim @@ -126,7 +126,7 @@ type videoDirectMessage = "video_direct_message" imageDirectMessage = "image_direct_message" audiospace = "audiospace" - + Card* = object kind*: CardKind id*: string @@ -212,6 +212,7 @@ type hmacKey*: string base64Media*: bool minTokens*: int + enableRSS*: bool rssCacheTime*: int listCacheTime*: int diff --git a/src/views/general.nim b/src/views/general.nim index 341e3c0..bb5d480 100644 --- a/src/views/general.nim +++ b/src/views/general.nim @@ -10,7 +10,7 @@ const doctype = "\n" lp = readFile("public/lp.svg") -proc renderNavbar*(title, rss: string; req: Request): VNode = +proc renderNavbar*(cfg: Config, rss: string; req: Request): VNode = let twitterPath = getTwitterLink(req.path, req.params) var path = $(parseUri(req.path) ? filterParams(req.params)) if "/status" in path: path.add "#m" @@ -18,13 +18,13 @@ proc renderNavbar*(title, rss: string; req: Request): VNode = buildHtml(nav): tdiv(class="inner-nav"): tdiv(class="nav-item"): - a(class="site-name", href="/"): text title + a(class="site-name", href="/"): text cfg.title a(href="/"): img(class="site-logo", src="/logo.png") tdiv(class="nav-item right"): icon "search", title="Search", href="/search" - if rss.len > 0: + if cfg.enableRSS and rss.len > 0: icon "rss-feed", title="RSS Feed", href=rss icon "bird", title="Open in Twitter", href=twitterPath a(href="https://liberapay.com/zedeus"): verbatim lp @@ -57,7 +57,7 @@ proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video=""; link(rel="search", type="application/opensearchdescription+xml", title=cfg.title, href=opensearchUrl) - if rss.len > 0: + if cfg.enableRSS and rss.len > 0: link(rel="alternate", type="application/rss+xml", href=rss, title="RSS feed") if prefs.hlsPlayback: @@ -119,7 +119,7 @@ proc renderMain*(body: VNode; req: Request; cfg: Config; prefs=defaultPrefs; renderHead(prefs, cfg, titleText, desc, video, images, banner, ogTitle, theme, rss) body: - renderNavbar(cfg.title, rss, req) + renderNavbar(cfg, rss, req) tdiv(class="container"): body