fix(mikrotikConfigRoutes): enhance script execution logic to find script ID before running
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m9s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m9s
This commit is contained in:
@@ -295,8 +295,12 @@ async function runScript(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const client = createRosClient(creds);
|
const client = createRosClient(creds);
|
||||||
// /rest/system/script/run — запуск скрипта по имени (.id принимает имя скрипта)
|
// Сначала находим скрипт по имени, затем запускаем по .id
|
||||||
await client.command('system/script/run', { '.id': script });
|
const scripts = await client.print('system/script');
|
||||||
|
const list = Array.isArray(scripts?.data) ? scripts.data : (scripts?.data ? [scripts.data] : []);
|
||||||
|
const found = list.find(s => (s.name || s['.id']) === script);
|
||||||
|
const scriptId = found ? (found['.id'] || found.name) : script;
|
||||||
|
await client.command('system/script/run', { '.id': scriptId });
|
||||||
|
|
||||||
return sendOk(res, { ok: true, message: `Скрипт ${script} запущен` });
|
return sendOk(res, { ok: true, message: `Скрипт ${script} запущен` });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -23,16 +23,19 @@ function createRosClient(opts) {
|
|||||||
const auth = Buffer.from(`${user}:${password || ''}`).toString('base64');
|
const auth = Buffer.from(`${user}:${password || ''}`).toString('base64');
|
||||||
const cleanPath = (urlPath.startsWith('/') ? urlPath.slice(1) : urlPath).replace(/\\/g, '/');
|
const cleanPath = (urlPath.startsWith('/') ? urlPath.slice(1) : urlPath).replace(/\\/g, '/');
|
||||||
const pathStr = `/rest/${cleanPath}`.replace(/\/+/g, '/');
|
const pathStr = `/rest/${cleanPath}`.replace(/\/+/g, '/');
|
||||||
|
const bodyStr = (body !== null && body !== undefined) ? JSON.stringify(body) : '';
|
||||||
|
const headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Basic ${auth}`,
|
||||||
|
};
|
||||||
|
if (bodyStr) headers['Content-Length'] = Buffer.byteLength(bodyStr, 'utf8');
|
||||||
const options = {
|
const options = {
|
||||||
hostname: host,
|
hostname: host,
|
||||||
port,
|
port,
|
||||||
path: pathStr,
|
path: pathStr,
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers,
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'Authorization': `Basic ${auth}`,
|
|
||||||
},
|
|
||||||
rejectUnauthorized: secure,
|
rejectUnauthorized: secure,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,9 +60,7 @@ function createRosClient(opts) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', reject);
|
req.on('error', reject);
|
||||||
if (body !== null && body !== undefined) {
|
if (bodyStr) req.write(bodyStr);
|
||||||
req.write(JSON.stringify(body));
|
|
||||||
}
|
|
||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user