added authentication headers to user search for nsfw users

This commit is contained in:
PrivacyDev 2023-04-16 02:05:45 -04:00
parent 6875569bf2
commit 11279e2b4f

View file

@ -3,6 +3,7 @@ import asyncdispatch, httpclient, uri, strutils, sequtils, sugar
import packedjson import packedjson
import types, query, formatters, consts, apiutils, parser import types, query, formatters, consts, apiutils, parser
import experimental/parser as newParser import experimental/parser as newParser
import config
proc getGraphUser*(username: string): Future[User] {.async.} = proc getGraphUser*(username: string): Future[User] {.async.} =
if username.len == 0: return if username.len == 0: return
@ -86,11 +87,18 @@ proc getPhotoRail*(name: string): Future[PhotoRail] {.async.} =
result = parsePhotoRail(await fetch(url, Api.timeline)) result = parsePhotoRail(await fetch(url, Api.timeline))
proc getSearch*[T](query: Query; after=""): Future[Result[T]] {.async.} = proc getSearch*[T](query: Query; after=""): Future[Result[T]] {.async.} =
let additional_headers = newHttpHeaders()
when T is User: when T is User:
const const
searchMode = ("result_filter", "user") searchMode = ("result_filter", "user")
parse = parseUsers parse = parseUsers
fetchFunc = fetchRaw fetchFunc = fetchRaw
if len(cfg.cookieHeader) != 0:
additional_headers.add("Cookie", cfg.cookieHeader)
if len(cfg.xCsrfToken) != 0:
additional_headers.add("x-csrf-token", cfg.xCsrfToken)
else: else:
const const
searchMode = ("tweet_search_mode", "live") searchMode = ("tweet_search_mode", "live")
@ -103,7 +111,7 @@ proc getSearch*[T](query: Query; after=""): Future[Result[T]] {.async.} =
let url = search ? genParams(searchParams & @[("q", q), searchMode], after) let url = search ? genParams(searchParams & @[("q", q), searchMode], after)
try: try:
result = parse(await fetchFunc(url, Api.search), after) result = parse(await fetchFunc(url, Api.search, additional_headers), after)
result.query = query result.query = query
except InternalError: except InternalError:
return Result[T](beginning: true, query: query) return Result[T](beginning: true, query: query)