diff --git a/.gitignore b/.gitignore index e5c484a..b262bb5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ .depbe.sh node_modules node_modules/* +**/package-lock.json backend/.env backend/images backend/images/* diff --git a/backend/services/modelsProxyService.js b/backend/services/modelsProxyService.js index d1249c8..6a99175 100644 --- a/backend/services/modelsProxyService.js +++ b/backend/services/modelsProxyService.js @@ -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();