feat(gateway): add scoped proxy egress deployment
This commit is contained in:
@@ -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 || '',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user