diff --git a/lib/routes/telegram/tglib/channel.ts b/lib/routes/telegram/tglib/channel.ts index 655f9389c..ca604c6c8 100644 --- a/lib/routes/telegram/tglib/channel.ts +++ b/lib/routes/telegram/tglib/channel.ts @@ -5,6 +5,8 @@ import { Api } from 'telegram'; import { HTMLParser } from 'telegram/extensions/html.js'; import { getClient, getDocument, getFilename, unwrapMedia } from './client'; import { getDisplayName } from 'telegram/Utils.js'; +import cache from '@/utils/cache'; +import { returnBigInt } from 'telegram/Helpers.js'; export function getGeoLink(geo: Api.GeoPoint) { return `Geo LatLon: ${geo.lat}, ${geo.long}`; @@ -114,7 +116,16 @@ export function humanDuration(seconds: number) { export default async function handler(ctx: Context) { const client = await getClient(); const username = ctx.req.param('username'); - const peer = await client.getInputEntity(username); + + let peerCache = await cache.get(`telegram:inputEntity:${username}`); + if (!peerCache) { + const p = await client.getInputEntity(username); + peerCache = JSON.stringify(p.toJSON()); + await cache.set(`telegram:inputEntity:${username}`, peerCache); + } + const peerData = JSON.parse(peerCache, (k, v) => (k === 'channelId' || k === 'accessHash' ? returnBigInt(v) : v)); + const peer = new Api.InputPeerChannel(peerData); + const entity = await client.getEntity(peer); let attachments: string[] = [];