feat(ping): refine interface selection logic to prioritize 'ether1' and 'ether2' before falling back to other 'ether' interfaces
Publish Fast Tabler Docker image / build-and-push-fast (push) Failing after 2m49s
Publish Fast Tabler Docker image / build-and-push-fast (push) Failing after 2m49s
This commit is contained in:
@@ -393,21 +393,28 @@ async function pingViaInterface(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 4) Последний фоллбек: если ifaceName до сих пор не определён,
|
// 4) Последний фоллбек: если ifaceName до сих пор не определён,
|
||||||
// пробуем взять первый интерфейс, имя которого начинается с "ether"
|
// пробуем взять первый физический порт ether1/ether2 (если есть),
|
||||||
// (обычно это основной WAN/LAN-порт).
|
// иначе любой интерфейс с префиксом "ether".
|
||||||
if (!ifaceName) {
|
if (!ifaceName) {
|
||||||
try {
|
try {
|
||||||
const ifRes = await client.command('interface/print', {
|
const ifRes = await client.command('interface/print', {
|
||||||
'.proplist': ['name'],
|
'.proplist': ['name'],
|
||||||
'.query': ['name~^ether'],
|
|
||||||
});
|
});
|
||||||
const data = ifRes?.data;
|
const data = ifRes?.data;
|
||||||
const interfaces = Array.isArray(data) ? data : (data ? [data] : []);
|
const interfaces = Array.isArray(data) ? data : (data ? [data] : []);
|
||||||
const firstEther = interfaces.find(
|
const names = interfaces
|
||||||
(it) => typeof it.name === 'string' && it.name.toLowerCase().startsWith('ether'),
|
.map((it) => (typeof it.name === 'string' ? it.name : null))
|
||||||
);
|
.filter(Boolean);
|
||||||
if (firstEther && typeof firstEther.name === 'string') {
|
|
||||||
ifaceName = firstEther.name;
|
let candidate = null;
|
||||||
|
if (names.includes('ether1')) candidate = 'ether1';
|
||||||
|
else if (names.includes('ether2')) candidate = 'ether2';
|
||||||
|
else {
|
||||||
|
candidate = names.find((n) => n.toLowerCase().startsWith('ether')) || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (candidate) {
|
||||||
|
ifaceName = candidate;
|
||||||
}
|
}
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// Если не получилось прочитать интерфейсы — просто продолжаем без interface.
|
// Если не получилось прочитать интерфейсы — просто продолжаем без interface.
|
||||||
|
|||||||
Reference in New Issue
Block a user