v2
This commit is contained in:
@@ -316,6 +316,9 @@ export async function syncNovavpsToXray(
|
||||
}
|
||||
|
||||
const outbounds = (config.outbounds as Record<string, unknown>[]) || [];
|
||||
console.log(`[${panelLabel}] Всего outbound'ов в конфиге ДО: ${outbounds.length}`);
|
||||
const existingNovavpsTags = outbounds.filter((o) => String(o.tag || "").startsWith("novavps"));
|
||||
console.log(`[${panelLabel}] Из них с тегом novavps*: ${existingNovavpsTags.length}`);
|
||||
|
||||
connections.forEach((conn, idx) => {
|
||||
const tag = `novavps${idx + 1}`;
|
||||
@@ -324,15 +327,17 @@ export async function syncNovavpsToXray(
|
||||
const existingIdx = outbounds.findIndex((o) => o.tag === tag);
|
||||
if (existingIdx >= 0) {
|
||||
outbounds[existingIdx] = newOutbound;
|
||||
console.log(`[${panelLabel}] Outbound ${tag} обновлён`);
|
||||
console.log(`[${panelLabel}] Outbound ${tag} обновлён (${conn.address})`);
|
||||
} else {
|
||||
outbounds.push(newOutbound);
|
||||
console.log(`[${panelLabel}] Outbound ${tag} добавлен`);
|
||||
console.log(`[${panelLabel}] Outbound ${tag} добавлен (${conn.address})`);
|
||||
}
|
||||
});
|
||||
|
||||
config.outbounds = outbounds;
|
||||
const modifiedJson = JSON.stringify(config, null, 2);
|
||||
const novavpsCountAfter = (outbounds.filter((o) => String(o.tag || "").startsWith("novavps"))).length;
|
||||
console.log(`[${panelLabel}] После модификации: всего outbound'ов ${outbounds.length}, novavps*: ${novavpsCountAfter}`);
|
||||
|
||||
await page.evaluate((json) => {
|
||||
const cm = document.querySelector(".CodeMirror") as unknown as { CodeMirror?: { setValue: (v: string) => void } };
|
||||
@@ -350,7 +355,7 @@ export async function syncNovavpsToXray(
|
||||
});
|
||||
}, modifiedJson);
|
||||
|
||||
await page.waitForTimeout(500);
|
||||
await page.waitForTimeout(1500);
|
||||
|
||||
const saved = await page.evaluate(() => {
|
||||
let clicked = false;
|
||||
@@ -366,13 +371,41 @@ export async function syncNovavpsToXray(
|
||||
});
|
||||
|
||||
if (saved) {
|
||||
console.log(`[${panelLabel}] Конфиг сохранён`);
|
||||
await page.waitForTimeout(2000);
|
||||
console.log(`[${panelLabel}] Кнопка 'Сохранить' нажата, жду сохранения...`);
|
||||
await page.waitForTimeout(3000);
|
||||
await page.waitForLoadState("networkidle");
|
||||
} else {
|
||||
console.log(`[${panelLabel}] Кнопка 'Сохранить' не найдена`);
|
||||
}
|
||||
|
||||
// Верификация — читаем JSON из редактора и проверяем novavps-теги
|
||||
console.log(`[${panelLabel}] Проверка сохранённого JSON...`);
|
||||
const verifyJson = await page.evaluate(() => {
|
||||
const cm = document.querySelector(".CodeMirror") as unknown as { CodeMirror?: { getValue: () => string } };
|
||||
if (cm?.CodeMirror) return cm.CodeMirror.getValue();
|
||||
const ta = document.querySelector("textarea");
|
||||
return ta?.value || "";
|
||||
});
|
||||
|
||||
if (verifyJson) {
|
||||
try {
|
||||
const verifyConfig = JSON.parse(verifyJson);
|
||||
const verifyOutbounds = (verifyConfig.outbounds as Record<string, unknown>[]) || [];
|
||||
const verifyNovavps = verifyOutbounds.filter((o) => String(o.tag || "").startsWith("novavps"));
|
||||
console.log(`[${panelLabel}] После сохранения: outbound'ов ${verifyOutbounds.length}, novavps*: ${verifyNovavps.length}`);
|
||||
verifyNovavps.forEach((o) => {
|
||||
const settings = (o as Record<string, unknown>).settings as Record<string, unknown> | undefined;
|
||||
const vnext = settings?.vnext as Record<string, unknown>[] | undefined;
|
||||
const addr = vnext?.[0]?.address as string | undefined;
|
||||
console.log(`[${panelLabel}] ${o.tag}: ${addr || "N/A"}`);
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(`[${panelLabel}] Ошибка парсинга JSON при верификации: ${e}`);
|
||||
}
|
||||
} else {
|
||||
console.log(`[${panelLabel}] Не удалось прочитать JSON после сохранения`);
|
||||
}
|
||||
|
||||
await page.goto(`${baseUrl}/panel/`, { waitUntil: "networkidle", timeout: 30000 });
|
||||
await page.waitForTimeout(3000);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user