@jackwener/opencli 1.7.21 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -148
- package/README.zh-CN.md +38 -211
- package/cli-manifest.json +6423 -4260
- package/clis/12306/me.js +73 -0
- package/clis/12306/orders.js +96 -0
- package/clis/12306/passengers.js +90 -0
- package/clis/12306/price.js +166 -0
- package/clis/12306/stations.js +66 -0
- package/clis/12306/train.js +91 -0
- package/clis/12306/trains.js +119 -0
- package/clis/12306/utils.js +272 -0
- package/clis/12306/utils.test.js +331 -0
- package/clis/36kr/article.js +6 -3
- package/clis/36kr/article.test.js +46 -0
- package/clis/apple-podcasts/commands.test.js +20 -0
- package/clis/apple-podcasts/search.js +2 -2
- package/clis/barchart/greeks.js +144 -56
- package/clis/barchart/greeks.test.js +138 -0
- package/clis/bilibili/summary.js +167 -0
- package/clis/bilibili/summary.test.js +210 -0
- package/clis/booking/booking.test.js +356 -0
- package/clis/booking/search.js +351 -0
- package/clis/boss/utils.js +17 -1
- package/clis/boss/utils.test.js +34 -0
- package/clis/chatgpt/envelope.test.js +108 -0
- package/clis/chatgpt/image.js +2 -2
- package/clis/chatgpt/image.test.js +6 -0
- package/clis/chatgpt/utils.js +148 -41
- package/clis/chatgpt/utils.test.js +92 -2
- package/clis/douyin/_shared/browser-fetch.js +44 -20
- package/clis/douyin/_shared/browser-fetch.test.js +22 -1
- package/clis/douyin/_shared/evaluate-result.js +16 -0
- package/clis/douyin/_shared/tos-upload.js +105 -69
- package/clis/douyin/_shared/vod-upload.js +212 -0
- package/clis/douyin/_shared/vod-upload.test.js +38 -0
- package/clis/douyin/delete.js +137 -4
- package/clis/douyin/delete.test.js +90 -1
- package/clis/douyin/publish-upload-id.test.js +170 -0
- package/clis/douyin/publish.js +88 -42
- package/clis/douyin/user-videos.js +9 -2
- package/clis/douyin/user-videos.test.js +43 -0
- package/clis/flomo/memos.js +228 -0
- package/clis/flomo/memos.test.js +144 -0
- package/clis/gitee/search.js +2 -2
- package/clis/gitee/search.test.js +65 -0
- package/clis/jike/post.js +27 -17
- package/clis/jike/read.test.js +86 -0
- package/clis/jike/topic.js +32 -19
- package/clis/jike/user.js +33 -20
- package/clis/lesswrong/comments.js +1 -1
- package/clis/lesswrong/curated.js +1 -1
- package/clis/lesswrong/frontpage.js +1 -1
- package/clis/lesswrong/frontpage.test.js +37 -0
- package/clis/lesswrong/new.js +1 -1
- package/clis/lesswrong/read.js +1 -1
- package/clis/lesswrong/sequences.js +1 -1
- package/clis/lesswrong/shortform.js +1 -1
- package/clis/lesswrong/tag.js +1 -1
- package/clis/lesswrong/top-month.js +1 -1
- package/clis/lesswrong/top-week.js +1 -1
- package/clis/lesswrong/top-year.js +1 -1
- package/clis/lesswrong/top.js +1 -1
- package/clis/linkedin/connect.js +401 -0
- package/clis/linkedin/connect.test.js +213 -0
- package/clis/linkedin/inbox.js +234 -0
- package/clis/linkedin/inbox.test.js +152 -0
- package/clis/linkedin/people-search.js +262 -0
- package/clis/linkedin/people-search.test.js +216 -0
- package/clis/linkedin/safe-send.js +357 -0
- package/clis/linkedin/safe-send.test.js +204 -0
- package/clis/linkedin/salesnav-inbox.js +210 -0
- package/clis/linkedin/salesnav-inbox.test.js +113 -0
- package/clis/linkedin/salesnav-message.js +360 -0
- package/clis/linkedin/salesnav-message.test.js +172 -0
- package/clis/linkedin/salesnav-search.js +186 -0
- package/clis/linkedin/salesnav-search.test.js +76 -0
- package/clis/linkedin/salesnav-thread.js +212 -0
- package/clis/linkedin/salesnav-thread.test.js +79 -0
- package/clis/linkedin/sent-invitations.js +92 -0
- package/clis/linkedin/sent-invitations.test.js +62 -0
- package/clis/linkedin/thread-snapshot.js +214 -0
- package/clis/linkedin/thread-snapshot.test.js +89 -0
- package/clis/linkedin-learning/course.js +138 -0
- package/clis/linkedin-learning/course.test.js +114 -0
- package/clis/linkedin-learning/search.js +155 -0
- package/clis/linkedin-learning/search.test.js +144 -0
- package/clis/linkedin-learning/trending.js +133 -0
- package/clis/linkedin-learning/trending.test.js +123 -0
- package/clis/powerchina/search.js +3 -3
- package/clis/powerchina/search.test.js +27 -1
- package/clis/reddit/extract-media.test.js +149 -0
- package/clis/reddit/frontpage.js +47 -9
- package/clis/reddit/frontpage.test.js +34 -0
- package/clis/reddit/home.js +31 -1
- package/clis/reddit/home.test.js +46 -3
- package/clis/reddit/hot.js +32 -1
- package/clis/reddit/hot.test.js +15 -1
- package/clis/reddit/popular.js +39 -1
- package/clis/reddit/popular.test.js +26 -0
- package/clis/reddit/saved.js +1 -1
- package/clis/reddit/search.js +38 -1
- package/clis/reddit/search.test.js +26 -0
- package/clis/reddit/subreddit.js +52 -7
- package/clis/reddit/subreddit.test.js +31 -0
- package/clis/reddit/subscribed.js +165 -0
- package/clis/reddit/subscribed.test.js +168 -0
- package/clis/reddit/upvoted.js +1 -1
- package/clis/suno/commands.test.js +188 -0
- package/clis/suno/download.js +140 -0
- package/clis/suno/download.test.js +151 -0
- package/clis/suno/generate.js +226 -0
- package/clis/suno/generate.test.js +243 -0
- package/clis/suno/list.js +79 -0
- package/clis/suno/status.js +62 -0
- package/clis/suno/utils.js +540 -0
- package/clis/suno/utils.test.js +223 -0
- package/clis/twitter/device-follow.js +193 -0
- package/clis/twitter/device-follow.test.js +287 -0
- package/clis/twitter/download.js +443 -73
- package/clis/twitter/download.test.js +457 -0
- package/clis/twitter/list-create.js +155 -0
- package/clis/twitter/list-create.test.js +169 -0
- package/clis/twitter/list-remove.js +12 -5
- package/clis/twitter/list-remove.test.js +74 -0
- package/clis/twitter/list-tweets.js +6 -2
- package/clis/twitter/list-tweets.test.js +41 -1
- package/clis/twitter/lists.js +31 -4
- package/clis/twitter/lists.test.js +152 -16
- package/clis/twitter/search.js +6 -2
- package/clis/twitter/search.test.js +6 -0
- package/clis/twitter/shared.js +144 -0
- package/clis/twitter/shared.test.js +429 -1
- package/clis/twitter/thread.js +10 -2
- package/clis/twitter/thread.test.js +58 -0
- package/clis/twitter/timeline.js +6 -2
- package/clis/twitter/timeline.test.js +2 -0
- package/clis/twitter/tweets.js +3 -2
- package/clis/twitter/tweets.test.js +1 -1
- package/clis/weibo/comments.js +3 -4
- package/clis/weibo/delete.js +172 -0
- package/clis/weibo/delete.test.js +94 -0
- package/clis/weibo/envelope.test.js +85 -0
- package/clis/weibo/favorites.js +4 -4
- package/clis/weibo/feed.js +3 -5
- package/clis/weibo/hot.js +3 -4
- package/clis/weibo/me.js +3 -5
- package/clis/weibo/post.js +3 -4
- package/clis/weibo/publish.js +37 -14
- package/clis/weibo/publish.test.js +14 -5
- package/clis/weibo/search.js +4 -3
- package/clis/weibo/user-posts.js +234 -0
- package/clis/weibo/user-posts.test.js +92 -0
- package/clis/weibo/user.js +3 -4
- package/clis/weibo/utils.js +34 -5
- package/clis/weibo/utils.test.js +36 -0
- package/clis/weread/search-regression.test.js +18 -11
- package/clis/weread/search.js +15 -7
- package/clis/weread-official/book.js +135 -0
- package/clis/weread-official/commands.test.js +385 -0
- package/clis/weread-official/discover.js +107 -0
- package/clis/weread-official/list-apis.js +95 -0
- package/clis/weread-official/notes.js +171 -0
- package/clis/weread-official/readdata.js +158 -0
- package/clis/weread-official/review.js +93 -0
- package/clis/weread-official/search.js +106 -0
- package/clis/weread-official/shelf.js +97 -0
- package/clis/weread-official/utils.js +293 -0
- package/clis/weread-official/utils.test.js +242 -0
- package/clis/wikipedia/trending.js +7 -3
- package/clis/wikipedia/trending.test.js +57 -0
- package/clis/xianyu/chat.js +24 -109
- package/clis/xianyu/chat.test.js +5 -0
- package/clis/xianyu/im.js +322 -0
- package/clis/xianyu/im.test.js +253 -0
- package/clis/xianyu/inbox.js +96 -0
- package/clis/xianyu/messages.js +91 -0
- package/clis/xianyu/reply.js +82 -0
- package/clis/xiaohongshu/creator-note-detail.js +2 -1
- package/clis/xiaohongshu/creator-note-detail.test.js +11 -0
- package/clis/xiaohongshu/creator-notes-summary.js +2 -1
- package/clis/xiaohongshu/creator-notes-summary.test.js +7 -0
- package/clis/xiaohongshu/creator-notes.js +2 -1
- package/clis/xiaohongshu/creator-notes.test.js +12 -0
- package/clis/xiaohongshu/creator-stats.js +2 -1
- package/clis/xiaohongshu/creator-stats.test.js +24 -0
- package/clis/xiaohongshu/delete-note.js +260 -0
- package/clis/xiaohongshu/delete-note.test.js +172 -0
- package/clis/xiaohongshu/publish.js +48 -8
- package/clis/xiaohongshu/publish.test.js +65 -10
- package/clis/xiaohongshu/user-helpers.test.js +41 -0
- package/clis/xiaohongshu/user.js +27 -4
- package/clis/xiaoyuzhou/download.js +1 -1
- package/clis/xiaoyuzhou/transcript.js +1 -1
- package/clis/youdao/note.js +258 -0
- package/clis/youdao/note.test.js +99 -0
- package/clis/youtube/transcript.js +397 -24
- package/clis/youtube/transcript.test.js +196 -6
- package/clis/zhihu/answer-comments.js +299 -0
- package/clis/zhihu/answer-comments.test.js +287 -0
- package/clis/zhihu/answer-detail.js +12 -0
- package/clis/zhihu/answer-detail.test.js +8 -0
- package/clis/zhihu/collection.js +15 -2
- package/clis/zhihu/collection.test.js +46 -0
- package/clis/zhihu/download.js +1 -1
- package/clis/zhihu/question.js +42 -9
- package/clis/zhihu/question.test.js +111 -9
- package/clis/zhihu/search.js +206 -43
- package/clis/zhihu/search.test.js +198 -0
- package/dist/src/browser/errors.js +4 -2
- package/dist/src/browser/errors.test.js +6 -0
- package/dist/src/browser/page.js +30 -4
- package/dist/src/browser/page.test.js +42 -0
- package/dist/src/browser/utils.d.ts +1 -1
- package/dist/src/cli-argv-preprocess.d.ts +26 -0
- package/dist/src/cli-argv-preprocess.js +138 -0
- package/dist/src/cli-argv-preprocess.test.js +79 -0
- package/dist/src/cli.js +1 -1
- package/dist/src/convention-audit.js +15 -8
- package/dist/src/convention-audit.test.js +21 -0
- package/dist/src/download/media-download.js +15 -2
- package/dist/src/download/media-download.test.d.ts +1 -0
- package/dist/src/download/media-download.test.js +110 -0
- package/dist/src/electron-apps.js +1 -1
- package/dist/src/electron-apps.test.js +7 -2
- package/dist/src/errors.d.ts +17 -0
- package/dist/src/errors.js +22 -0
- package/dist/src/external-clis.yaml +20 -0
- package/dist/src/external.d.ts +6 -1
- package/dist/src/external.test.js +19 -0
- package/dist/src/main.js +14 -2
- package/dist/src/utils.d.ts +43 -0
- package/dist/src/utils.js +97 -0
- package/dist/src/utils.test.d.ts +1 -0
- package/dist/src/utils.test.js +155 -0
- package/package.json +8 -2
- package/scripts/silent-column-drop-baseline.json +0 -52
- package/scripts/typed-error-lint-baseline.json +28 -380
- package/clis/slock/_utils.js +0 -12
package/clis/twitter/search.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ArgumentError, AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
|
|
2
2
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
3
|
-
import { extractMedia, normalizeTwitterGraphqlPayload, resolveTwitterOperationMetadata } from './shared.js';
|
|
3
|
+
import { extractMedia, extractCard, extractQuotedTweet, normalizeTwitterGraphqlPayload, resolveTwitterOperationMetadata } from './shared.js';
|
|
4
4
|
import { TWITTER_BEARER_TOKEN, applyTopByEngagement } from './utils.js';
|
|
5
5
|
|
|
6
6
|
// ── Public-search operator surface ─────────────────────────────────────
|
|
@@ -212,15 +212,19 @@ function tweetToRow(result, seen) {
|
|
|
212
212
|
if (!tweet?.rest_id || seen.has(tweet.rest_id)) return null;
|
|
213
213
|
seen.add(tweet.rest_id);
|
|
214
214
|
const tweetUser = tweet.core?.user_results?.result;
|
|
215
|
+
const bio = tweetUser?.legacy?.description || '';
|
|
215
216
|
return {
|
|
216
217
|
id: tweet.rest_id,
|
|
217
218
|
author: tweetUser?.core?.screen_name || tweetUser?.legacy?.screen_name || 'unknown',
|
|
219
|
+
bio,
|
|
218
220
|
text: tweet.note_tweet?.note_tweet_results?.result?.text || tweet.legacy?.full_text || '',
|
|
219
221
|
created_at: tweet.legacy?.created_at || '',
|
|
220
222
|
likes: tweet.legacy?.favorite_count || 0,
|
|
221
223
|
views: tweet.views?.count || '0',
|
|
222
224
|
url: `https://x.com/i/status/${tweet.rest_id}`,
|
|
223
225
|
...extractMedia(tweet.legacy),
|
|
226
|
+
card: extractCard(tweet),
|
|
227
|
+
quoted_tweet: extractQuotedTweet(tweet),
|
|
224
228
|
};
|
|
225
229
|
}
|
|
226
230
|
|
|
@@ -271,7 +275,7 @@ cli({
|
|
|
271
275
|
{ name: 'limit', type: 'int', default: 15, help: 'Maximum number of tweets to return (default 15). Result count after server-side filtering.' },
|
|
272
276
|
{ name: 'top-by-engagement', type: 'int', default: 0, help: 'When set to N>0, re-rank the results by weighted engagement (likes×1 + retweets×3 + replies×2 + bookmarks×5 + log10(views+1)×0.5) and return the top N. Default 0 keeps X\'s native ordering.' },
|
|
273
277
|
],
|
|
274
|
-
columns: ['id', 'author', 'text', 'created_at', 'likes', 'views', 'url', 'has_media', 'media_urls'],
|
|
278
|
+
columns: ['id', 'author', 'bio', 'text', 'created_at', 'likes', 'views', 'url', 'has_media', 'media_urls', 'card', 'quoted_tweet'],
|
|
275
279
|
func: async (page, kwargs) => {
|
|
276
280
|
const finalQuery = buildSearchQuery(kwargs.query, kwargs);
|
|
277
281
|
if (!finalQuery) {
|
|
@@ -44,6 +44,9 @@ describe('twitter search command', () => {
|
|
|
44
44
|
core: {
|
|
45
45
|
screen_name: 'alice',
|
|
46
46
|
},
|
|
47
|
+
legacy: {
|
|
48
|
+
description: 'Search author bio',
|
|
49
|
+
},
|
|
47
50
|
},
|
|
48
51
|
},
|
|
49
52
|
},
|
|
@@ -68,6 +71,7 @@ describe('twitter search command', () => {
|
|
|
68
71
|
{
|
|
69
72
|
id: '1',
|
|
70
73
|
author: 'alice',
|
|
74
|
+
bio: 'Search author bio',
|
|
71
75
|
text: 'hello world',
|
|
72
76
|
created_at: 'Thu Mar 26 10:30:00 +0000 2026',
|
|
73
77
|
likes: 7,
|
|
@@ -75,6 +79,8 @@ describe('twitter search command', () => {
|
|
|
75
79
|
url: 'https://x.com/i/status/1',
|
|
76
80
|
has_media: false,
|
|
77
81
|
media_urls: [],
|
|
82
|
+
card: null,
|
|
83
|
+
quoted_tweet: null,
|
|
78
84
|
},
|
|
79
85
|
]);
|
|
80
86
|
expect(page.getCookies).toHaveBeenCalledWith({ url: 'https://x.com' });
|
package/clis/twitter/shared.js
CHANGED
|
@@ -288,6 +288,148 @@ export function extractMedia(legacy) {
|
|
|
288
288
|
}
|
|
289
289
|
return { has_media: urls.length > 0, media_urls: urls };
|
|
290
290
|
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Extract the link-preview card from a tweet's GraphQL response.
|
|
294
|
+
*
|
|
295
|
+
* Reads `tweet.card.legacy.{name, binding_values}` plus the expanded URL from
|
|
296
|
+
* the `tweet.legacy.entities.urls` entry matching the card's t.co URL.
|
|
297
|
+
* `binding_values` is an array of `{ key, value: { type, string_value, image_value: { url } } }`.
|
|
298
|
+
*
|
|
299
|
+
* Returns `null` when:
|
|
300
|
+
* - the tweet has no card, OR
|
|
301
|
+
* - the card is structurally empty (no landing URL AND no title/description),
|
|
302
|
+
* which would be useless to downstream renderers.
|
|
303
|
+
*
|
|
304
|
+
* Otherwise returns a partial card object — missing fields are simply omitted
|
|
305
|
+
* (no `undefined` values in the output) so JSON consumers see a clean shape.
|
|
306
|
+
*/
|
|
307
|
+
export function extractCard(tweet) {
|
|
308
|
+
const cardLegacy = tweet?.card?.legacy;
|
|
309
|
+
if (!cardLegacy) return null;
|
|
310
|
+
const bindings = Array.isArray(cardLegacy.binding_values) ? cardLegacy.binding_values : [];
|
|
311
|
+
const byKey = new Map();
|
|
312
|
+
for (const b of bindings) {
|
|
313
|
+
if (b && typeof b.key === 'string') byKey.set(b.key, b.value);
|
|
314
|
+
}
|
|
315
|
+
const str = (key) => {
|
|
316
|
+
const v = byKey.get(key);
|
|
317
|
+
return typeof v?.string_value === 'string' && v.string_value.length > 0 ? v.string_value : undefined;
|
|
318
|
+
};
|
|
319
|
+
const img = (key) => {
|
|
320
|
+
const v = byKey.get(key);
|
|
321
|
+
const u = v?.image_value?.url;
|
|
322
|
+
return typeof u === 'string' && u.length > 0 ? u : undefined;
|
|
323
|
+
};
|
|
324
|
+
const title = str('title');
|
|
325
|
+
const description = str('description');
|
|
326
|
+
const domainBinding = str('domain');
|
|
327
|
+
const cardUrlBinding = str('card_url');
|
|
328
|
+
const image_url = img('thumbnail_image_large') || img('photo_image_full_size_large') || img('summary_photo_image_large');
|
|
329
|
+
const urlEntities = Array.isArray(tweet?.legacy?.entities?.urls)
|
|
330
|
+
? tweet.legacy.entities.urls
|
|
331
|
+
: [];
|
|
332
|
+
const matchingEntity = cardUrlBinding
|
|
333
|
+
? urlEntities.find((entity) => entity?.url === cardUrlBinding || entity?.expanded_url === cardUrlBinding)
|
|
334
|
+
: undefined;
|
|
335
|
+
const matchedExpandedUrl = matchingEntity?.expanded_url;
|
|
336
|
+
const url = (typeof matchedExpandedUrl === 'string' && matchedExpandedUrl.length > 0)
|
|
337
|
+
? matchedExpandedUrl
|
|
338
|
+
: cardUrlBinding;
|
|
339
|
+
let domain = domainBinding;
|
|
340
|
+
if (!domain && url) {
|
|
341
|
+
try { domain = new URL(url).hostname; }
|
|
342
|
+
catch { /* malformed url — domain stays undefined */ }
|
|
343
|
+
}
|
|
344
|
+
if (!url && !title && !description) return null;
|
|
345
|
+
const out = { name: cardLegacy.name };
|
|
346
|
+
if (title) out.title = title;
|
|
347
|
+
if (description) out.description = description;
|
|
348
|
+
if (image_url) out.image_url = image_url;
|
|
349
|
+
if (url) out.url = url;
|
|
350
|
+
if (domain) out.domain = domain;
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Extract the quoted tweet from a tweet's GraphQL response.
|
|
356
|
+
*
|
|
357
|
+
* A quote tweet is a tweet that embeds and comments on another tweet (distinct
|
|
358
|
+
* from a reply or retweet). The author writes new commentary and the embedded
|
|
359
|
+
* tweet renders as a card-like preview under the new tweet.
|
|
360
|
+
*
|
|
361
|
+
* GraphQL surfaces this as `tweet.quoted_status_result.result`, which contains
|
|
362
|
+
* the same `legacy / core / card / note_tweet` shape as the outer tweet — so
|
|
363
|
+
* we reuse `extractMedia` / `extractCard` on the nested object. Detection is
|
|
364
|
+
* gated by `legacy.is_quote_status === true` (plus the presence of the nested
|
|
365
|
+
* result) so we don't return junk on plain replies that share field shapes.
|
|
366
|
+
*
|
|
367
|
+
* Returns `null` when:
|
|
368
|
+
* - the tweet is not a quote, OR
|
|
369
|
+
* - the nested `quoted_status_result.result` is missing/empty/tombstoned.
|
|
370
|
+
*
|
|
371
|
+
* Only goes ONE level deep — a quote-of-a-quote returns its level-1 quoted
|
|
372
|
+
* tweet without further nesting. Recursing would explode payload size on
|
|
373
|
+
* threads where every reply re-quotes the original.
|
|
374
|
+
*
|
|
375
|
+
* The output shape is a deliberately small subset of the main tweet shape
|
|
376
|
+
* (id/author/name/text/created_at/url + media + card). Consumers that need
|
|
377
|
+
* counts or full author bio of the quoted tweet can re-fetch the quoted id
|
|
378
|
+
* via `twitter thread <id>` — keeping this slim avoids ballooning every
|
|
379
|
+
* timeline/list/search response by 2-3x.
|
|
380
|
+
*/
|
|
381
|
+
export function extractQuotedTweet(tweet) {
|
|
382
|
+
const legacy = tweet?.legacy;
|
|
383
|
+
if (!legacy?.is_quote_status) return null;
|
|
384
|
+
const q = tweet?.quoted_status_result?.result
|
|
385
|
+
?? tweet?.legacy?.quoted_status_result?.result;
|
|
386
|
+
// `result` can be a tombstone (`__typename: 'TweetTombstone'`) or
|
|
387
|
+
// `'TweetUnavailable'` when the quoted tweet was deleted / privacy-restricted.
|
|
388
|
+
if (!q) return null;
|
|
389
|
+
// Nested `tweet` wrapper appears on TweetWithVisibilityResults — same
|
|
390
|
+
// shim that callers already do at the top level (`tw.tweet || tw`).
|
|
391
|
+
const qTw = q.tweet || q;
|
|
392
|
+
if (!qTw || typeof qTw !== 'object') return null;
|
|
393
|
+
const qLegacy = qTw.legacy && typeof qTw.legacy === 'object' ? qTw.legacy : {};
|
|
394
|
+
// `rest_id` is required — tombstoned / unavailable wrappers have neither
|
|
395
|
+
// rest_id nor legacy. Don't fall back to outer `legacy.quoted_status_id_str`:
|
|
396
|
+
// the id alone can't substitute for missing content (author/text/media all
|
|
397
|
+
// empty), so emitting a stub object would mislead downstream renderers into
|
|
398
|
+
// drawing an empty "quoted tweet" preview.
|
|
399
|
+
if (typeof qTw.rest_id !== 'string' || !qTw.rest_id.trim()) return null;
|
|
400
|
+
const qUser = qTw.core?.user_results?.result;
|
|
401
|
+
const qLegacyScreenName = qUser?.legacy?.screen_name;
|
|
402
|
+
const qCoreScreenName = qUser?.core?.screen_name;
|
|
403
|
+
const qScreenName = typeof qLegacyScreenName === 'string' && qLegacyScreenName.trim()
|
|
404
|
+
? qLegacyScreenName.trim()
|
|
405
|
+
: (typeof qCoreScreenName === 'string' && qCoreScreenName.trim() ? qCoreScreenName.trim() : '');
|
|
406
|
+
if (!SCREEN_NAME_PATTERN.test(qScreenName)) return null;
|
|
407
|
+
const qLegacyDisplayName = qUser?.legacy?.name;
|
|
408
|
+
const qCoreDisplayName = qUser?.core?.name;
|
|
409
|
+
const qDisplayName = typeof qLegacyDisplayName === 'string'
|
|
410
|
+
? qLegacyDisplayName
|
|
411
|
+
: (typeof qCoreDisplayName === 'string' ? qCoreDisplayName : '');
|
|
412
|
+
const qNoteText = qTw.note_tweet?.note_tweet_results?.result?.text;
|
|
413
|
+
const qText = (typeof qNoteText === 'string' && qNoteText.length > 0)
|
|
414
|
+
? qNoteText
|
|
415
|
+
: (typeof qLegacy.full_text === 'string' ? qLegacy.full_text : '');
|
|
416
|
+
const qMedia = extractMedia(qLegacy);
|
|
417
|
+
const qCard = extractCard(qTw);
|
|
418
|
+
if (!qText && !qMedia.has_media && !qCard) return null;
|
|
419
|
+
const out = {
|
|
420
|
+
id: qTw.rest_id,
|
|
421
|
+
author: qScreenName,
|
|
422
|
+
name: qDisplayName,
|
|
423
|
+
text: qText,
|
|
424
|
+
created_at: typeof qLegacy.created_at === 'string' ? qLegacy.created_at : '',
|
|
425
|
+
url: `https://x.com/${qScreenName}/status/${qTw.rest_id}`,
|
|
426
|
+
has_media: qMedia.has_media,
|
|
427
|
+
media_urls: qMedia.media_urls,
|
|
428
|
+
};
|
|
429
|
+
if (qCard) out.card = qCard;
|
|
430
|
+
return out;
|
|
431
|
+
}
|
|
432
|
+
|
|
291
433
|
export const __test__ = {
|
|
292
434
|
sanitizeQueryId,
|
|
293
435
|
sanitizeTwitterOperationMetadata,
|
|
@@ -295,6 +437,8 @@ export const __test__ = {
|
|
|
295
437
|
normalizeTwitterGraphqlPayload,
|
|
296
438
|
normalizeTwitterScreenName,
|
|
297
439
|
extractMedia,
|
|
440
|
+
extractCard,
|
|
441
|
+
extractQuotedTweet,
|
|
298
442
|
parseTweetUrl,
|
|
299
443
|
buildTwitterArticleScopeSource,
|
|
300
444
|
};
|
|
@@ -3,7 +3,27 @@ import { JSDOM } from 'jsdom';
|
|
|
3
3
|
import { __test__ } from './shared.js';
|
|
4
4
|
import { ArgumentError } from '@jackwener/opencli/errors';
|
|
5
5
|
|
|
6
|
-
const { extractMedia, parseTweetUrl, buildTwitterArticleScopeSource, unwrapBrowserResult, normalizeTwitterGraphqlPayload, normalizeTwitterScreenName, sanitizeTwitterOperationMetadata } = __test__;
|
|
6
|
+
const { extractMedia, extractCard, extractQuotedTweet, parseTweetUrl, buildTwitterArticleScopeSource, unwrapBrowserResult, normalizeTwitterGraphqlPayload, normalizeTwitterScreenName, sanitizeTwitterOperationMetadata } = __test__;
|
|
7
|
+
|
|
8
|
+
function makeCardTweet({ name, bindings, expandedUrl, urls }) {
|
|
9
|
+
const tweet = {
|
|
10
|
+
card: { legacy: { name, binding_values: bindings } },
|
|
11
|
+
};
|
|
12
|
+
if (urls !== undefined) {
|
|
13
|
+
tweet.legacy = { entities: { urls } };
|
|
14
|
+
return tweet;
|
|
15
|
+
}
|
|
16
|
+
if (expandedUrl !== undefined) {
|
|
17
|
+
tweet.legacy = { entities: { urls: [{ expanded_url: expandedUrl }] } };
|
|
18
|
+
}
|
|
19
|
+
return tweet;
|
|
20
|
+
}
|
|
21
|
+
function strBinding(key, string_value) {
|
|
22
|
+
return { key, value: { type: 'STRING', string_value } };
|
|
23
|
+
}
|
|
24
|
+
function imgBinding(key, url) {
|
|
25
|
+
return { key, value: { type: 'IMAGE', image_value: { url } } };
|
|
26
|
+
}
|
|
7
27
|
|
|
8
28
|
describe('twitter browser result helpers', () => {
|
|
9
29
|
it('unwraps Browser Bridge exec envelopes', () => {
|
|
@@ -328,3 +348,411 @@ describe('twitter extractMedia', () => {
|
|
|
328
348
|
});
|
|
329
349
|
});
|
|
330
350
|
});
|
|
351
|
+
|
|
352
|
+
describe('twitter extractCard', () => {
|
|
353
|
+
it('returns null when tweet has no card', () => {
|
|
354
|
+
expect(extractCard({})).toBeNull();
|
|
355
|
+
expect(extractCard(undefined)).toBeNull();
|
|
356
|
+
expect(extractCard({ legacy: { full_text: 'hi' } })).toBeNull();
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('extracts full summary_large_image card with all bindings present', () => {
|
|
360
|
+
const tweet = makeCardTweet({
|
|
361
|
+
name: 'summary_large_image',
|
|
362
|
+
bindings: [
|
|
363
|
+
strBinding('title', 'jackwener/OpenCLI'),
|
|
364
|
+
strBinding('description', 'Make Any Website & Tool Your CLI'),
|
|
365
|
+
strBinding('domain', 'github.com'),
|
|
366
|
+
strBinding('card_url', 'https://t.co/abc'),
|
|
367
|
+
imgBinding('thumbnail_image_large', 'https://pbs.twimg.com/card_img/thumb_large.jpg'),
|
|
368
|
+
imgBinding('photo_image_full_size_large', 'https://pbs.twimg.com/card_img/photo_large.jpg'),
|
|
369
|
+
imgBinding('summary_photo_image_large', 'https://pbs.twimg.com/card_img/summary_large.jpg'),
|
|
370
|
+
],
|
|
371
|
+
urls: [{ url: 'https://t.co/abc', expanded_url: 'https://github.com/jackwener/OpenCLI' }],
|
|
372
|
+
});
|
|
373
|
+
expect(extractCard(tweet)).toEqual({
|
|
374
|
+
name: 'summary_large_image',
|
|
375
|
+
title: 'jackwener/OpenCLI',
|
|
376
|
+
description: 'Make Any Website & Tool Your CLI',
|
|
377
|
+
image_url: 'https://pbs.twimg.com/card_img/thumb_large.jpg',
|
|
378
|
+
url: 'https://github.com/jackwener/OpenCLI',
|
|
379
|
+
domain: 'github.com',
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('picks summary_photo_image_large when higher-priority image keys are missing', () => {
|
|
384
|
+
const tweet = makeCardTweet({
|
|
385
|
+
name: 'summary',
|
|
386
|
+
bindings: [
|
|
387
|
+
strBinding('title', 'Some article'),
|
|
388
|
+
strBinding('description', 'Body text'),
|
|
389
|
+
strBinding('domain', 'example.com'),
|
|
390
|
+
imgBinding('summary_photo_image_large', 'https://pbs.twimg.com/card_img/fallback.jpg'),
|
|
391
|
+
],
|
|
392
|
+
expandedUrl: 'https://example.com/article',
|
|
393
|
+
});
|
|
394
|
+
const card = extractCard(tweet);
|
|
395
|
+
expect(card.image_url).toBe('https://pbs.twimg.com/card_img/fallback.jpg');
|
|
396
|
+
expect(card.name).toBe('summary');
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('derives domain from expanded_url when domain binding is missing', () => {
|
|
400
|
+
const tweet = makeCardTweet({
|
|
401
|
+
name: 'promo_image_convo',
|
|
402
|
+
bindings: [
|
|
403
|
+
strBinding('title', 'YouTube video'),
|
|
404
|
+
strBinding('card_url', 'https://t.co/youtube'),
|
|
405
|
+
imgBinding('photo_image_full_size_large', 'https://pbs.twimg.com/card_img/yt.jpg'),
|
|
406
|
+
],
|
|
407
|
+
urls: [{ url: 'https://t.co/youtube', expanded_url: 'https://www.youtube.com/watch?v=abc' }],
|
|
408
|
+
});
|
|
409
|
+
const card = extractCard(tweet);
|
|
410
|
+
expect(card.url).toBe('https://www.youtube.com/watch?v=abc');
|
|
411
|
+
expect(card.domain).toBe('www.youtube.com');
|
|
412
|
+
expect(card.image_url).toBe('https://pbs.twimg.com/card_img/yt.jpg');
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('falls back to card_url binding when there is no expanded_url', () => {
|
|
416
|
+
const tweet = makeCardTweet({
|
|
417
|
+
name: 'summary_large_image',
|
|
418
|
+
bindings: [
|
|
419
|
+
strBinding('title', 'arXiv paper'),
|
|
420
|
+
strBinding('card_url', 'https://arxiv.org/abs/2305.12345'),
|
|
421
|
+
],
|
|
422
|
+
expandedUrl: undefined,
|
|
423
|
+
});
|
|
424
|
+
const card = extractCard(tweet);
|
|
425
|
+
expect(card.url).toBe('https://arxiv.org/abs/2305.12345');
|
|
426
|
+
expect(card.domain).toBe('arxiv.org');
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('matches card_url to the correct URL entity instead of assuming the first tweet URL', () => {
|
|
430
|
+
const tweet = makeCardTweet({
|
|
431
|
+
name: 'summary_large_image',
|
|
432
|
+
bindings: [
|
|
433
|
+
strBinding('title', 'OpenCLI release'),
|
|
434
|
+
strBinding('card_url', 'https://t.co/card123'),
|
|
435
|
+
],
|
|
436
|
+
urls: [
|
|
437
|
+
{ url: 'https://t.co/unrelated', expanded_url: 'https://example.com/unrelated' },
|
|
438
|
+
{ url: 'https://t.co/card123', expanded_url: 'https://github.com/jackwener/OpenCLI/releases' },
|
|
439
|
+
],
|
|
440
|
+
});
|
|
441
|
+
const card = extractCard(tweet);
|
|
442
|
+
expect(card.url).toBe('https://github.com/jackwener/OpenCLI/releases');
|
|
443
|
+
expect(card.domain).toBe('github.com');
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('falls back to card_url itself when no matching URL entity is present', () => {
|
|
447
|
+
const tweet = makeCardTweet({
|
|
448
|
+
name: 'summary_large_image',
|
|
449
|
+
bindings: [
|
|
450
|
+
strBinding('title', 'Unmatched card'),
|
|
451
|
+
strBinding('card_url', 'https://t.co/card123'),
|
|
452
|
+
],
|
|
453
|
+
urls: [
|
|
454
|
+
{ url: 'https://t.co/unrelated', expanded_url: 'https://example.com/unrelated' },
|
|
455
|
+
],
|
|
456
|
+
});
|
|
457
|
+
const card = extractCard(tweet);
|
|
458
|
+
expect(card.url).toBe('https://t.co/card123');
|
|
459
|
+
expect(card.domain).toBe('t.co');
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it('omits missing fields rather than emitting undefined values', () => {
|
|
463
|
+
const tweet = makeCardTweet({
|
|
464
|
+
name: 'summary',
|
|
465
|
+
bindings: [
|
|
466
|
+
strBinding('title', 'Just a title'),
|
|
467
|
+
strBinding('description', 'Just a description'),
|
|
468
|
+
strBinding('card_url', 'https://t.co/example'),
|
|
469
|
+
],
|
|
470
|
+
urls: [{ url: 'https://t.co/example', expanded_url: 'https://example.com/x' }],
|
|
471
|
+
});
|
|
472
|
+
const card = extractCard(tweet);
|
|
473
|
+
expect('image_url' in card).toBe(false);
|
|
474
|
+
expect(card).toEqual({
|
|
475
|
+
name: 'summary',
|
|
476
|
+
title: 'Just a title',
|
|
477
|
+
description: 'Just a description',
|
|
478
|
+
url: 'https://example.com/x',
|
|
479
|
+
domain: 'example.com',
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('returns null for a structurally empty card (no url, no title, no description)', () => {
|
|
484
|
+
const tweet = makeCardTweet({
|
|
485
|
+
name: 'summary',
|
|
486
|
+
bindings: [
|
|
487
|
+
imgBinding('thumbnail_image_large', 'https://pbs.twimg.com/card_img/x.jpg'),
|
|
488
|
+
],
|
|
489
|
+
expandedUrl: undefined,
|
|
490
|
+
});
|
|
491
|
+
expect(extractCard(tweet)).toBeNull();
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it('does not throw on a malformed expanded_url; domain is simply omitted', () => {
|
|
495
|
+
const tweet = makeCardTweet({
|
|
496
|
+
name: 'summary',
|
|
497
|
+
bindings: [
|
|
498
|
+
strBinding('title', 'broken url card'),
|
|
499
|
+
strBinding('card_url', 'https://t.co/broken'),
|
|
500
|
+
],
|
|
501
|
+
urls: [{ url: 'https://t.co/broken', expanded_url: 'not a url' }],
|
|
502
|
+
});
|
|
503
|
+
const card = extractCard(tweet);
|
|
504
|
+
expect(card.url).toBe('not a url');
|
|
505
|
+
expect('domain' in card).toBe(false);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it('tolerates missing binding_values array', () => {
|
|
509
|
+
const tweet = {
|
|
510
|
+
card: { legacy: { name: 'summary' } },
|
|
511
|
+
legacy: { entities: { urls: [{ expanded_url: 'https://example.com/' }] } },
|
|
512
|
+
};
|
|
513
|
+
const card = extractCard(tweet);
|
|
514
|
+
expect(card).toBeNull();
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
describe('twitter extractQuotedTweet', () => {
|
|
519
|
+
it('returns null on plain tweets (is_quote_status absent or false)', () => {
|
|
520
|
+
expect(extractQuotedTweet({})).toBeNull();
|
|
521
|
+
expect(extractQuotedTweet({ legacy: {} })).toBeNull();
|
|
522
|
+
expect(extractQuotedTweet({ legacy: { is_quote_status: false } })).toBeNull();
|
|
523
|
+
// is_quote_status true but no nested result (deleted / restricted): still null
|
|
524
|
+
expect(extractQuotedTweet({
|
|
525
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
526
|
+
})).toBeNull();
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
it('returns null on tombstoned / unavailable quoted tweets', () => {
|
|
530
|
+
// GraphQL emits TweetTombstone / TweetUnavailable when the quoted tweet
|
|
531
|
+
// is deleted, suspended, or privacy-restricted. The wrapper has no
|
|
532
|
+
// `legacy` / `rest_id` — null-coalesces in the helper cover this.
|
|
533
|
+
const tweet = {
|
|
534
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
535
|
+
quoted_status_result: { result: { __typename: 'TweetTombstone' } },
|
|
536
|
+
};
|
|
537
|
+
expect(extractQuotedTweet(tweet)).toBeNull();
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it('returns null when the quoted tweet lacks author identity', () => {
|
|
541
|
+
const tweet = {
|
|
542
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
543
|
+
quoted_status_result: {
|
|
544
|
+
result: {
|
|
545
|
+
rest_id: '99',
|
|
546
|
+
legacy: { full_text: 'real quoted text' },
|
|
547
|
+
core: { user_results: { result: { legacy: {} } } },
|
|
548
|
+
},
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
expect(extractQuotedTweet(tweet)).toBeNull();
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
it('returns null when the quoted tweet author identity has the wrong shape', () => {
|
|
555
|
+
const tweet = {
|
|
556
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
557
|
+
quoted_status_result: {
|
|
558
|
+
result: {
|
|
559
|
+
rest_id: '99',
|
|
560
|
+
legacy: { full_text: 'real quoted text' },
|
|
561
|
+
core: {
|
|
562
|
+
user_results: {
|
|
563
|
+
result: {
|
|
564
|
+
legacy: { screen_name: { value: 'alice' }, name: { value: 'Alice' } },
|
|
565
|
+
},
|
|
566
|
+
},
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
},
|
|
570
|
+
};
|
|
571
|
+
expect(extractQuotedTweet(tweet)).toBeNull();
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it('returns null when the quoted tweet author handle is not a valid screen name', () => {
|
|
575
|
+
const tweet = {
|
|
576
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
577
|
+
quoted_status_result: {
|
|
578
|
+
result: {
|
|
579
|
+
rest_id: '99',
|
|
580
|
+
legacy: { full_text: 'real quoted text' },
|
|
581
|
+
core: { user_results: { result: { legacy: { screen_name: 'not/a/user' } } } },
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
};
|
|
585
|
+
expect(extractQuotedTweet(tweet)).toBeNull();
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it('returns null when the quoted tweet lacks renderable content', () => {
|
|
589
|
+
const tweet = {
|
|
590
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
591
|
+
quoted_status_result: {
|
|
592
|
+
result: {
|
|
593
|
+
rest_id: '99',
|
|
594
|
+
legacy: {},
|
|
595
|
+
core: { user_results: { result: { legacy: { screen_name: 'alice' } } } },
|
|
596
|
+
},
|
|
597
|
+
},
|
|
598
|
+
};
|
|
599
|
+
expect(extractQuotedTweet(tweet)).toBeNull();
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
it('extracts a minimal quoted tweet shape with author, text, url', () => {
|
|
603
|
+
const tweet = {
|
|
604
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '2040254679301718161' },
|
|
605
|
+
quoted_status_result: {
|
|
606
|
+
result: {
|
|
607
|
+
rest_id: '2040254679301718161',
|
|
608
|
+
legacy: {
|
|
609
|
+
full_text: '罗某官二代背景考',
|
|
610
|
+
created_at: 'Wed May 13 22:00:00 +0000 2026',
|
|
611
|
+
},
|
|
612
|
+
core: {
|
|
613
|
+
user_results: {
|
|
614
|
+
result: { legacy: { screen_name: 'alice', name: 'Alice' } },
|
|
615
|
+
},
|
|
616
|
+
},
|
|
617
|
+
},
|
|
618
|
+
},
|
|
619
|
+
};
|
|
620
|
+
expect(extractQuotedTweet(tweet)).toEqual({
|
|
621
|
+
id: '2040254679301718161',
|
|
622
|
+
author: 'alice',
|
|
623
|
+
name: 'Alice',
|
|
624
|
+
text: '罗某官二代背景考',
|
|
625
|
+
created_at: 'Wed May 13 22:00:00 +0000 2026',
|
|
626
|
+
url: 'https://x.com/alice/status/2040254679301718161',
|
|
627
|
+
has_media: false,
|
|
628
|
+
media_urls: [],
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
it('extracts media from the quoted tweet via extractMedia', () => {
|
|
633
|
+
const tweet = {
|
|
634
|
+
legacy: { is_quote_status: true },
|
|
635
|
+
quoted_status_result: {
|
|
636
|
+
result: {
|
|
637
|
+
rest_id: '99',
|
|
638
|
+
legacy: {
|
|
639
|
+
full_text: '日本电车实录',
|
|
640
|
+
extended_entities: {
|
|
641
|
+
media: [
|
|
642
|
+
{ type: 'photo', media_url_https: 'https://pbs.twimg.com/media/a.jpg' },
|
|
643
|
+
{ type: 'photo', media_url_https: 'https://pbs.twimg.com/media/b.jpg' },
|
|
644
|
+
],
|
|
645
|
+
},
|
|
646
|
+
},
|
|
647
|
+
core: { user_results: { result: { legacy: { screen_name: 'rwayne' } } } },
|
|
648
|
+
},
|
|
649
|
+
},
|
|
650
|
+
};
|
|
651
|
+
const q = extractQuotedTweet(tweet);
|
|
652
|
+
expect(q.has_media).toBe(true);
|
|
653
|
+
expect(q.media_urls).toEqual([
|
|
654
|
+
'https://pbs.twimg.com/media/a.jpg',
|
|
655
|
+
'https://pbs.twimg.com/media/b.jpg',
|
|
656
|
+
]);
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it('extracts the quoted tweet card when present', () => {
|
|
660
|
+
const tweet = {
|
|
661
|
+
legacy: { is_quote_status: true },
|
|
662
|
+
quoted_status_result: {
|
|
663
|
+
result: {
|
|
664
|
+
rest_id: '100',
|
|
665
|
+
legacy: {
|
|
666
|
+
full_text: '',
|
|
667
|
+
entities: {
|
|
668
|
+
urls: [{ url: 'https://t.co/abc', expanded_url: 'https://github.com/x/y' }],
|
|
669
|
+
},
|
|
670
|
+
},
|
|
671
|
+
core: { user_results: { result: { legacy: { screen_name: 'bob' } } } },
|
|
672
|
+
card: {
|
|
673
|
+
legacy: {
|
|
674
|
+
name: 'summary_large_image',
|
|
675
|
+
binding_values: [
|
|
676
|
+
{ key: 'title', value: { type: 'STRING', string_value: 'x/y' } },
|
|
677
|
+
{ key: 'card_url', value: { type: 'STRING', string_value: 'https://t.co/abc' } },
|
|
678
|
+
],
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
},
|
|
682
|
+
},
|
|
683
|
+
};
|
|
684
|
+
const q = extractQuotedTweet(tweet);
|
|
685
|
+
expect(q.card).toEqual({
|
|
686
|
+
name: 'summary_large_image',
|
|
687
|
+
title: 'x/y',
|
|
688
|
+
url: 'https://github.com/x/y',
|
|
689
|
+
domain: 'github.com',
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
it('prefers long-form note_tweet text over truncated legacy full_text', () => {
|
|
694
|
+
const tweet = {
|
|
695
|
+
legacy: { is_quote_status: true },
|
|
696
|
+
quoted_status_result: {
|
|
697
|
+
result: {
|
|
698
|
+
rest_id: '101',
|
|
699
|
+
legacy: { full_text: 'short…' },
|
|
700
|
+
note_tweet: { note_tweet_results: { result: { text: 'full long body of the quoted tweet' } } },
|
|
701
|
+
core: { user_results: { result: { legacy: { screen_name: 'carol' } } } },
|
|
702
|
+
},
|
|
703
|
+
},
|
|
704
|
+
};
|
|
705
|
+
expect(extractQuotedTweet(tweet)?.text).toBe('full long body of the quoted tweet');
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
it('unwraps TweetWithVisibilityResults — quoted_status_result.result.tweet shim', () => {
|
|
709
|
+
// Mirrors the top-level `tw.tweet || tw` shim that callers do for sensitive content.
|
|
710
|
+
const tweet = {
|
|
711
|
+
legacy: { is_quote_status: true },
|
|
712
|
+
quoted_status_result: {
|
|
713
|
+
result: {
|
|
714
|
+
__typename: 'TweetWithVisibilityResults',
|
|
715
|
+
tweet: {
|
|
716
|
+
rest_id: '102',
|
|
717
|
+
legacy: { full_text: 'sensitive content quoted' },
|
|
718
|
+
core: { user_results: { result: { legacy: { screen_name: 'dave' } } } },
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
},
|
|
722
|
+
};
|
|
723
|
+
const q = extractQuotedTweet(tweet);
|
|
724
|
+
expect(q?.id).toBe('102');
|
|
725
|
+
expect(q?.author).toBe('dave');
|
|
726
|
+
expect(q?.text).toBe('sensitive content quoted');
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
it('does NOT recurse — a quote of a quote drops the inner-inner quote', () => {
|
|
730
|
+
// Avoid payload explosion on threads where every reply re-quotes the root.
|
|
731
|
+
// Level-1 quote is preserved; level-2 (a quote inside the quoted tweet)
|
|
732
|
+
// is intentionally not surfaced.
|
|
733
|
+
const tweet = {
|
|
734
|
+
legacy: { is_quote_status: true },
|
|
735
|
+
quoted_status_result: {
|
|
736
|
+
result: {
|
|
737
|
+
rest_id: '200',
|
|
738
|
+
legacy: {
|
|
739
|
+
full_text: 'level-1 quote text',
|
|
740
|
+
is_quote_status: true,
|
|
741
|
+
},
|
|
742
|
+
core: { user_results: { result: { legacy: { screen_name: 'l1' } } } },
|
|
743
|
+
quoted_status_result: {
|
|
744
|
+
result: {
|
|
745
|
+
rest_id: '300',
|
|
746
|
+
legacy: { full_text: 'level-2 should be dropped' },
|
|
747
|
+
core: { user_results: { result: { legacy: { screen_name: 'l2' } } } },
|
|
748
|
+
},
|
|
749
|
+
},
|
|
750
|
+
},
|
|
751
|
+
},
|
|
752
|
+
};
|
|
753
|
+
const q = extractQuotedTweet(tweet);
|
|
754
|
+
expect(q?.id).toBe('200');
|
|
755
|
+
expect(q?.text).toBe('level-1 quote text');
|
|
756
|
+
expect(q).not.toHaveProperty('quoted_tweet');
|
|
757
|
+
});
|
|
758
|
+
});
|