Skip to content

Commit

Permalink
feat(route/telegram): add mtproxy support for tglib
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Nov 5, 2024
1 parent 9876331 commit b4fece4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
13 changes: 13 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ export type Config = {
telegram: {
token?: string;
session?: string;
apiId?: number;
apiHash?: string;
maxConcurrentDownloads?: number;
proxy?: {
host?: string;
port?: number;
secret?: string;
};
};
tophub: {
cookie?: string;
Expand Down Expand Up @@ -709,6 +717,11 @@ const calculateValue = () => {
apiId: envs.TELEGRAM_API_ID,
apiHash: envs.TELEGRAM_API_HASH,
maxConcurrentDownloads: envs.TELEGRAM_MAX_CONCURRENT_DOWNLOADS,
proxy: {
host: envs.TELEGRAM_PROXY_HOST,
port: envs.TELEGRAM_PROXY_PORT,
secret: envs.TELEGRAM_PROXY_SECRET,
},
},
tophub: {
cookie: envs.TOPHUB_COOKIE,
Expand Down
30 changes: 30 additions & 0 deletions lib/routes/telegram/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,36 @@ For backward compatibility reasons, invalid \`routeParams\` will be treated as \
optional: true,
description: 'Telegram API Authentication',
},
{
name: 'TELEGRAM_API_ID',
optional: true,
description: 'Telegram API ID',
},
{
name: 'TELEGRAM_API_HASH',
optional: true,
description: 'Telegram API Hash',
},
{
name: 'TELEGRAM_MAX_CONCURRENT_DOWNLOADS',
optional: true,
description: 'Telegram Max Concurrent Downloads',
},
{
name: 'TELEGRAM_PROXY_HOST',
optional: true,
description: 'Telegram Proxy Host',
},
{
name: 'TELEGRAM_PROXY_PORT',
optional: true,
description: 'Telegram Proxy Port',
},
{
name: 'TELEGRAM_PROXY_SECRET',
optional: true,
description: 'Telegram Proxy Secret',
},
],
requirePuppeteer: false,
antiCrawler: false,
Expand Down
18 changes: 11 additions & 7 deletions lib/routes/telegram/tglib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ export async function getClient(authParams?: UserAuthParams, session?: string) {
autoReconnect: true,
retryDelay: 3000,
maxConcurrentDownloads: Number(config.telegram.maxConcurrentDownloads ?? 10),
proxy:
config.telegram.proxy?.host && config.telegram.proxy.port && config.telegram.proxy.secret
? {
ip: config.telegram.proxy.host,
port: Number(config.telegram.proxy.port),
MTProxy: true,
secret: config.telegram.proxy.secret,
}
: undefined,
});
await client.start(
Object.assign(authParams ?? {}, {
onError: (err) => {
throw new Error('Cannot start TG: ' + err);
},
}) as any
);

await client.connect();
return client;
}

Expand Down

0 comments on commit b4fece4

Please sign in to comment.