updates
This commit is contained in:
@@ -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');
|
||||
*/
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user