mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-11 13:57:28 +08:00
removed duplicate validation
This commit is contained in:
parent
182d0b6b22
commit
053ca05d00
3 changed files with 0 additions and 74 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import ConfigDAO from "../../dao/config";
|
||||
import { validateConfig } from "../../handlers/validation";
|
||||
import { MonkeyResponse } from "../../handlers/monkey-response";
|
||||
|
||||
class ConfigController {
|
||||
|
|
@ -14,7 +13,6 @@ class ConfigController {
|
|||
const { config } = req.body;
|
||||
const { uid } = req.ctx.decodedToken;
|
||||
|
||||
validateConfig(config);
|
||||
await ConfigDAO.saveConfig(uid, config);
|
||||
|
||||
return new MonkeyResponse("Config updated");
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import ResultDAO from "../../dao/result";
|
|||
import UserDAO from "../../dao/user";
|
||||
import PublicStatsDAO from "../../dao/public-stats";
|
||||
import BotDAO from "../../dao/bot";
|
||||
import { validateObjectValues } from "../../handlers/validation";
|
||||
import { roundTo2, stdDev } from "../../handlers/misc";
|
||||
import node_object_hash from "node-object-hash";
|
||||
import Logger from "../../handlers/logger";
|
||||
|
|
@ -61,8 +60,6 @@ class ResultController {
|
|||
const { uid } = req.ctx.decodedToken;
|
||||
const { result } = req.body;
|
||||
result.uid = uid;
|
||||
if (validateObjectValues(result) > 0)
|
||||
throw new MonkeyError(400, "Bad input");
|
||||
if (result.wpm === result.raw && result.acc !== 100) {
|
||||
throw new MonkeyError(400, "Bad input");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import MonkeyError from "./error";
|
||||
|
||||
export function isUsernameValid(name) {
|
||||
if (name === null || name === undefined || name === "") return false;
|
||||
if (/.*miodec.*/.test(name.toLowerCase())) return false;
|
||||
|
|
@ -20,70 +18,3 @@ export function isTagPresetNameValid(name) {
|
|||
if (name.length > 16) return false;
|
||||
return /^[0-9a-zA-Z_.-]+$/.test(name);
|
||||
}
|
||||
|
||||
function isConfigKeyValid(name) {
|
||||
if (name === null || name === undefined || name === "") return false;
|
||||
if (name.length > 40) return false;
|
||||
return /^[0-9a-zA-Z_.\-#+]+$/.test(name);
|
||||
}
|
||||
|
||||
export function validateConfig(config) {
|
||||
Object.keys(config).forEach((key) => {
|
||||
if (!isConfigKeyValid(key)) {
|
||||
throw new MonkeyError(500, `Invalid config: ${key} failed regex check`);
|
||||
}
|
||||
// if (key === "resultFilters") return;
|
||||
// if (key === "customBackground") return;
|
||||
if (key === "customBackground" || key === "customLayoutfluid") {
|
||||
let val = config[key];
|
||||
if (/[<>]/.test(val)) {
|
||||
throw new MonkeyError(
|
||||
500,
|
||||
`Invalid config: ${key}:${val} failed regex check`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
let val = config[key];
|
||||
if (Array.isArray(val)) {
|
||||
val.forEach((valarr) => {
|
||||
if (!isConfigKeyValid(valarr)) {
|
||||
throw new MonkeyError(
|
||||
500,
|
||||
`Invalid config: ${key}:${valarr} failed regex check`
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (!isConfigKeyValid(val)) {
|
||||
throw new MonkeyError(
|
||||
500,
|
||||
`Invalid config: ${key}:${val} failed regex check`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
export function validateObjectValues(val) {
|
||||
let errCount = 0;
|
||||
if (val === null || val === undefined) {
|
||||
//
|
||||
} else if (Array.isArray(val)) {
|
||||
//array
|
||||
val.forEach((val2) => {
|
||||
errCount += validateObjectValues(val2);
|
||||
});
|
||||
} else if (typeof val === "object" && !Array.isArray(val)) {
|
||||
//object
|
||||
Object.keys(val).forEach((valkey) => {
|
||||
errCount += validateObjectValues(val[valkey]);
|
||||
});
|
||||
} else {
|
||||
if (!/^[0-9a-zA-Z._\-+]+$/.test(val)) {
|
||||
errCount++;
|
||||
}
|
||||
}
|
||||
return errCount;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue