Fix blob: urls

This commit is contained in:
Ethan O'Brien 2023-07-03 22:56:29 -05:00
parent 2e09e83493
commit d8d6db6d82

View file

@ -135,7 +135,7 @@ class EmulatorJS {
let res; let res;
try { try {
res = await fetch(path); res = await fetch(path);
if (opts.type && opts.type.toLowerCase() === 'arraybuffer') { if ((opts.type && opts.type.toLowerCase() === 'arraybuffer') || !opts.type) {
res = await res.arrayBuffer(); res = await res.arrayBuffer();
} else { } else {
res = await res.text(); res = await res.text();
@ -149,7 +149,7 @@ class EmulatorJS {
data: res, data: res,
headers: {} headers: {}
}); });
}) })();
} }
} }
constructor(element, config) { constructor(element, config) {
@ -558,7 +558,7 @@ class EmulatorJS {
}, true, {responseType: "arraybuffer", method: "GET"}); }, true, {responseType: "arraybuffer", method: "GET"});
} }
downloadBios() { downloadBios() {
if (typeof this.config.biosUrl !== "string") { if (typeof this.config.biosUrl !== "string" || !this.config.biosUrl.trim()) {
this.downloadStartState(); this.downloadStartState();
return; return;
} }
@ -591,10 +591,12 @@ class EmulatorJS {
return; return;
} }
gotBios(res.data); gotBios(res.data);
this.storage.bios.put(this.config.biosUrl.split("/").pop(), { if (this.saveInBrowserSupported()) {
"content-length": res.headers['content-length'], this.storage.bios.put(this.config.biosUrl.split("/").pop(), {
data: res.data "content-length": res.headers['content-length'],
}) data: res.data
})
}
}, (progress) => { }, (progress) => {
this.textElem.innerText = this.localization("Download Game BIOS") + progress; this.textElem.innerText = this.localization("Download Game BIOS") + progress;
}, true, {responseType: "arraybuffer", method: "GET"}); }, true, {responseType: "arraybuffer", method: "GET"});
@ -615,7 +617,7 @@ class EmulatorJS {
this.checkCompression(new Uint8Array(data), this.localization("Decompress Game Data")).then((data) => { this.checkCompression(new Uint8Array(data), this.localization("Decompress Game Data")).then((data) => {
for (const k in data) { for (const k in data) {
if (k === "!!notCompressedData") { if (k === "!!notCompressedData") {
this.fileName = this.config.gameUrl.split('/').pop().split("#")[0].split("?")[0]; this.fileName = this.config.gameUrl.startsWith("blob:") ? this.config.gameName || "game" : this.config.gameUrl.split('/').pop().split("#")[0].split("?")[0];
FS.writeFile(this.fileName, data[k]); FS.writeFile(this.fileName, data[k]);
break; break;
} }
@ -648,7 +650,7 @@ class EmulatorJS {
} }
gotGameData(res.data); gotGameData(res.data);
const limit = (typeof this.config.cacheLimit === "number") ? this.config.cacheLimit : 1073741824; const limit = (typeof this.config.cacheLimit === "number") ? this.config.cacheLimit : 1073741824;
if (parseFloat(res.headers['content-length']) < limit) { if (parseFloat(res.headers['content-length']) < limit && this.saveInBrowserSupported()) {
this.storage.rom.put(this.config.gameUrl.split("/").pop(), { this.storage.rom.put(this.config.gameUrl.split("/").pop(), {
"content-length": res.headers['content-length'], "content-length": res.headers['content-length'],
data: res.data data: res.data
@ -700,8 +702,6 @@ class EmulatorJS {
console.log(args); console.log(args);
this.Module.callMain(args); this.Module.callMain(args);
this.Module.resumeMainLoop(); this.Module.resumeMainLoop();
this.started = true;
this.paused = false;
if (this.touch) { if (this.touch) {
this.virtualGamepad.style.display = ""; this.virtualGamepad.style.display = "";
} }
@ -718,10 +718,13 @@ class EmulatorJS {
this.game.classList.remove("ejs_game"); this.game.classList.remove("ejs_game");
this.game.appendChild(this.canvas); this.game.appendChild(this.canvas);
this.handleResize(); this.handleResize();
this.started = true;
this.paused = false;
} catch(e) { } catch(e) {
console.warn("failed to start game", e); console.warn("failed to start game", e);
this.textElem.innerText = "Failed to start game"; this.textElem.innerText = "Failed to start game";
this.textElem.style.color = "red"; this.textElem.style.color = "red";
return;
} }
this.callEvent("start"); this.callEvent("start");
} }