From 0a8fd2fce2349002db221cdb063b93f0cbe9e251 Mon Sep 17 00:00:00 2001 From: Zed Date: Tue, 28 Dec 2021 06:21:22 +0100 Subject: [PATCH] Improve enableRSS logic --- nitter.example.conf | 2 +- src/config.nim | 2 +- src/nitter.nim | 3 +-- src/routes/rss.nim | 4 ++++ src/types.nim | 2 +- src/views/general.nim | 4 ++-- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/nitter.example.conf b/nitter.example.conf index d4dfdbf..518114d 100644 --- a/nitter.example.conf +++ b/nitter.example.conf @@ -22,13 +22,13 @@ redisMaxConnections = 30 [Config] hmacKey = "secretkey" # random key for cryptographic signing of video urls base64Media = false # use base64 encoding for proxied media urls +enableRSS = true # set this to false to disable RSS feeds tokenCount = 10 # minimum amount of usable tokens. tokens are used to authorize API requests, # but they expire after ~1 hour, and have a limit of 187 requests. # 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 db09533..a07c224 100644 --- a/src/config.nim +++ b/src/config.nim @@ -26,7 +26,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), + 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 08946e5..2e69576 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -48,8 +48,7 @@ createStatusRouter(cfg) createSearchRouter(cfg) createMediaRouter(cfg) createEmbedRouter(cfg) -if cfg.enableRSS: - createRssRouter(cfg) +createRssRouter(cfg) settings: port = Port(cfg.port) diff --git a/src/routes/rss.nim b/src/routes/rss.nim index 3797aa7..2fd2901 100644 --- a/src/routes/rss.nim +++ b/src/routes/rss.nim @@ -52,6 +52,7 @@ template respRss*(rss) = proc createRssRouter*(cfg: Config) = router rss: get "/search/rss": + cond cfg.enableRss if @"q".len > 200: resp Http400, showError("Search input too long.", cfg) @@ -76,6 +77,7 @@ proc createRssRouter*(cfg: Config) = respRss(rss) get "/@name/rss": + cond cfg.enableRss cond '.' notin @"name" let cursor = getCursor() @@ -92,6 +94,7 @@ proc createRssRouter*(cfg: Config) = respRss(rss) get "/@name/@tab/rss": + cond cfg.enableRss cond '.' notin @"name" cond @"tab" in ["with_replies", "media", "search"] let name = @"name" @@ -117,6 +120,7 @@ proc createRssRouter*(cfg: Config) = respRss(rss) get "/@name/lists/@list/rss": + cond cfg.enableRss cond '.' notin @"name" let cursor = getCursor() diff --git a/src/types.nim b/src/types.nim index 27c0dc6..8ab3236 100644 --- a/src/types.nim +++ b/src/types.nim @@ -216,7 +216,7 @@ type hmacKey*: string base64Media*: bool minTokens*: int - enableRSS*: bool + enableRss*: bool rssCacheTime*: int listCacheTime*: int diff --git a/src/views/general.nim b/src/views/general.nim index 1ddd512..fc47c5a 100644 --- a/src/views/general.nim +++ b/src/views/general.nim @@ -25,7 +25,7 @@ proc renderNavbar*(cfg: Config, rss: string; req: Request): VNode = tdiv(class="nav-item right"): icon "search", title="Search", href="/search" - if cfg.enableRSS and 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 @@ -58,7 +58,7 @@ proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video=""; link(rel="search", type="application/opensearchdescription+xml", title=cfg.title, href=opensearchUrl) - if cfg.enableRSS and 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: