Fix everything (#927)

* Switch bearer token and endpoints, update parser

* Enable user search, disable tweet search

* Disable multi-user timelines for now

* Fix parsing of pinned tombstone
This commit is contained in:
Zed
2023-07-10 11:25:34 +02:00
committed by GitHub
parent dcf73354ff
commit 0bc3c153d9
20 changed files with 260 additions and 264 deletions

View File

@@ -10,22 +10,22 @@ export api, embed, vdom, tweet, general, router_utils
proc createEmbedRouter*(cfg: Config) =
router embed:
get "/i/videos/tweet/@id":
let convo = await getTweet(@"id")
if convo == nil or convo.tweet == nil or convo.tweet.video.isNone:
let tweet = await getGraphTweetResult(@"id")
if tweet == nil or tweet.video.isNone:
resp Http404
resp renderVideoEmbed(convo.tweet, cfg, request)
resp renderVideoEmbed(tweet, cfg, request)
get "/@user/status/@id/embed":
let
convo = await getTweet(@"id")
tweet = await getGraphTweetResult(@"id")
prefs = cookiePrefs()
path = getPath()
if convo == nil or convo.tweet == nil:
if tweet == nil:
resp Http404
resp renderTweetEmbed(convo.tweet, path, prefs, cfg, request)
resp renderTweetEmbed(tweet, path, prefs, cfg, request)
get "/embed/Tweet.html":
let id = @"id"

View File

@@ -27,14 +27,12 @@ proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async.
else:
var q = query
q.fromUser = names
profile = Profile(
tweets: await getGraphSearch(q, after),
# this is kinda dumb
user: User(
username: name,
fullname: names.join(" | "),
userpic: "https://abs.twimg.com/sticky/default_profile_images/default_profile.png"
)
profile = await getGraphSearch(q, after)
# this is kinda dumb
profile.user = User(
username: name,
fullname: names.join(" | "),
userpic: "https://abs.twimg.com/sticky/default_profile_images/default_profile.png"
)
if profile.user.suspended:
@@ -61,29 +59,29 @@ template respRss*(rss, page) =
proc createRssRouter*(cfg: Config) =
router rss:
get "/search/rss":
cond cfg.enableRss
if @"q".len > 200:
resp Http400, showError("Search input too long.", cfg)
# get "/search/rss":
# cond cfg.enableRss
# if @"q".len > 200:
# resp Http400, showError("Search input too long.", cfg)
let query = initQuery(params(request))
if query.kind != tweets:
resp Http400, showError("Only Tweet searches are allowed for RSS feeds.", cfg)
# let query = initQuery(params(request))
# if query.kind != tweets:
# resp Http400, showError("Only Tweet searches are allowed for RSS feeds.", cfg)
let
cursor = getCursor()
key = redisKey("search", $hash(genQueryUrl(query)), cursor)
# let
# cursor = getCursor()
# key = redisKey("search", $hash(genQueryUrl(query)), cursor)
var rss = await getCachedRss(key)
if rss.cursor.len > 0:
respRss(rss, "Search")
# var rss = await getCachedRss(key)
# if rss.cursor.len > 0:
# respRss(rss, "Search")
let tweets = await getGraphSearch(query, cursor)
rss.cursor = tweets.bottom
rss.feed = renderSearchRss(tweets.content, query.text, genQueryUrl(query), cfg)
# let tweets = await getGraphSearch(query, cursor)
# rss.cursor = tweets.bottom
# rss.feed = renderSearchRss(tweets.content, query.text, genQueryUrl(query), cfg)
await cacheRss(key, rss)
respRss(rss, "Search")
# await cacheRss(key, rss)
# respRss(rss, "Search")
get "/@name/rss":
cond cfg.enableRss
@@ -112,7 +110,7 @@ proc createRssRouter*(cfg: Config) =
case tab
of "with_replies": getReplyQuery(name)
of "media": getMediaQuery(name)
of "search": initQuery(params(request), name=name)
# of "search": initQuery(params(request), name=name)
else: Query(fromUser: @[name])
let searchKey = if tab != "search": ""

View File

@@ -34,11 +34,15 @@ proc createSearchRouter*(cfg: Config) =
users = Result[User](beginning: true, query: query)
resp renderMain(renderUserSearch(users, prefs), request, cfg, prefs, title)
of tweets:
let
tweets = await getGraphSearch(query, getCursor())
rss = "/search/rss?" & genQueryUrl(query)
resp renderMain(renderTweetSearch(tweets, prefs, getPath()),
request, cfg, prefs, title, rss=rss)
# let
# tweets = await getGraphSearch(query, getCursor())
# rss = "/search/rss?" & genQueryUrl(query)
# resp renderMain(renderTweetSearch(tweets, prefs, getPath()),
# request, cfg, prefs, title, rss=rss)
var fakeTimeline = Timeline(beginning: true)
fakeTimeline.content.add Tweet(tombstone: "Tweet search is unavailable for now")
resp renderMain(renderTweetSearch(fakeTimeline, prefs, getPath()), request, cfg, prefs, title)
else:
resp Http404, showError("Invalid search", cfg)

View File

@@ -45,34 +45,24 @@ proc fetchProfile*(after: string; query: Query; skipRail=false;
after.setLen 0
let
timeline =
case query.kind
of posts: getGraphUserTweets(userId, TimelineKind.tweets, after)
of replies: getGraphUserTweets(userId, TimelineKind.replies, after)
of media: getGraphUserTweets(userId, TimelineKind.media, after)
else: getGraphSearch(query, after)
rail =
skipIf(skipRail or query.kind == media, @[]):
getCachedPhotoRail(name)
user = await getCachedUser(name)
user = getCachedUser(name)
var pinned: Option[Tweet]
if not skipPinned and user.pinnedTweet > 0 and
after.len == 0 and query.kind in {posts, replies}:
let tweet = await getCachedTweet(user.pinnedTweet)
if not tweet.isNil:
tweet.pinned = true
tweet.user = user
pinned = some tweet
result =
case query.kind
of posts: await getGraphUserTweets(userId, TimelineKind.tweets, after)
of replies: await getGraphUserTweets(userId, TimelineKind.replies, after)
of media: await getGraphUserTweets(userId, TimelineKind.media, after)
else: Profile(tweets: Timeline(beginning: true, content: @[Chain(content:
@[Tweet(tombstone: "Tweet search is unavailable for now")]
)]))
# else: await getGraphSearch(query, after)
result = Profile(
user: user,
pinned: pinned,
tweets: await timeline,
photoRail: await rail
)
result.user = await user
result.photoRail = await rail
if result.user.protected or result.user.suspended:
return
@@ -83,8 +73,11 @@ proc showTimeline*(request: Request; query: Query; cfg: Config; prefs: Prefs;
rss, after: string): Future[string] {.async.} =
if query.fromUser.len != 1:
let
timeline = await getGraphSearch(query, after)
html = renderTweetSearch(timeline, prefs, getPath())
# timeline = await getGraphSearch(query, after)
timeline = Profile(tweets: Timeline(beginning: true, content: @[Chain(content:
@[Tweet(tombstone: "This features is unavailable for now")]
)]))
html = renderTweetSearch(timeline.tweets, prefs, getPath())
return renderMain(html, request, cfg, prefs, "Multi", rss=rss)
var profile = await fetchProfile(after, query, skipPinned=prefs.hidePins)
@@ -138,7 +131,7 @@ proc createTimelineRouter*(cfg: Config) =
# used for the infinite scroll feature
if @"scroll".len > 0:
if query.fromUser.len != 1:
var timeline = await getGraphSearch(query, after)
var timeline = (await getGraphSearch(query, after)).tweets
if timeline.content.len == 0: resp Http404
timeline.beginning = true
resp $renderTweetSearch(timeline, prefs, getPath())