1
0
mirror of https://github.com/zedeus/nitter synced 2024-11-25 11:09:32 +01:00

Use "max_position" instead of "after" for compat

This commit is contained in:
Zed 2019-10-08 15:15:47 +02:00
parent 381a8a106c
commit 211b086f4d
10 changed files with 17 additions and 40 deletions

View File

@ -9,7 +9,7 @@ proc getResult*[T](json: JsonNode; query: Query; after: string): Result[T] =
Result[T](
hasMore: json{"has_more_items"}.getBool(false),
maxId: json{"max_position"}.getStr(""),
minId: json{"min_position"}.getStr("").cleanPos(),
minId: json{"min_position"}.getStr(""),
query: query,
beginning: after.len == 0
)
@ -17,7 +17,6 @@ proc getResult*[T](json: JsonNode; query: Query; after: string): Result[T] =
proc getSearch*[T](query: Query; after, agent: string): Future[Result[T]] {.async.} =
let
kind = if query.kind == users: "users" else: "tweets"
pos = when T is Tweet: genPos(after) else: after
param = genQueryParam(query)
encoded = encodeUrl(param, usePlus=false)
@ -32,7 +31,7 @@ proc getSearch*[T](query: Query; after, agent: string): Future[Result[T]] {.asyn
"src": "typd",
"include_available_features": "1",
"include_entities": "1",
"max_position": if pos.len > 0: pos else: "0",
"max_position": if after.len > 0: after else: "0",
"reset_error_state": "false"
}

View File

@ -146,21 +146,14 @@ proc getTwitterLink*(path: string; params: Table[string, string]): string =
username = params.getOrDefault("name")
query = initQuery(params, username)
var after = params.getOrDefault("after", "0")
if query.kind notin {userList, users} and "/members" notin path:
after = after.genPos()
var paramList = filterParams(params).mapIt(
if it[0] == "after": ("max_position", after) else: it)
if "/search" notin path:
return $(twitter / path ? paramList)
return $(twitter / path ? filterParams(params))
let p = {
"f": $query.kind,
"q": genQueryParam(query),
"src": "typd",
"max_position": after
"max_position": params.getOrDefault("max_position", "0")
}
result = $(parseUri("https://twitter.com") / path ? p)

View File

@ -12,12 +12,6 @@ const
"verified", "safe"
]
# Experimental, this might break in the future
# Till then, it results in shorter urls
const
posPrefix = "thGAVUV0VFVB"
posSuffix = "EjUAFQAlAFUAFQAA"
template `@`(param: string): untyped =
if param in pms: pms[param]
else: ""
@ -105,12 +99,3 @@ proc genQueryUrl*(query: Query): string =
if params.len > 0:
result &= params.join("&")
proc cleanPos*(pos: string): string =
pos.multiReplace((posPrefix, ""), (posSuffix, ""))
proc genPos*(pos: string): string =
if pos.len == 0 or pos == "0": return pos
result = posPrefix & pos
if "A==" notin result:
result &= posSuffix

View File

@ -18,17 +18,17 @@ proc createListRouter*(cfg: Config) =
get "/@name/lists/@list":
cond '.' notin @"name"
let
list = await getListTimeline(@"name", @"list", getAgent(), @"after")
list = await getListTimeline(@"name", @"list", getAgent(), @"max_position")
tweets = renderTimelineTweets(list, cookiePrefs(), request.path)
respList list, tweets
get "/@name/lists/@list/members":
cond '.' notin @"name"
let list =
if @"after".len == 0:
if @"max_position".len == 0:
await getListMembers(@"name", @"list", getAgent())
else:
await getListMembersSearch(@"name", @"list", getAgent(), @"after")
await getListMembersSearch(@"name", @"list", getAgent(), @"max_position")
let users = renderTimelineUsers(list, cookiePrefs(), request.path)
respList list, users

View File

@ -21,10 +21,10 @@ proc createSearchRouter*(cfg: Config) =
of users:
if "," in @"q":
redirect("/" & @"q")
let users = await getSearch[Profile](query, @"after", getAgent())
let users = await getSearch[Profile](query, @"max_position", getAgent())
resp renderMain(renderUserSearch(users, prefs), request, cfg.title)
of tweets:
let tweets = await getSearch[Tweet](query, @"after", getAgent())
let tweets = await getSearch[Tweet](query, @"max_position", getAgent())
let rss = "/search/rss?" & genQueryUrl(query)
resp renderMain(renderTweetSearch(tweets, prefs, getPath()), request,
cfg.title, rss=rss)

View File

@ -17,7 +17,7 @@ proc createStatusRouter*(cfg: Config) =
cond '.' notin @"name"
let prefs = cookiePrefs()
let conversation = await getTweet(@"name", @"id", @"after", getAgent())
let conversation = await getTweet(@"name", @"id", @"max_position", getAgent())
if conversation == nil or conversation.tweet.id.len == 0:
var error = "Tweet not found"
if conversation != nil and conversation.tweet.tombstone.len > 0:

View File

@ -56,7 +56,7 @@ proc showTimeline*(request: Request; query: Query; title, rss: string): Future[s
agent = getAgent()
prefs = cookiePrefs()
name = request.get("name")
after = request.get("after")
after = request.get("max_position")
names = name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
if names.len == 1:

View File

@ -19,7 +19,7 @@ proc renderNewer*(query: Query; path: string): VNode =
proc renderMore*(query: Query; minId: string): VNode =
buildHtml(tdiv(class="show-more")):
a(href=(&"?{getQuery(query)}after={minId}")):
a(href=(&"?{getQuery(query)}max_position={minId}")):
text "Load more"
proc renderNoMore(): VNode =

View File

@ -8,9 +8,9 @@ after = [['mobile_test', '627635134573862912'],
short = [['mobile_test_6'], ['mobile_test_8'], ['picman']]
no_more = [['mobile_test_8?after=159455542543257601']]
no_more = [['mobile_test_8?max_position=159455542543257601']]
none_found = [['mobile_test_8?after=159455542543257600']]
none_found = [['mobile_test_8?max_position=159455542543257600']]
empty = [['maybethis'], ['mobile_test_10']]
@ -28,7 +28,7 @@ class TweetTest(BaseTestCase):
@parameterized.expand(after)
def test_after(self, username, index):
self.open_nitter(f'{username}?after={index}')
self.open_nitter(f'{username}?max_position={index}')
self.assert_element_present(Timeline.newest)
self.assert_element_present(Timeline.older)
self.assert_element_absent(Timeline.end)

View File

@ -81,8 +81,8 @@ retweet = [
]
reply = [
['mobile_test?after=471336696307392513', '@mobile_test', '@mobile_test'],
['mobile_test_2?after=375101899214561280', '@mobile_test_2', '@mobile_test']
['mobile_test?max_position=471336696307392513', '@mobile_test', '@mobile_test'],
['mobile_test_2?max_position=375101899214561280', '@mobile_test_2', '@mobile_test']
]