Make max goals and milestones configurable

This commit is contained in:
zkldi
2022-03-31 00:16:32 +01:00
parent dff4027c94
commit ee86fb1af7
4 changed files with 16 additions and 7 deletions
+6
View File
@@ -79,6 +79,8 @@ export interface TachiServerConfig {
};
USC_QUEUE_SIZE: integer;
BEATORAJA_QUEUE_SIZE: integer;
MAX_GOAL_SUBSCRIPTIONS: integer;
MAX_MILESTONE_SUBSCRIPTIONS: integer;
OUR_URL: string;
INVITE_CODE_CONFIG?: {
BATCH_SIZE: integer;
@@ -152,6 +154,8 @@ const err = p(config, {
}),
USC_QUEUE_SIZE: p.optional(p.gteInt(2)),
BEATORAJA_QUEUE_SIZE: p.optional(p.gteInt(2)),
MAX_GOAL_SUBSCRIPTIONS: p.optional(p.isPositiveInteger),
MAX_MILESTONE_SUBSCRIPTIONS: p.optional(p.isPositiveInteger),
OUR_URL: "string",
INVITE_CODE_CONFIG: p.optional({
BATCH_SIZE: p.isPositiveInteger,
@@ -209,6 +213,8 @@ tachiServerConfig.RATE_LIMIT ??= 500;
tachiServerConfig.OAUTH_CLIENT_CAP ??= 15;
tachiServerConfig.USC_QUEUE_SIZE ??= 3;
tachiServerConfig.BEATORAJA_QUEUE_SIZE ??= 3;
tachiServerConfig.MAX_GOAL_SUBSCRIPTIONS ??= 1_000;
tachiServerConfig.MAX_MILESTONE_SUBSCRIPTIONS ??= 100;
// Assign sane defaults to the logger config.
tachiServerConfig.LOGGER_CONFIG = Object.assign(
+1 -1
View File
@@ -320,7 +320,7 @@ export async function SubscribeToGoal(
progress: result.progress,
progressHuman: result.progressHuman,
userID,
lastInteraction: Date.now(),
lastInteraction: null,
timeAchieved: result.achieved ? Date.now() : null,
timeSet: Date.now(),
// if this goal subscription came from a milestone, add the milestone to
@@ -11,6 +11,7 @@ import { AssignToReqTachiData } from "utils/req-tachi-data";
import { GetGoalForIDGuaranteed, GetMilestoneForIDGuaranteed } from "utils/db";
import { RequireAuthedAsUser } from "../../../../../middleware";
import { SubscribeFailReasons } from "lib/constants/err-codes";
import { ServerConfig } from "lib/setup/config";
const router: Router = Router({ mergeParams: true });
@@ -136,10 +137,10 @@ router.post(
playtype,
});
if (existingGoalsCount > 1_000) {
if (existingGoalsCount > ServerConfig.MAX_GOAL_SUBSCRIPTIONS) {
return res.status(400).json({
success: false,
description: `You already have 1000 goals. You cannot have anymore.`,
description: `You already have ${ServerConfig.MAX_GOAL_SUBSCRIPTIONS} goals. You cannot have anymore.`,
});
}
@@ -3,15 +3,16 @@ import db from "external/mongo/db";
import { SubscribeFailReasons } from "lib/constants/err-codes";
import { SYMBOL_TachiData } from "lib/constants/tachi";
import CreateLogCtx from "lib/logger/logger";
import { ServerConfig } from "lib/setup/config";
import {
EvaluateMilestoneProgress,
SubscribeToMilestone,
UnsubscribeFromMilestone,
} from "lib/targets/milestones";
import { RequirePermissions } from "server/middleware/auth";
import { GetMilestoneForIDGuaranteed } from "utils/db";
import { AssignToReqTachiData } from "utils/req-tachi-data";
import { FormatUserDoc } from "utils/user";
import { RequireAuthedAsUser } from "../../../../../middleware";
const logger = CreateLogCtx(__filename);
@@ -72,7 +73,6 @@ const GetMilestoneSubscription: RequestHandler = async (req, res, next) => {
};
const GetMilestone: RequestHandler = async (req, res, next) => {
const user = req[SYMBOL_TachiData]!.requestedUser!;
const game = req[SYMBOL_TachiData]!.game!;
const playtype = req[SYMBOL_TachiData]!.playtype!;
@@ -130,6 +130,7 @@ router.get("/:milestoneID", GetMilestone, GetMilestoneSubscription, async (req,
*/
router.put(
"/:milestoneID",
RequireAuthedAsUser,
GetMilestone,
RequirePermissions("manage_targets"),
async (req, res) => {
@@ -143,10 +144,10 @@ router.put(
playtype,
});
if (existingMilestonesCount > 100) {
if (existingMilestonesCount > ServerConfig.MAX_MILESTONE_SUBSCRIPTIONS) {
return res.status(400).json({
success: false,
description: `You already have 100 milestones. You cannot have anymore for this game.`,
description: `You already have ${ServerConfig.MAX_MILESTONE_SUBSCRIPTIONS} milestones. You cannot have anymore for this game.`,
});
}
@@ -195,6 +196,7 @@ router.put(
*/
router.delete(
"/:milestoneID",
RequireAuthedAsUser,
GetMilestone,
RequirePermissions("manage_targets"),
async (req, res) => {