feat(route/telegram): add mtproxy support for tglib
This commit is contained in:
parent
98763316e2
commit
b4fece47ed
|
|
@ -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;
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue