diff --git a/functions/index.js b/functions/index.js index a05be6a60..f14526140 100644 --- a/functions/index.js +++ b/functions/index.js @@ -872,15 +872,13 @@ exports.verifyUser = functions.https.onRequest(async (request, response) => { (await db.collection("users").where("discordId", "==", did).get()) .docs.length > 0 ) { - response - .status(200) - .send({ - data: { - status: -1, - message: - "This Discord account is already paired to a different Monkeytype account", - }, - }); + response.status(200).send({ + data: { + status: -1, + message: + "This Discord account is already paired to a different Monkeytype account", + }, + }); return; } @@ -1255,7 +1253,8 @@ exports.testCompleted = functions.https.onRequest(async (request, response) => { function verifyValue(val) { let errCount = 0; - if (Array.isArray(val)) { + if (val === null || val === undefined) { + } else if (Array.isArray(val)) { //array val.forEach((val2) => { errCount += verifyValue(val2); @@ -1271,8 +1270,6 @@ exports.testCompleted = functions.https.onRequest(async (request, response) => { return errCount; } let errCount = verifyValue(obj); - - // console.log(errCount); if (errCount > 0) { console.error( `error saving result for ${ @@ -1293,6 +1290,27 @@ exports.testCompleted = functions.https.onRequest(async (request, response) => { response.status(200).send({ data: { resultCode: -1 } }); return; } + if ( + (obj.mode === "time" && obj.mode2 < 15) || + (obj.mode === "words" && obj.mode2 < 10) || + (obj.mode === "custom" && + !obj.customText.isWordRandom && + !obj.customText.isTimeRandom && + obj.customText.textLen < 10) || + (obj.mode === "custom" && + obj.customText.isWordRandom && + !obj.customText.isTimeRandom && + obj.customText.word < 10) || + (obj.mode === "custom" && + !obj.customText.isWordRandom && + obj.customText.isTimeRandom && + obj.customText.time < 15) + ) { + response + .status(200) + .send({ data: { resultCode: -5, message: "Test too short" } }); + return; + } if (!validateResult(obj)) { if ( obj.bailedOut && diff --git a/src/js/script.js b/src/js/script.js index 49fce2d9b..45260c8f7 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -2123,6 +2123,23 @@ function showResult(difficultyFailed = false) { Notifications.add("Test invalid - AFK detected", 0); } else if (sameWordset) { Notifications.add("Test invalid - repeated", 0); + } else if ( + (config.mode === "time" && mode2 < 15) || + (config.mode === "words" && mode2 < 10) || + (config.mode === "custom" && + !customText.isWordRandom && + !customText.isTimeRandom && + customText.text.length < 10) || + (config.mode === "custom" && + customText.isWordRandom && + !customText.isTimeRandom && + customText.word < 10) || + (config.mode === "custom" && + !customText.isWordRandom && + customText.isTimeRandom && + customText.time < 15) + ) { + Notifications.add("Test too short", 0); } else { let activeTags = []; let activeTagsIds = []; @@ -2154,6 +2171,16 @@ function showResult(difficultyFailed = false) { quoteLength = randomQuote.group; } + let cdata = null; + if (config.mode === "custom") { + cdata = {}; + cdata.textLen = customText.text.length; + cdata.isWordRandom = customText.isWordRandom; + cdata.isTimeRandom = customText.isTimeRandom; + cdata.word = customText.word !== "" ? customText.word : null; + cdata.time = customText.time !== "" ? customText.time : null; + } + let completedEvent = { wpm: stats.wpm, rawWpm: stats.wpmRaw, @@ -2183,7 +2210,13 @@ function showResult(difficultyFailed = false) { funbox: activeFunBox, bailedOut: bailout, chartData: chartData, + customText: cdata, }; + + if (config.mode !== "custom") { + delete completedEvent.customText; + } + if ( config.difficulty == "normal" || ((config.difficulty == "master" || config.difficulty == "expert") && @@ -2379,6 +2412,8 @@ function showResult(difficultyFailed = false) { "Result data does not make sense. Result not saved.", -1 ); + } else if (e.data.resultCode === -5) { + Notifications.add("Test too short. Result not saved.", -1); } else if (e.data.resultCode === -999) { console.error("internal error: " + e.data.message); Notifications.add( diff --git a/static/themes/_list.json b/static/themes/_list.json index 888583c77..4b2a270ab 100644 --- a/static/themes/_list.json +++ b/static/themes/_list.json @@ -505,8 +505,8 @@ "textColor": "#575279" }, { - "name": "copper", - "bgColor": "#442f29", - "textColor": "#e7e0de" -} + "name": "copper", + "bgColor": "#442f29", + "textColor": "#e7e0de" + } ]