mirror of
https://github.com/d0zingcat/BroadcastChannel.git
synced 2026-05-13 23:16:46 +00:00
feat: enable conditional loading of reactions in getPost function
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user