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 # always at least $tokenCount usable tokens. again, only increase this if
# you receive major bursts all the time # 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 #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 #xCsrfToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # required for the likes tab and NSFW content
# Change default preferences here, see src/prefs_impl.nim for a complete list # Change default preferences here, see src/prefs_impl.nim for a complete list
[Preferences] [Preferences]

View file

@ -70,11 +70,7 @@ proc getFavorites*(id: string; cfg: Config; after=""): Future[Timeline] {.async.
let let
ps = genParams({"userId": id}, after) ps = genParams({"userId": id}, after)
url = consts.favorites / (id & ".json") ? ps url = consts.favorites / (id & ".json") ? ps
headers = newHttpHeaders({ result = parseTimeline(await fetch(url, Api.favorites), after)
"Cookie": cfg.cookieHeader,
"x-csrf-token": cfg.xCsrfToken
})
result = parseTimeline(await fetch(url, Api.favorites, headers), after)
proc getMediaTimeline*(id: string; after=""): Future[Timeline] {.async.} = proc getMediaTimeline*(id: string; after=""): Future[Timeline] {.async.} =
if id.len == 0: return if id.len == 0: return

View file

@ -3,6 +3,7 @@ import httpclient, asyncdispatch, options, strutils, uri
import jsony, packedjson, zippy import jsony, packedjson, zippy
import types, tokens, consts, parserutils, http_pool import types, tokens, consts, parserutils, http_pool
import experimental/types/common import experimental/types/common
import config
const const
rlRemaining = "x-rate-limit-remaining" rlRemaining = "x-rate-limit-remaining"
@ -42,6 +43,10 @@ proc genHeaders*(token: Token = nil): HttpHeaders =
"accept": "*/*", "accept": "*/*",
"DNT": "1" "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() = template updateToken() =
if api != Api.search and resp.headers.hasKey(rlRemaining): if api != Api.search and resp.headers.hasKey(rlRemaining):

View file

@ -1,6 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
import parsecfg except Config import parsecfg except Config
import types, strutils import types, strutils
from os import getEnv
proc get*[T](config: parseCfg.Config; section, key: string; default: T): T = proc get*[T](config: parseCfg.Config; section, key: string; default: T): T =
let val = config.getSectionValue(section, key) let val = config.getSectionValue(section, key)
@ -46,3 +47,7 @@ proc getConfig*(path: string): (Config, parseCfg.Config) =
) )
return (conf, cfg) 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 import asyncdispatch, strformat, logging
from net import Port from net import Port
from htmlgen import a from htmlgen import a
from os import getEnv
import jester import jester
@ -15,9 +14,6 @@ import routes/[
const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances" const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances"
const issuesUrl = "https://github.com/zedeus/nitter/issues" 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: if not cfg.enableDebug:
# Silence Jester's query warning # Silence Jester's query warning
addHandler(newConsoleLogger()) addHandler(newConsoleLogger())