This commit is contained in:
Miodec 2022-02-24 13:15:25 +01:00
commit 0718fd58bd
11 changed files with 101 additions and 258 deletions

View file

@ -3,14 +3,14 @@ import { validateConfig } from "../../handlers/validation";
import { MonkeyResponse } from "../../handlers/monkey-response";
class ConfigController {
static async getConfig(req, _res) {
static async getConfig(req: MonkeyTypes.Request): Promise<MonkeyResponse> {
const { uid } = req.ctx.decodedToken;
const data = await ConfigDAO.getConfig(uid);
return new MonkeyResponse("Configuration retrieved", data);
}
static async saveConfig(req, _res) {
static async saveConfig(req: MonkeyTypes.Request): Promise<MonkeyResponse> {
const { config } = req.body;
const { uid } = req.ctx.decodedToken;

View file

@ -1,18 +1,18 @@
import { MonkeyResponse } from "../../handlers/monkey-response";
import _ from "lodash";
import { MonkeyResponse } from "../../handlers/monkey-response";
import LeaderboardsDAO from "../../dao/leaderboards";
class LeaderboardsController {
static async get(req, _res) {
const { language, mode, mode2, skip, limit } = req.query;
static async get(req: MonkeyTypes.Request): Promise<MonkeyResponse> {
const { language, mode, mode2, skip, limit = 50 } = req.query;
const { uid } = req.ctx.decodedToken;
const leaderboard = await LeaderboardsDAO.get(
mode,
mode2,
language,
skip,
limit
parseInt(skip as string),
parseInt(limit as string)
);
const normalizedLeaderboard = _.map(leaderboard, (entry) => {
@ -24,10 +24,12 @@ class LeaderboardsController {
return new MonkeyResponse("Leaderboard retrieved", normalizedLeaderboard);
}
static async getRank(req, _res) {
static async getRank(req: MonkeyTypes.Request): Promise<MonkeyResponse> {
const { language, mode, mode2 } = req.query;
const { uid } = req.ctx.decodedToken;
const data = await LeaderboardsDAO.getRank(mode, mode2, language, uid);
return new MonkeyResponse("Rank retrieved", data);
}
}

View file

@ -2,14 +2,14 @@ import PresetDAO from "../../dao/preset";
import { MonkeyResponse } from "../../handlers/monkey-response";
class PresetController {
static async getPresets(req, _res) {
static async getPresets(req: MonkeyTypes.Request): Promise<MonkeyResponse> {
const { uid } = req.ctx.decodedToken;
const data = await PresetDAO.getPresets(uid);
return new MonkeyResponse("Preset retrieved", data);
}
static async addPreset(req, _res) {
static async addPreset(req: MonkeyTypes.Request): Promise<MonkeyResponse> {
const { name, config } = req.body;
const { uid } = req.ctx.decodedToken;
@ -18,7 +18,7 @@ class PresetController {
return new MonkeyResponse("Preset created", data);
}
static async editPreset(req, _res) {
static async editPreset(req: MonkeyTypes.Request): Promise<MonkeyResponse> {
const { _id, name, config } = req.body;
const { uid } = req.ctx.decodedToken;
@ -27,7 +27,7 @@ class PresetController {
return new MonkeyResponse("Preset updated");
}
static async removePreset(req, _res) {
static async removePreset(req: MonkeyTypes.Request): Promise<MonkeyResponse> {
const { presetId } = req.params;
const { uid } = req.ctx.decodedToken;

View file

@ -2,8 +2,8 @@ import PsaDAO from "../../dao/psa";
import { MonkeyResponse } from "../../handlers/monkey-response";
class PsaController {
static async get(_req, _res) {
let data = await PsaDAO.get();
static async get(_req: MonkeyTypes.Request): Promise<MonkeyResponse> {
const data = await PsaDAO.get();
return new MonkeyResponse("PSAs retrieved", data);
}
}

View file

@ -7,8 +7,11 @@ import Logger from "../../handlers/logger";
import { MonkeyResponse } from "../../handlers/monkey-response";
class QuotesController {
static async reportQuote(req, _res) {
static async reportQuote(req: MonkeyTypes.Request): Promise<MonkeyResponse> {
const { uid } = req.ctx.decodedToken;
const {
quoteReport: { maxReports, contentReportLimit },
} = req.ctx.configuration;
const user = await UsersDAO.getUser(uid);
if (user.cannotReport) {
@ -33,7 +36,7 @@ class QuotesController {
},
};
await ReportDAO.createReport(newReport);
await ReportDAO.createReport(newReport, maxReports, contentReportLimit);
Logger.log("report_created", {
type: newReport.type,

View file

@ -1,25 +1,21 @@
import MonkeyError from "../handlers/error";
import db from "../init/db";
const MAX_REPORTS = 1000;
const CONTENT_REPORT_LIMIT = 5;
class ReportDAO {
static async createReport(report) {
static async createReport(report, maxReports, contentReportLimit) {
const reports = await db.collection("reports").find().toArray();
if (reports.length >= MAX_REPORTS) {
if (reports.length >= maxReports) {
throw new MonkeyError(
503,
"Reports are not being accepted at this time. Please try again later."
);
}
const reportAlreadyExists = reports.filter((existingReport) => {
const sameReports = reports.filter((existingReport) => {
return existingReport.details.contentId === report.details.contentId;
});
if (reportAlreadyExists.length >= CONTENT_REPORT_LIMIT) {
if (sameReports.length >= contentReportLimit) {
throw new MonkeyError(
409,
"A report limit for this content has been reached."

View file

@ -38,7 +38,7 @@ function validateConfiguration(
type AsyncHandler = (
req: MonkeyTypes.Request,
res: Response
res?: Response
) => Promise<MonkeyResponse>;
/**

View file

@ -290,7 +290,8 @@
"code_swift",
"code_bash",
"code_lua",
"code_luau"
"code_luau",
"code_matlab"
]
},
{

View file

@ -157,6 +157,7 @@
,"code_bash"
,"code_lua"
,"code_luau"
,"code_matlab"
,"hindi"
,"hindi_1k"
,"macedonian"

View file

@ -0,0 +1,72 @@
{
"name": "code_matlab",
"leftToRight": true,
"noLazyMode": true,
"words": [
"x",
"X",
".^",
"plot",
"plot3",
"contour",
"contour3",
"y",
"Y",
"function[]",
"for",
"end",
"meshgrid",
"a:0.1:b",
"cos()",
"sin()",
"cosh()",
"sinh()",
"cos()",
"tan()",
"log()",
"sqrt()",
"exp()",
"@(x)",
"i=0",
"i++",
"~=",
"&&",
"==",
"linspace",
"ans",
"pi",
"nan",
"eps",
"real()",
"angle()",
"ceil",
"longspace",
"abs",
"floor",
"hold",
"figure",
"factorial()",
"round()",
"table()",
"surf()",
"scatter()",
"quiver()",
"f(x)",
"sign()",
"%comment",
"else",
"curl()",
"integral()",
"break",
"continue",
"roots()",
"normalize()",
"sort()",
"table()",
"text()",
"label()",
"zeros()",
"ones()",
"||"
]
}

File diff suppressed because it is too large Load diff