fix: SF3 download prefers SF2, cache invalidation on parse error

- Download endpoint reverses extension priority: .sf2 > .sf3
- loadSoundFont adds ?t= cache-buster, invalidates IndexedDB on error
- Retry logic: delete corrupted cache entry, allow re-download
This commit is contained in:
2026-07-26 18:37:46 +07:00
parent e7a0a85eca
commit 5096c618b4
2 changed files with 17 additions and 6 deletions
+13 -2
View File
@@ -91,7 +91,7 @@
}
if (!buffer) {
try {
const resp = await fetch("/api/v1/plugins/soundfonts/download/" + encodeURIComponent(sfId));
const resp = await fetch("/api/v1/plugins/soundfonts/download/" + encodeURIComponent(sfId) + "?t=" + Date.now());
if (!resp.ok) throw new Error("Download failed: " + resp.status);
buffer = await resp.arrayBuffer();
if (window.SonicSFStorage) {
@@ -107,7 +107,18 @@
_currentSfId = sfId;
console.log("[SonicSF] SoundFont loaded:", sfId);
} catch (e) {
console.error("[SonicSF] Error parsing SF in SpessaSynth:", e);
console.error("[SonicSF] Error parsing SF in SpessaSynth:", sfId, e);
// Invalidate cache and retry once with fresh download
if (window.SonicSFStorage) {
try {
const db = await window.SonicSFStorage.openDB();
const tx = db.transaction(window.SonicSFStorage.storeName, "readwrite");
tx.objectStore(window.SonicSFStorage.storeName).delete(sfId);
console.log("[SonicSF] Invalidated cache for:", sfId);
} catch (ce) {}
}
// Clear current SF so next load will actually run
_currentSfId = null;
}
},