func optimization
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Setting } from './entities/setting.entity';
|
||||
import * as dns from 'dns/promises';
|
||||
import { COUNTRIES } from './countries';
|
||||
|
||||
@Controller('settings')
|
||||
export class SettingsController {
|
||||
@@ -28,6 +29,37 @@ export class SettingsController {
|
||||
|
||||
settings['xui_ip'] = address;
|
||||
console.log(`Extracted host: ${parsed.hostname} from ${settings.xui_url}`);
|
||||
|
||||
if (address && address !== '127.0.0.1' && address !== 'localhost') {
|
||||
try {
|
||||
console.log(`Определяем страну для IP: ${address}...`);
|
||||
const geoRes = await fetch(`http://ip-api.com/json/${address}`);
|
||||
const geoData: any = await geoRes.json();
|
||||
|
||||
if (geoData.status === 'success') {
|
||||
const countryCode = geoData.countryCode;
|
||||
|
||||
const countryInfo = COUNTRIES.find(c => c.code === countryCode);
|
||||
|
||||
if (countryInfo) {
|
||||
const flagEmoji = countryInfo.emoji;
|
||||
|
||||
settings['xui_geo_country'] = countryInfo.name;
|
||||
settings['xui_geo_flag'] = flagEmoji;
|
||||
|
||||
console.log(`GeoIP Success: ${countryInfo.name} ${flagEmoji}`);
|
||||
} else {
|
||||
console.warn(`Страна с кодом ${countryCode} не найдена в countries.ts`);
|
||||
settings['xui_geo_country'] = geoData.country;
|
||||
settings['xui_geo_flag'] = '';
|
||||
}
|
||||
} else {
|
||||
console.warn(`GeoIP Error: ${geoData.message}`);
|
||||
}
|
||||
} catch (geoError) {
|
||||
console.error(`Ошибка запроса к ip-api.com: ${geoError.message}`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(`Не удалось извлечь хост из URL: ${settings.xui_url}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user