refactor(measurement): modularize editor JS

Move inline <script> from measurement.html into 8 modules under
src/editor/. measurement.js adds the static-file routes that serve them
to Node-RED.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
lzm
2026-05-28 08:59:28 +02:00
parent 36eaa2f859
commit d7f6613892
10 changed files with 1570 additions and 270 deletions

View File

@@ -1,4 +1,5 @@
const nameOfNode = 'measurement'; // this is the name of the node, it should match the file name and the node type in Node-RED
const path = require('path');
const nodeClass = require('./src/nodeClass.js'); // this is the specific node class
const { MenuManager, configManager, assetApiConfig } = require('generalFunctions');
const assetUtils = require('generalFunctions/assetUtils');
@@ -38,6 +39,18 @@ module.exports = function(RED) {
}
});
// Editor JS modules — loaded by measurement.html via <script src=...> tags.
// Files live in src/editor/. Filename is restricted to a safe charset to
// prevent path-traversal. Mirror of the pumpingStation pattern.
RED.httpAdmin.get(`/${nameOfNode}/editor/:file`, (req, res) => {
const safe = String(req.params.file || '').replace(/[^a-zA-Z0-9._-]/g, '');
if (!safe.endsWith('.js')) return res.status(400).send('// invalid');
res.type('application/javascript');
res.sendFile(path.join(__dirname, 'src', 'editor', safe), (err) => {
if (err && !res.headersSent) res.status(404).send('// editor module not found');
});
});
RED.httpAdmin.post(`/${nameOfNode}/asset-reg`, async (req, res) => {
const body = req.body || {};
const assetPayload = body.asset;