feat(gateway): add scoped proxy egress deployment

This commit is contained in:
wmq
2026-08-01 19:53:29 +08:00
parent 06112602ec
commit cf25d71fcf
14 changed files with 114 additions and 4 deletions
@@ -171,7 +171,7 @@ export class TgAccountsService implements OnModuleInit {
const binding = await this.bindingRepo.findOne({
where: { accountId, isActive: true },
});
if (!binding) return undefined;
if (!binding) return this.getDefaultProxy();
const proxy = await this.proxyRepo
.createQueryBuilder('proxy')
@@ -179,7 +179,7 @@ export class TgAccountsService implements OnModuleInit {
.where('proxy.id = :id', { id: binding.proxyId })
.andWhere('proxy.isActive = :isActive', { isActive: true })
.getOne();
if (!proxy) return undefined;
if (!proxy) return this.getDefaultProxy();
return {
type: proxy.type,
@@ -190,4 +190,27 @@ export class TgAccountsService implements OnModuleInit {
secret: proxy.secret,
};
}
private getDefaultProxy() {
const host = String(process.env.TG_DEFAULT_PROXY_HOST || '').trim();
const port = Number(process.env.TG_DEFAULT_PROXY_PORT || 0);
if (!host || !Number.isInteger(port) || port < 1 || port > 65535) {
return undefined;
}
const type = String(process.env.TG_DEFAULT_PROXY_TYPE || 'socks5').toLowerCase();
if (!['socks5', 'http', 'mtproto'].includes(type)) {
this.logger.warn(`Ignoring unsupported TG_DEFAULT_PROXY_TYPE: ${type}`);
return undefined;
}
return {
type,
host,
port,
username: process.env.TG_DEFAULT_PROXY_USERNAME || '',
password: process.env.TG_DEFAULT_PROXY_PASSWORD || '',
secret: process.env.TG_DEFAULT_PROXY_SECRET || '',
};
}
}