diff --git a/docs/en/social-media.md b/docs/en/social-media.md
index 0cd5ed040..ea83ae471 100644
--- a/docs/en/social-media.md
+++ b/docs/en/social-media.md
@@ -440,6 +440,31 @@ Due to Telegram restrictions, some channels involving pornography, copyright, an
`;
+ } else {
+ html += `';
+ }
+ }
+ } else {
+ post.carousel_media.forEach((media) => {
+ const firstImage = media.image_versions2?.candidates[0];
+ const firstVideo = media.video_versions?.[0];
+ if (!firstVideo) {
+ html += `
`;
+ } else {
+ html += `';
+ }
+ });
+ }
+
+ return html;
+};
+
+const buildContent = (item, options) => {
+ let title = '';
+ let description = '';
+ const quotedPost = item.post.text_post_app_info?.share_info?.quoted_post;
+ const repostedPost = item.post.text_post_app_info?.share_info?.reposted_post;
+ const isReply = item.post.text_post_app_info?.reply_to_author;
+ const embededPost = quotedPost ?? repostedPost;
+
+ if (options.showAuthorInTitle) {
+ title += `@${item.post.user?.username}: `;
+ }
+
+ if (options.showAuthorInDesc) {
+ description += '
';
+ if (options.showAuthorAvatarInDesc) {
+ description += ` `;
+ }
+ description += `@${item.post.user?.username}`;
+ if (embededPost) {
+ description += options.showEmojiForQuotesAndReply ? ' đ' : ' quoted';
+ } else if (isReply) {
+ description += options.showEmojiForQuotesAndReply ? ' âŠī¸' : ' replied';
+ }
+ description += ':
${item.post.caption?.text}
`; + } + + if (hasMedia(item.post)) { + description += `${buildMedia(item.post)}
`; + } + + if (embededPost) { + if (options.showQuotedInTitle) { + title += options.showEmojiForQuotesAndReply ? ' đ ' : ' QT: '; + title += `@${embededPost.user?.username}: `; + title += `"${embededPost.caption?.text}"`; + } + description += ''; + description += `'; + } + return { title, description }; +}; + +module.exports = async (ctx) => { + const { user, routeParams } = ctx.params; + const { lsd, userId } = await extractTokens(user, ctx); + + const params = new URLSearchParams(routeParams); + ctx.state.json.params = routeParams; + + const options = { + showAuthorInTitle: params.get('showAuthorInTitle') ?? true, + showAuthorInDesc: params.get('showAuthorInDesc') ?? true, + showAuthorAvatarInDesc: params.get('showAuthorAvatarInDesc') ?? false, + showQuotedInTitle: params.get('showQuotedInTitle') ?? true, + showQuotedAuthorAvatarInDesc: params.get('showQuotedAuthorAvatarInDesc') ?? false, + showEmojiForQuotesAndReply: params.get('showEmojiForQuotesAndReply') ?? true, + replies: params.get('replies') ?? false, + }; + + const headers = makeHeader(user, lsd); + const resp = await got.post(apiUrl, { + headers, + form: { + lsd, + variables: JSON.stringify({ userID: userId }), + doc_id: options.replies ? REPLIES_QUERY : THREADS_QUERY, + }, + }); + + ctx.state.json.request = { + headers: resp.request.options.headers, + body: resp.request.options.body, + }; + + const responseBody = resp.data; + const threads = responseBody?.data?.mediaData?.threads || []; + + const items = threads.flatMap((thread) => + thread.thread_items + .filter((item) => user === item.post.user?.username) + .map((item) => { + const { title, description } = buildContent(item, options); + return { + author: user, + title, + description, + pubDate: parseDate(item.post.taken_at, 'X'), + link: threadUrl(item.post.code), + }; + }) + ); + + ctx.state.json.items = items; + + ctx.state.data = { + title: user, + link: profileUrl(user), + description: user, + item: items, + }; +}; diff --git a/lib/v2/threads/maintainer.js b/lib/v2/threads/maintainer.js new file mode 100644 index 000000000..f56a62efb --- /dev/null +++ b/lib/v2/threads/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:user/:routeParams?': ['ninboy'], +}; diff --git a/lib/v2/threads/radar.js b/lib/v2/threads/radar.js new file mode 100644 index 000000000..d33de9376 --- /dev/null +++ b/lib/v2/threads/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'threads.net': { + _name: 'Threads', + '.': [ + { + title: 'User timeline', + docs: 'https://docs.rsshub.app/en/social-media.html#threads', + source: ['/:user'], + target: (params) => `/threads/${params.user.substring(1)}`, + }, + ], + }, +}; diff --git a/lib/v2/threads/router.js b/lib/v2/threads/router.js new file mode 100644 index 000000000..ffd936fdc --- /dev/null +++ b/lib/v2/threads/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:user/:routeParams?', require('./index')); +};${embededPost.caption?.text}
`; + if (hasMedia(embededPost)) { + description += `${buildMedia(embededPost)}
`; + } + description += 'â '; + if (options.showQuotedAuthorAvatarInDesc) { + description += ``; + } + description += `@${embededPost.user?.username} â `; + description += `${dayjs(embededPost.taken_at, 'X').toString()}`; + description += '