mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-22 00:06:16 +08:00
Merge branch 'master' of https://github.com/Miodec/monkeytype
This commit is contained in:
commit
0718fd58bd
|
@ -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;
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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,
|
|
@ -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."
|
||||
|
|
|
@ -38,7 +38,7 @@ function validateConfiguration(
|
|||
|
||||
type AsyncHandler = (
|
||||
req: MonkeyTypes.Request,
|
||||
res: Response
|
||||
res?: Response
|
||||
) => Promise<MonkeyResponse>;
|
||||
|
||||
/**
|
||||
|
|
|
@ -290,7 +290,8 @@
|
|||
"code_swift",
|
||||
"code_bash",
|
||||
"code_lua",
|
||||
"code_luau"
|
||||
"code_luau",
|
||||
"code_matlab"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -157,6 +157,7 @@
|
|||
,"code_bash"
|
||||
,"code_lua"
|
||||
,"code_luau"
|
||||
,"code_matlab"
|
||||
,"hindi"
|
||||
,"hindi_1k"
|
||||
,"macedonian"
|
||||
|
|
72
frontend/static/languages/code_matlab.json
Normal file
72
frontend/static/languages/code_matlab.json
Normal 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
Loading…
Reference in a new issue