From d5689f2253d761dd72723868742fdc3211c850bd Mon Sep 17 00:00:00 2001 From: PrivacyDev Date: Sat, 8 Apr 2023 10:33:49 -0400 Subject: [PATCH] added login-based workaround to view NSFW content --- nitter.example.conf | 4 ++-- src/api.nim | 6 +----- src/apiutils.nim | 5 +++++ src/config.nim | 5 +++++ src/nitter.nim | 4 ---- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/nitter.example.conf b/nitter.example.conf index 656e879..a950916 100644 --- a/nitter.example.conf +++ b/nitter.example.conf @@ -33,8 +33,8 @@ tokenCount = 10 # always at least $tokenCount usable tokens. again, only increase this if # you receive major bursts all the time -#cookieHeader = "ct0=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; auth_token=XXXXXXXXXXXXXXXXXXXXXXX" # authentication cookie of a logged in account, required for the likes tab -#xCsrfToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # required for the likes tab +#cookieHeader = "ct0=XXXXXXXXXXXXXXXXX; auth_token=XXXXXXXXXXXXXX" # authentication cookie of a logged in account, required for the likes tab and NSFW content +#xCsrfToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # required for the likes tab and NSFW content # Change default preferences here, see src/prefs_impl.nim for a complete list [Preferences] diff --git a/src/api.nim b/src/api.nim index 45e0f65..a5eb0fd 100644 --- a/src/api.nim +++ b/src/api.nim @@ -70,11 +70,7 @@ proc getFavorites*(id: string; cfg: Config; after=""): Future[Timeline] {.async. let ps = genParams({"userId": id}, after) url = consts.favorites / (id & ".json") ? ps - headers = newHttpHeaders({ - "Cookie": cfg.cookieHeader, - "x-csrf-token": cfg.xCsrfToken - }) - result = parseTimeline(await fetch(url, Api.favorites, headers), after) + result = parseTimeline(await fetch(url, Api.favorites), after) proc getMediaTimeline*(id: string; after=""): Future[Timeline] {.async.} = if id.len == 0: return diff --git a/src/apiutils.nim b/src/apiutils.nim index ff10735..15c7200 100644 --- a/src/apiutils.nim +++ b/src/apiutils.nim @@ -3,6 +3,7 @@ import httpclient, asyncdispatch, options, strutils, uri import jsony, packedjson, zippy import types, tokens, consts, parserutils, http_pool import experimental/types/common +import config const rlRemaining = "x-rate-limit-remaining" @@ -42,6 +43,10 @@ proc genHeaders*(token: Token = nil): HttpHeaders = "accept": "*/*", "DNT": "1" }) + if len(cfg.cookieHeader) != 0: + result.add("Cookie", cfg.cookieHeader) + if len(cfg.xCsrfToken) != 0: + result.add("x-csrf-token", cfg.xCsrfToken) template updateToken() = if api != Api.search and resp.headers.hasKey(rlRemaining): diff --git a/src/config.nim b/src/config.nim index 47f0fc3..fe4aba5 100644 --- a/src/config.nim +++ b/src/config.nim @@ -1,6 +1,7 @@ # SPDX-License-Identifier: AGPL-3.0-only import parsecfg except Config import types, strutils +from os import getEnv proc get*[T](config: parseCfg.Config; section, key: string; default: T): T = let val = config.getSectionValue(section, key) @@ -46,3 +47,7 @@ proc getConfig*(path: string): (Config, parseCfg.Config) = ) return (conf, cfg) + + +let configPath = getEnv("NITTER_CONF_FILE", "./nitter.conf") +let (cfg*, fullCfg*) = getConfig(configPath) diff --git a/src/nitter.nim b/src/nitter.nim index 2e868a4..5eee56f 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -2,7 +2,6 @@ import asyncdispatch, strformat, logging from net import Port from htmlgen import a -from os import getEnv import jester @@ -15,9 +14,6 @@ import routes/[ const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances" const issuesUrl = "https://github.com/zedeus/nitter/issues" -let configPath = getEnv("NITTER_CONF_FILE", "./nitter.conf") -let (cfg, fullCfg) = getConfig(configPath) - if not cfg.enableDebug: # Silence Jester's query warning addHandler(newConsoleLogger())