Refactor source directory handling in modelsProxyService.js

- Introduced a cached source directory variable to optimize the retrieval of model paths.
- Updated comments for clarity on the source directory logic and its impact on cache validation.
This commit is contained in:
Torsten Schulz (local)
2026-01-22 15:50:46 +01:00
parent 69a83c584b
commit 82734e8383

View File

@@ -17,9 +17,15 @@ const PUBLIC_MODELS = path.join(PROJECT_ROOT, 'frontend', 'public', MODELS_REL);
const CACHE_DIR = path.join(BACKEND_DIR, 'data', 'model-cache'); const CACHE_DIR = path.join(BACKEND_DIR, 'data', 'model-cache');
const CLI_PATH = path.join(BACKEND_DIR, 'node_modules', '.bin', 'gltf-transform'); const CLI_PATH = path.join(BACKEND_DIR, 'node_modules', '.bin', 'gltf-transform');
/** Production: frontend/dist; Local: frontend/public. Ermittelt bei Bedarf. */ /** Einmal ermitteltes Quellverzeichnis (frontend/dist oder frontend/public). */
let _sourceDir = null;
/** Production: frontend/dist; Local: frontend/public. Einmal pro Prozess festgelegt, damit
* isCacheValid() stets gegen dieselbe Quelle prüft (kein Wechsel zwischen dist/public). */
function getSourceDir() { function getSourceDir() {
return fs.existsSync(DIST_MODELS) ? DIST_MODELS : PUBLIC_MODELS; if (_sourceDir !== null) return _sourceDir;
_sourceDir = fs.existsSync(DIST_MODELS) ? DIST_MODELS : PUBLIC_MODELS;
return _sourceDir;
} }
/** Erlaubte Dateinamen (nur [a-z0-9_.-]+.glb) */ /** Erlaubte Dateinamen (nur [a-z0-9_.-]+.glb) */