Skip to content

Commit

Permalink
Catch exception for isValidGLB
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Jun 21, 2023
1 parent 20f0f47 commit af29349
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/utils/scene-url-utils.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { isLocalHubsSceneUrl, proxiedUrlFor } from "../utils/media-url-utils";

export async function isValidGLB(url) {
return fetch(url).then(async r => {
const reader = r.body.getReader();
let header = "";
function readChunk({ done, value }) {
header += String.fromCharCode.apply(null, value.slice(0, 4));
if (!done && header.length < 4) {
return reader.read().then(readChunk);
} else {
reader.cancel();
return fetch(url)
.then(async r => {
const reader = r.body.getReader();
let header = "";
function readChunk({ done, value }) {
header += String.fromCharCode.apply(null, value.slice(0, 4));
if (!done && header.length < 4) {
return reader.read().then(readChunk);
} else {
reader.cancel();
}
}
}
await reader.read().then(readChunk);
return header.startsWith("glTF");
});
await reader.read().then(readChunk);
return header.startsWith("glTF");
})
.catch(e => console.error(e));
}

export async function isValidSceneUrl(url) {
Expand Down

0 comments on commit af29349

Please sign in to comment.