Enhance model path handling in modelsProxyService.js

- Refactored model source directory logic to dynamically select between production and local paths.
- Updated error messages to provide clearer context on model source lookup failures.
- Added package-lock.json to .gitignore to streamline dependency management.
This commit is contained in:
Torsten Schulz (local)
2026-01-22 13:50:47 +01:00
parent a8fdcd179e
commit 69a83c584b
2 changed files with 12 additions and 3 deletions

View File

@@ -11,10 +11,17 @@ import { spawn } from 'child_process';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const BACKEND_DIR = path.join(__dirname, '..');
const PROJECT_ROOT = path.join(BACKEND_DIR, '..');
const SOURCE_DIR = path.join(PROJECT_ROOT, 'frontend', 'public', 'models', '3d', 'falukant', 'characters');
const MODELS_REL = path.join('models', '3d', 'falukant', 'characters');
const DIST_MODELS = path.join(PROJECT_ROOT, 'frontend', 'dist', MODELS_REL);
const PUBLIC_MODELS = path.join(PROJECT_ROOT, 'frontend', 'public', MODELS_REL);
const CACHE_DIR = path.join(BACKEND_DIR, 'data', 'model-cache');
const CLI_PATH = path.join(BACKEND_DIR, 'node_modules', '.bin', 'gltf-transform');
/** Production: frontend/dist; Local: frontend/public. Ermittelt bei Bedarf. */
function getSourceDir() {
return fs.existsSync(DIST_MODELS) ? DIST_MODELS : PUBLIC_MODELS;
}
/** Erlaubte Dateinamen (nur [a-z0-9_.-]+.glb) */
const FILENAME_RE = /^[a-z0-9_.-]+\.glb$/i;
@@ -80,12 +87,13 @@ export async function getOptimizedModelPath(filename) {
throw new Error(`Invalid model filename: ${filename}`);
}
const sourcePath = path.join(SOURCE_DIR, filename);
const sourceDir = getSourceDir();
const sourcePath = path.join(sourceDir, filename);
const cacheFilename = filename.replace(/\.glb$/, '_opt.glb');
const cachePath = path.join(CACHE_DIR, cacheFilename);
if (!fs.existsSync(sourcePath)) {
throw new Error(`Source model not found: ${filename}`);
throw new Error(`Source model not found: ${filename} (looked in ${sourceDir})`);
}
ensureCacheDir();