From d2505b913cf4467d36f137f5ee5747fff833b012 Mon Sep 17 00:00:00 2001 From: Muffin Date: Thu, 11 Jan 2024 16:57:19 -0600 Subject: [PATCH] Validate as sb3 first A vast majority of projects we get are sb3, so try that first Technically this might change behavior if a project is both, but that seems like an edge case not worth worrying about As part of this the sb2 schema is now compiled only if sb3 validation failed, which should slightly help loading performance --- lib/validate.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/validate.js b/lib/validate.js index 6f68ed8..5c078c1 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -8,22 +8,20 @@ var sprite3Schema = require('./sprite3_schema.json'); ajv.addSchema(sb2Defs).addSchema(sb3Defs); module.exports = function (isSprite, input, callback) { - var validateSb2 = ajv.compile(isSprite ? sprite2Schema : sb2Schema); var validateSb3 = ajv.compile(isSprite ? sprite3Schema : sb3Schema); + var isValidSb3 = validateSb3(input); + if (isValidSb3) { + input.projectVersion = 3; + return callback(null, input); + } + var validateSb2 = ajv.compile(isSprite ? sprite2Schema : sb2Schema); var isValidSb2 = validateSb2(input); - if (isValidSb2) { input.projectVersion = 2; return callback(null, input); } - var isValidSb3 = validateSb3(input); - if (isValidSb3) { - input.projectVersion = 3; - return callback(null, input); - } - var validationErrors = { validationError: 'Could not parse as a valid SB2 or SB3 project.', sb3Errors: validateSb3.errors,