mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-27 01:03:08 +03:00
feat: validate if zip is unity game file or otherwise
This commit is contained in:
parent
0ed17fc797
commit
2a03dd5384
@ -3,6 +3,7 @@ import * as Store from "~/common/store";
|
||||
import * as Constants from "~/common/constants";
|
||||
import * as Credentials from "~/common/credentials";
|
||||
import * as Strings from "~/common/strings";
|
||||
import * as Validations from "~/common/validations";
|
||||
|
||||
import { dispatchCustomEvent } from "~/common/custom-events";
|
||||
import { encode } from "blurhash";
|
||||
@ -48,8 +49,9 @@ export const upload = async ({ file, context, bucketName, routes }) => {
|
||||
return null;
|
||||
}
|
||||
|
||||
const isFileZip =
|
||||
const isZipFile =
|
||||
file.type.startsWith("application/zip") || file.type.startsWith("application/x-zip-compressed");
|
||||
const isUnityFile = await Validations.isUnityFile(file);
|
||||
|
||||
// TODO(jim): Put this somewhere else to handle conversion cases.
|
||||
if (file.type.startsWith("image/heic")) {
|
||||
@ -144,7 +146,7 @@ export const upload = async ({ file, context, bucketName, routes }) => {
|
||||
}
|
||||
|
||||
let res;
|
||||
if (isFileZip) {
|
||||
if (isZipFile && isUnityFile) {
|
||||
res = await _privateUploadMethod(`${zipUploadRoute}${file.name}`, file);
|
||||
} else if (bucketName && bucketName === STAGING_DEAL_BUCKET) {
|
||||
res = await _privateUploadMethod(`${storageDealRoute}${file.name}`, file);
|
||||
|
@ -1,5 +1,7 @@
|
||||
import * as Strings from "~/common/strings";
|
||||
|
||||
import JSZip from "jszip";
|
||||
|
||||
const USERNAME_REGEX = new RegExp("^[a-zA-Z0-9_]{0,}[a-zA-Z]+[0-9]*$");
|
||||
const MIN_PASSWORD_LENGTH = 8;
|
||||
const EMAIL_REGEX = /^[\w-]+@[a-zA-Z0-9_]+?\.[a-zA-Z]{2,50}$/;
|
||||
@ -144,3 +146,13 @@ export const isPreviewableImage = (type = "") => {
|
||||
|
||||
return type.startsWith("image/");
|
||||
};
|
||||
|
||||
export const isUnityFile = async (file) => {
|
||||
const zip = new JSZip();
|
||||
|
||||
const contents = await zip.loadAsync(file);
|
||||
const fileNames = Object.keys(contents.files);
|
||||
|
||||
// NOTE(daniel): every Unity game file will have this file
|
||||
return fileNames.includes("Build/UnityLoader.js");
|
||||
};
|
||||
|
@ -57,6 +57,7 @@
|
||||
"heic2any": "0.0.3",
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"jszip": "^3.5.0",
|
||||
"knex": "^0.21.12",
|
||||
"minisearch": "^2.5.1",
|
||||
"moment": "^2.27.0",
|
||||
|
Loading…
Reference in New Issue
Block a user