fixes JSZip throw when checking if a file is a zip

This commit is contained in:
@wwwjim 2020-11-15 18:31:18 -08:00
parent 7306b3bd8b
commit de50a08a2c
2 changed files with 10 additions and 7 deletions

View File

@ -79,7 +79,6 @@ export const upload = async ({ file, context, bucketName, routes }) => {
});
XHR.open("post", path, true);
XHR.setRequestHeader("authorization", getCookie(Credentials.session.key));
XHR.onerror = (event) => {
console.log(event);

View File

@ -148,13 +148,17 @@ export const isPreviewableImage = (type = "") => {
};
export const isUnityFile = async (file) => {
const zip = new JSZip();
try {
const zip = new JSZip();
const contents = await zip.loadAsync(file);
const fileNames = Object.keys(contents.files);
const contents = await zip.loadAsync(file);
const fileNames = Object.keys(contents.files);
// NOTE(daniel): every Unity game file will have this file
const unityRegex = new RegExp(/unityloader.js/i);
// NOTE(daniel): every Unity game file will have this file
const unityRegex = new RegExp(/unityloader.js/i);
return fileNames.some((file) => unityRegex.test(file));
return fileNames.some((file) => unityRegex.test(file));
} catch (e) {
return false;
}
};