This commit is contained in:
znetsixe
2026-03-11 11:13:05 +01:00
parent c60aa40666
commit 27a6d3c709
20 changed files with 1555 additions and 229 deletions

View File

@@ -25,7 +25,11 @@ class AssetLoader {
*/
loadAsset(datasetType, assetId) {
//const cacheKey = `${datasetType}/${assetId}`;
const cacheKey = `${assetId}`;
const normalizedAssetId = String(assetId || '').trim();
if (!normalizedAssetId) {
return null;
}
const cacheKey = normalizedAssetId.toLowerCase();
// Check cache first
@@ -34,11 +38,11 @@ class AssetLoader {
}
try {
const filePath = path.join(this.baseDir, `${assetId}.json`);
const filePath = this._resolveAssetPath(normalizedAssetId);
// Check if file exists
if (!fs.existsSync(filePath)) {
console.warn(`Asset not found: ${filePath}`);
if (!filePath || !fs.existsSync(filePath)) {
console.warn(`Asset not found for id '${normalizedAssetId}' in ${this.baseDir}`);
return null;
}
@@ -56,6 +60,21 @@ class AssetLoader {
}
}
_resolveAssetPath(assetId) {
const exactPath = path.join(this.baseDir, `${assetId}.json`);
if (fs.existsSync(exactPath)) {
return exactPath;
}
const target = `${assetId}.json`.toLowerCase();
const files = fs.readdirSync(this.baseDir);
const matched = files.find((file) => file.toLowerCase() === target);
if (!matched) {
return null;
}
return path.join(this.baseDir, matched);
}
/**
* Get all available assets in a dataset
* @param {string} datasetType - The dataset folder name
@@ -121,4 +140,4 @@ console.log('Available curves:', availableCurves);
const { AssetLoader } = require('./index.js');
const customLoader = new AssetLoader();
const data = customLoader.loadCurve('hidrostal-H05K-S03R');
*/
*/