fix errors

This commit is contained in:
Den Piligrim
2026-02-03 10:34:24 +03:00
parent 10208930ff
commit 007afd3b83
8 changed files with 113 additions and 17 deletions
+6 -3
View File
@@ -58,16 +58,18 @@ export class RotationService {
const isLoginSuccess = await this.xuiService.login();
if (!isLoginSuccess) {
this.logger.error('Отмена ротации: Не удалось войти в панель 3x-ui');
return;
return { success: false, message: 'Не удалось войти в панель 3x-ui' };
}
const subscriptions = await this.subRepo.find({ where: { isEnabled: true }, relations: ['inbounds'] });
if (subscriptions.length === 0) return;
if (subscriptions.length === 0) {
return { success: false, message: 'Нет активных подписок для ротации' };
}
const domains = await this.domainRepo.find({ where: { isEnabled: true } });
if (domains.length === 0) {
this.logger.warn('Список доменов пуст! Ротация невозможна.');
return;
return { success: false, message: 'Список доменов пуст!' };
}
for (const sub of subscriptions) {
@@ -75,6 +77,7 @@ export class RotationService {
}
this.logger.log('Ротация завершена.');
return { success: true, message: 'Ротация успешно выполнена' };
}
private async rotateSubscription(sub: Subscription, domains: Domain[]) {
@@ -4,12 +4,14 @@ import { Repository } from 'typeorm';
import { Setting } from './entities/setting.entity';
import * as dns from 'dns/promises';
import { COUNTRIES } from './countries';
import { XuiService } from 'src/xui/xui.service';
@Controller('settings')
export class SettingsController {
constructor(
@InjectRepository(Setting)
private settingsRepo: Repository<Setting>,
private xuiService: XuiService
) {}
@Get()
@@ -18,6 +20,12 @@ export class SettingsController {
return settings.reduce((acc, curr) => ({ ...acc, [curr.key]: curr.value }), {});
}
@Post('check')
async checkConnection(@Body() body: { xui_url: string; xui_login: string; xui_password: string }) {
const success = await this.xuiService.checkConnection(body.xui_url, body.xui_login, body.xui_password);
return { success };
}
@Post()
async update(@Body() settings: Record<string, string>) {
if (settings.xui_url) {
+2 -1
View File
@@ -2,9 +2,10 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { SettingsController } from './settings.controller';
import { Setting } from './entities/setting.entity';
import { XuiModule } from 'src/xui/xui.module';
@Module({
imports: [TypeOrmModule.forFeature([Setting])],
imports: [TypeOrmModule.forFeature([Setting]), XuiModule],
controllers: [SettingsController],
})
export class SettingsModule {}
@@ -11,7 +11,6 @@ export class SubscriptionsService {
constructor(
@InjectRepository(Subscription)
private subRepo: Repository<Subscription>,
@InjectRepository(Inbound)
private xuiService: XuiService,
) {}
+23
View File
@@ -119,6 +119,29 @@ export class XuiService {
}
}
async checkConnection(url: string, username: string, pass: string): Promise<boolean> {
try {
const tempApi = axios.create({
baseURL: url,
timeout: 5000,
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
withCredentials: true
});
const res = await tempApi.post('/login', {
username: username,
password: pass,
});
if (res.headers['set-cookie'] && res.data?.success) {
return true;
}
} catch (e) {
this.logger.warn(`Ошибка авторизации: ${e.message}`);
}
return false;
}
async getNewX25519Cert() {
try {
const res = await this.api.get('/panel/api/server/getNewX25519Cert');