From 9118442a7e3b19bc84b5bca03691ece6de7dfba3 Mon Sep 17 00:00:00 2001 From: bunizao <102936102+bunizao@users.noreply.github.com> Date: Fri, 16 Jan 2026 21:36:33 +0800 Subject: [PATCH] feat: enable conditional loading of reactions in getPost function --- src/lib/telegram/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/telegram/index.js b/src/lib/telegram/index.js index 0a21abe..086b4bd 100644 --- a/src/lib/telegram/index.js +++ b/src/lib/telegram/index.js @@ -222,7 +222,7 @@ async function getReactions($, item, staticProxy) { return reactions } -async function getPost($, item, { channel, staticProxy, index = 0 }) { +async function getPost($, item, { channel, staticProxy, index = 0, reactionsEnabled } = {}) { item = item ? $(item).find('.tgme_widget_message') : $('.tgme_widget_message') const content = $(item).find('.js-message_reply_text')?.length > 0 ? await modifyHTMLContent($, $(item).find('.tgme_widget_message_text.js-message_text'), { index, staticProxy }) @@ -264,7 +264,7 @@ async function getPost($, item, { channel, staticProxy, index = 0 }) { } return `${p1}${staticProxy}${p2}` }), - reactions: await getReactions($, item, staticProxy), + reactions: reactionsEnabled ? await getReactions($, item, staticProxy) : [], } } @@ -283,6 +283,7 @@ export async function getChannelInfo(Astro, { before = '', after = '', q = '', t const host = getEnv(import.meta.env, Astro, 'TELEGRAM_HOST') ?? 't.me' const channel = getEnv(import.meta.env, Astro, 'CHANNEL') const staticProxy = getEnv(import.meta.env, Astro, 'STATIC_PROXY') ?? '/static/' + const reactionsEnabled = getEnv(import.meta.env, Astro, 'REACTIONS') const url = id ? `https://${host}/${channel}/${id}?embed=1&mode=tme` : `https://${host}/s/${channel}` const headers = Object.fromEntries(Astro.request.headers) @@ -307,13 +308,13 @@ export async function getChannelInfo(Astro, { before = '', after = '', q = '', t const $ = cheerio.load(html, {}, false) if (id) { - const post = await getPost($, null, { channel, staticProxy }) + const post = await getPost($, null, { channel, staticProxy, reactionsEnabled }) cache.set(cacheKey, post) return post } const posts = (await Promise.all( $('.tgme_channel_history .tgme_widget_message_wrap')?.map((index, item) => { - return getPost($, item, { channel, staticProxy, index }) + return getPost($, item, { channel, staticProxy, index, reactionsEnabled }) })?.get() ?? [], ))?.reverse().filter(post => ['text'].includes(post.type) && post.id && post.content)