Skip to content

Instantly share code, notes, and snippets.

@rotorot0
Created February 26, 2024 19:54
Show Gist options
  • Select an option

  • Save rotorot0/f84db5d6bbc1982b598c4157ffa15de5 to your computer and use it in GitHub Desktop.

Select an option

Save rotorot0/f84db5d6bbc1982b598c4157ffa15de5 to your computer and use it in GitHub Desktop.
diff --git a/nitter.example.conf b/nitter.example.conf
index ffe7a3b..1674516 100644
--- a/nitter.example.conf
+++ b/nitter.example.conf
@@ -35,6 +35,7 @@ tokenCount = 10
#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
+#bearerToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # required for likes
# Change default preferences here, see src/prefs_impl.nim for a complete list
[Preferences]
diff --git a/src/apiutils.nim b/src/apiutils.nim
index 22e75c9..9de40bb 100644
--- a/src/apiutils.nim
+++ b/src/apiutils.nim
@@ -47,12 +47,16 @@ proc getOauthHeader(url, oauthToken, oauthTokenSecret: string): string =
return getOauth1RequestHeader(params)["authorization"]
-proc genHeaders*(url, oauthToken, oauthTokenSecret: string): HttpHeaders =
- let header = getOauthHeader(url, oauthToken, oauthTokenSecret)
-
+proc genHeaders* (url, oauthToken, oauthTokenSecret: string): HttpHeaders =
+ var header: string
+ if "favorites" in url:
+ header = cfg.bearerToken
+ else:
+ header = getOauthHeader(url, oauthToken, oauthTokenSecret)
+
result = newHttpHeaders({
"connection": "keep-alive",
- "authorization": header,
+ "authorization" : header,
"content-type": "application/json",
"x-twitter-active-user": "yes",
"authority": "api.twitter.com",
diff --git a/src/auth.nim b/src/auth.nim
index b288c50..c98dd82 100644
--- a/src/auth.nim
+++ b/src/auth.nim
@@ -1,5 +1,6 @@
#SPDX-License-Identifier: AGPL-3.0-only
-import std/[asyncdispatch, times, json, random, sequtils, strutils, tables, packedsets, os]
+#import std/[asyncdispatch, times, json, random, sequtils, strutils, tables, packedsets, os]
+import std/[asyncdispatch, times, json, random, strutils, tables, packedsets, os]
import types
import experimental/parser/guestaccount
@@ -202,7 +203,7 @@ proc initAccountPool*(cfg: Config; path: string) =
quit 1
let accountsPrePurge = accountPool.len
- accountPool.keepItIf(not it.hasExpired)
+ #accountPool.keepItIf(not it.hasExpired)
log "Successfully added ", accountPool.len, " valid accounts."
if accountsPrePurge > accountPool.len:
diff --git a/src/config.nim b/src/config.nim
index fe4aba5..663045d 100644
--- a/src/config.nim
+++ b/src/config.nim
@@ -43,7 +43,8 @@ proc getConfig*(path: string): (Config, parseCfg.Config) =
proxy: cfg.get("Config", "proxy", ""),
proxyAuth: cfg.get("Config", "proxyAuth", ""),
cookieHeader: cfg.get("Config", "cookieHeader", ""),
- xCsrfToken: cfg.get("Config", "xCsrfToken", "")
+ xCsrfToken: cfg.get("Config", "xCsrfToken", ""),
+ bearerToken: cfg.get("Config", "bearerToken","")
)
return (conf, cfg)
diff --git a/src/nitter.nim b/src/nitter.nim
index f976db2..4da11e6 100644
--- a/src/nitter.nim
+++ b/src/nitter.nim
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: AGPL-3.0-only
import asyncdispatch, strformat, logging
-import config
+#import config
from net import Port
from htmlgen import a
from os import getEnv
diff --git a/src/routes/rss.nim b/src/routes/rss.nim
index 0896536..50ab8ba 100644
--- a/src/routes/rss.nim
+++ b/src/routes/rss.nim
@@ -116,7 +116,7 @@ proc createRssRouter*(cfg: Config) =
let searchKey = if tab != "search": ""
else: ":" & $hash(genQueryUrl(query))
-
+
let key = redisKey(tab, name & searchKey, getCursor())
var rss = await getCachedRss(key)
diff --git a/src/types.nim b/src/types.nim
index 5e58716..1d11b6c 100644
--- a/src/types.nim
+++ b/src/types.nim
@@ -285,6 +285,7 @@ type
cookieHeader*: string
xCsrfToken*: string
+ bearerToken*: string
Rss* = object
feed*, cursor*: string
diff --git a/src/views/search.nim b/src/views/search.nim
index 8e797b7..d53f756 100644
--- a/src/views/search.nim
+++ b/src/views/search.nim
@@ -38,7 +38,7 @@ proc renderProfileTabs*(query: Query; username: string; cfg: Config): VNode =
a(href=(link & "/with_replies")): text "Tweets & Replies"
li(class=query.getTabClass(media)):
a(href=(link & "/media")): text "Media"
- if len(cfg.xCsrfToken) != 0 and len(cfg.cookieHeader) != 0:
+ if len(cfg.xCsrfToken) != 0 and len(cfg.cookieHeader) != 0 and len(cfg.bearerToken) != 0:
li(class=query.getTabClass(favorites)):
a(href=(link & "/favorites")): text "Likes"
li(class=query.getTabClass(tweets)):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment