mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
Merge e3e00965c8 into 3f7b9667c6
This commit is contained in:
commit
10f886851c
2 changed files with 66 additions and 2 deletions
|
|
@ -46,6 +46,11 @@ interface TwitterAPITweet {
|
|||
}
|
||||
}
|
||||
|
||||
interface TwitterAPIVisibilityResult {
|
||||
__typename: "TweetWithVisibilityResults"
|
||||
tweet?: TwitterAPITweet
|
||||
}
|
||||
|
||||
interface MediaEntity {
|
||||
type: string
|
||||
media_url_https: string
|
||||
|
|
@ -270,9 +275,13 @@ export function transformTweetData(
|
|||
return null
|
||||
}
|
||||
|
||||
const tweet = tweetData as TwitterAPITweet
|
||||
const visibilityResult = tweetData as TwitterAPIVisibilityResult
|
||||
const tweet =
|
||||
visibilityResult.__typename === "TweetWithVisibilityResults"
|
||||
? visibilityResult.tweet
|
||||
: (tweetData as TwitterAPITweet)
|
||||
|
||||
if (!tweet.legacy) {
|
||||
if (!tweet?.legacy) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
import { describe, expect, it } from "bun:test"
|
||||
import { getAllTweets, type TwitterAPIResponse } from "./twitter-utils"
|
||||
|
||||
const apiTweet = (id: string) => ({
|
||||
__typename: "Tweet",
|
||||
legacy: {
|
||||
favorite_count: 0,
|
||||
created_at: "Wed Oct 10 20:19:24 +0000 2018",
|
||||
id_str: id,
|
||||
full_text: `Tweet ${id}`,
|
||||
},
|
||||
})
|
||||
|
||||
const timelineEntry = (id: string, result: unknown) => ({
|
||||
entryId: `tweet-${id}`,
|
||||
sortIndex: id,
|
||||
content: { itemContent: { tweet_results: { result } } },
|
||||
})
|
||||
|
||||
describe("getAllTweets", () => {
|
||||
it("extracts visibility-wrapped results and skips unavailable tweets", () => {
|
||||
const response: TwitterAPIResponse = {
|
||||
data: {
|
||||
bookmark_timeline_v2: {
|
||||
timeline: {
|
||||
instructions: [
|
||||
{
|
||||
type: "TimelineAddEntries",
|
||||
entries: [
|
||||
timelineEntry("100", apiTweet("100")),
|
||||
timelineEntry("200", {
|
||||
__typename: "TweetWithVisibilityResults",
|
||||
limitedActionResults: {},
|
||||
tweet: apiTweet("200"),
|
||||
}),
|
||||
timelineEntry("300", {
|
||||
__typename: "TweetTombstone",
|
||||
}),
|
||||
timelineEntry("400", {
|
||||
__typename: "TweetWithVisibilityResults",
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(getAllTweets(response).map((tweet) => tweet.id_str)).toEqual([
|
||||
"100",
|
||||
"200",
|
||||
])
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Reference in a new issue