fix(assets): Zielpfad der Aufbereitung unabhängig vom Arbeitsverzeichnis

places.mjs schrieb bisher nach public/models/places/<id>.glb relativ
zu process.cwd() und nahm jede id ungeprüft an. Die neue, exportierte
placeTarget(id) löst den Pfad stattdessen von import.meta.url ab (egal
von wo das Skript aufgerufen wird) und lehnt IDs außerhalb von
[a-z0-9-]+ ab, bevor daraus ein Pfad wird, der aus public/models/
places/ herausführen könnte.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
knsoandClaude Sonnet 5 committed 2026-09-14 13:41:18 +02:00
1 parent ed5254f88e
commit 23a0623898
2 files changed
+37 -4

No files matched your search

+17 -3
View File
@@ -8,7 +8,7 @@
// verwirft EXT_materials_bump, und darin steckt das Wellblech der Container (bumpExtension.mjs).
import { mkdir, stat } from "node:fs/promises";
import { dirname } from "node:path";
import { pathToFileURL } from "node:url";
import { fileURLToPath, pathToFileURL } from "node:url";
import { ExtensionProperty, NodeIO, PropertyType } from "@gltf-transform/core";
import { ALL_EXTENSIONS, EXTTextureWebP } from "@gltf-transform/extensions";
import { compressTexture, dedup, flatten, getBounds, join, listTextureSlots, meshopt, prune,
@@ -119,13 +119,27 @@ export function describePlace(document) {
};
}
/**
* Zielpfad für ein aufbereitetes Modell, absolut und unabhängig vom Arbeitsverzeichnis (public/
* models/places/<id>.glb, relativ zu dieser Datei aufgelöst statt zu process.cwd()). id landet auch
* in src/world/places.js (PLACES) und im Dateinamen — nur Kleinbuchstaben, Ziffern und Bindestrich,
* damit sie auf jedem Dateisystem gleich aussieht und nicht aus public/models/places/ herausführt.
*/
export function placeTarget(id) {
if (!/^[a-z0-9-]+$/.test(id)) {
throw new Error(`Ungültige Orts-ID "${id}": erlaubt sind nur Kleinbuchstaben, Ziffern und Bindestrich.`);
}
const dir = new URL("../../public/models/places/", import.meta.url);
return fileURLToPath(new URL(`${id}.glb`, dir));
}
async function main() {
const [source, id] = process.argv.slice(2);
if (!source || !id) {
console.error("Aufruf: node tools/assets/places.mjs <quelle.glb> <id>");
console.error("Aufruf: node tools/assets/places.mjs <quelle.glb> <id (Kleinbuchstaben, Ziffern, Bindestrich)>");
process.exit(1);
}
const target = `public/models/places/${id}.glb`;
const target = placeTarget(id);
const io = new NodeIO()
.registerExtensions([...ALL_EXTENSIONS, EXTMaterialsBump])
.registerDependencies({ "meshopt.encoder": MeshoptEncoder });