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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,6 +5,7 @@
|
||||
.depbe.sh
|
||||
node_modules
|
||||
node_modules/*
|
||||
**/package-lock.json
|
||||
backend/.env
|
||||
backend/images
|
||||
backend/images/*
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user