Skip to content

Commit

Permalink
added login-based workaround to view NSFW content
Browse files Browse the repository at this point in the history
  • Loading branch information
PrivacyDevel committed Apr 8, 2023
1 parent a6dd229 commit d5689f2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions nitter.example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 1 addition & 5 deletions src/api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/apiutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions src/config.nim
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
4 changes: 0 additions & 4 deletions src/nitter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import asyncdispatch, strformat, logging
from net import Port
from htmlgen import a
from os import getEnv

import jester

Expand All @@ -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())
Expand Down

0 comments on commit d5689f2

Please sign in to comment.