mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 15:26:15 +08:00
Add config for discord integration (#3081) Bruception
This commit is contained in:
parent
26d359a168
commit
1260f13293
|
@ -2,7 +2,11 @@ import joi from "joi";
|
|||
import { authenticateRequest } from "../../middlewares/auth";
|
||||
import { Router } from "express";
|
||||
import * as UserController from "../controllers/user";
|
||||
import { asyncHandler, validateRequest } from "../../middlewares/api-utils";
|
||||
import {
|
||||
asyncHandler,
|
||||
validateRequest,
|
||||
validateConfiguration,
|
||||
} from "../../middlewares/api-utils";
|
||||
import * as RateLimit from "../../middlewares/rate-limit";
|
||||
import apeRateLimit from "../../middlewares/ape-rate-limit";
|
||||
import { isUsernameValid } from "../../utils/validation";
|
||||
|
@ -268,9 +272,17 @@ router.patch(
|
|||
asyncHandler(UserController.editCustomTheme)
|
||||
);
|
||||
|
||||
const requireDiscordIntegrationEnabled = validateConfiguration({
|
||||
criteria: (configuration) => {
|
||||
return configuration.discordIntegration.enabled;
|
||||
},
|
||||
invalidMessage: "Discord integration is not available at this time",
|
||||
});
|
||||
|
||||
router.post(
|
||||
"/discord/link",
|
||||
RateLimit.userDiscordLink,
|
||||
requireDiscordIntegrationEnabled,
|
||||
authenticateRequest(),
|
||||
validateRequest({
|
||||
body: {
|
||||
|
|
|
@ -39,6 +39,9 @@ export const BASE_CONFIGURATION: MonkeyTypes.Configuration = {
|
|||
dailyLeaderboardCacheSize: 1,
|
||||
topResultsToAnnounce: 1, // This should never be 0. Setting to zero will announce all results.
|
||||
},
|
||||
discordIntegration: {
|
||||
enabled: false,
|
||||
},
|
||||
};
|
||||
|
||||
export const CONFIGURATION_FORM_SCHEMA = {
|
||||
|
@ -49,6 +52,16 @@ export const CONFIGURATION_FORM_SCHEMA = {
|
|||
type: "boolean",
|
||||
label: "In Maintenance",
|
||||
},
|
||||
discordIntegration: {
|
||||
type: "object",
|
||||
label: "Discord Integration",
|
||||
fields: {
|
||||
enabled: {
|
||||
type: "boolean",
|
||||
label: "Enabled",
|
||||
},
|
||||
},
|
||||
},
|
||||
results: {
|
||||
type: "object",
|
||||
label: "Results",
|
||||
|
|
3
backend/src/types/types.d.ts
vendored
3
backend/src/types/types.d.ts
vendored
|
@ -44,6 +44,9 @@ declare namespace MonkeyTypes {
|
|||
dailyLeaderboardCacheSize: number;
|
||||
topResultsToAnnounce: number;
|
||||
};
|
||||
discordIntegration: {
|
||||
enabled: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface DecodedToken {
|
||||
|
|
Loading…
Reference in a new issue