Files
cad-data-router/services/router.js

40 lines
942 B
JavaScript
Raw Normal View History

2026-03-05 14:45:06 +01:00
const path = require('path');
function getCadType(filename) {
const baseName = path.basename(filename).toLowerCase();
const match = baseName.match(/\.(prt|asm|drw|dwr)(?:\.\d+)?$/);
return match ? match[1] : null;
}
2026-03-05 14:45:06 +01:00
function findDestination(filename, config) {
const cadType = getCadType(filename);
const globalDestination = typeof config?.destination === 'string' ? config.destination.trim() : '';
if (globalDestination && cadType) {
return globalDestination;
}
2026-03-05 14:45:06 +01:00
for (const rule of config.rules || []) {
if ((rule.ext || '').toLowerCase() !== cadType) {
2026-03-05 14:45:06 +01:00
continue;
}
if (!rule.pattern) {
return rule.destination;
}
const regex = new RegExp(rule.pattern);
if (regex.test(path.basename(filename))) {
return rule.destination;
}
}
return null;
}
function isCadFile(filename) {
return Boolean(getCadType(filename));
2026-03-05 14:45:06 +01:00
}
module.exports = { findDestination, isCadFile };