added login-based workaround to view NSFW content

This commit is contained in:
PrivacyDev 2023-04-08 10:33:49 -04:00
parent a6dd229444
commit d5689f2253
5 changed files with 13 additions and 11 deletions

View file

@ -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]

View file

@ -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

View file

@ -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):

View file

@ -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)

View file

@ -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())