feat(mikrotik-config): add OSPF area comparison and enhance template application logic
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m35s

This commit is contained in:
2026-03-05 16:13:13 +07:00
parent f77d71f22c
commit 5d66f04286
2 changed files with 129 additions and 206 deletions
+21 -5
View File
@@ -1489,6 +1489,12 @@ function sameOspfInterface(a, b) {
return String(a || '').trim().toUpperCase() === String(b || '').trim().toUpperCase();
}
function sameOspfArea(a, b) {
const left = String(a || '').trim().toUpperCase() || 'BACKBONE';
const right = String(b || '').trim().toUpperCase() || 'BACKBONE';
return left === right;
}
/**
* GET /api/mikrotik/ospf-interface-templates?serverId=
* Возвращает текущие OSPF interface-template с HOME роутеров.
@@ -1567,7 +1573,7 @@ async function getOspfInterfaceTemplates(req, res) {
/**
* POST /api/mikrotik/ospf-interface-templates/apply
* Body: { servers: [{ serverId, templates: [{ interfaceName, cost }] }] }
* Body: { servers: [{ serverId, templates: [{ rosId?, interfaceName, area?, cost }] }] }
*/
async function applyOspfInterfaceTemplates(req, res) {
try {
@@ -1611,17 +1617,27 @@ async function applyOspfInterfaceTemplates(req, res) {
let invalid = 0;
for (const desired of desiredTemplates) {
const desiredRosId = String(desired?.rosId || '').trim();
const interfaceName = String(desired?.interfaceName || '').trim();
const desiredArea = String(desired?.area || '').trim();
const desiredCost = parseOspfCost(desired?.cost);
if (!interfaceName || desiredCost == null) {
if ((!interfaceName && !desiredRosId) || desiredCost == null) {
invalid += 1;
continue;
}
const match = existing.find((item) =>
sameOspfInterface(normalizeOspfInterfaceName(item), interfaceName)
);
let match = null;
if (desiredRosId) {
match = existing.find((item) => String(item?.['.id'] || '') === desiredRosId);
}
if (!match && interfaceName) {
match = existing.find((item) => {
if (!sameOspfInterface(normalizeOspfInterfaceName(item), interfaceName)) return false;
if (!desiredArea) return true;
return sameOspfArea(item?.area, desiredArea);
});
}
if (!match || !match['.id']) {
missing += 1;