Config: First rewrite of config and working implementation of getting values
This commit is contained in:
@@ -3,7 +3,7 @@ import { check, FieldErrors, Length } from "../../util/instanceOf";
|
||||
import bcrypt from "bcrypt";
|
||||
import jwt from "jsonwebtoken";
|
||||
import { UserModel } from "@fosscord/server-util";
|
||||
import Config from "../../util/Config";
|
||||
import * as Config from "../../util/Config";
|
||||
import { adjustEmail } from "./register";
|
||||
|
||||
const router: Router = Router();
|
||||
@@ -25,7 +25,9 @@ router.post(
|
||||
const query: any[] = [{ phone: login }];
|
||||
if (email) query.push({ email });
|
||||
|
||||
const config = Config.get();
|
||||
// TODO: Rewrite this to have the proper config syntax on the new method
|
||||
|
||||
const config = Config.apiConfig.store as unknown as Config.DefaultOptions;
|
||||
|
||||
if (config.login.requireCaptcha && config.security.captcha.enabled) {
|
||||
if (!captcha_key) {
|
||||
@@ -67,9 +69,10 @@ export async function generateToken(id: string) {
|
||||
const algorithm = "HS256";
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
const securityPropertiesSecret = Config.apiConfig.get('security.jwtSecret') as Config.DefaultOptions;
|
||||
jwt.sign(
|
||||
{ id: id, iat },
|
||||
Config.get().security.jwtSecret,
|
||||
securityPropertiesSecret.security.jwtSecret,
|
||||
{
|
||||
algorithm,
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import Config from "../../util/Config";
|
||||
import * as Config from "../../util/Config";
|
||||
import { trimSpecial, User, Snowflake, UserModel } from "@fosscord/server-util";
|
||||
import bcrypt from "bcrypt";
|
||||
import { check, Email, EMAIL_REGEX, FieldErrors, Length } from "../../util/instanceOf";
|
||||
@@ -52,7 +52,8 @@ router.post(
|
||||
let discriminator = "";
|
||||
|
||||
// get register Config
|
||||
const { register, security } = Config.get();
|
||||
const securityProperties = Config.apiConfig.store as unknown as Config.DefaultOptions;
|
||||
const { register, security } = securityProperties;
|
||||
|
||||
// check if registration is allowed
|
||||
if (!register.allowNewRegistration) {
|
||||
@@ -90,13 +91,13 @@ router.post(
|
||||
},
|
||||
});
|
||||
}
|
||||
} else if (register.email.required) {
|
||||
} else if (register.email.necessary) {
|
||||
throw FieldErrors({
|
||||
email: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") },
|
||||
});
|
||||
}
|
||||
|
||||
if (register.dateOfBirth.required && !date_of_birth) {
|
||||
if (register.dateOfBirth.necessary && !date_of_birth) {
|
||||
throw FieldErrors({
|
||||
date_of_birth: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Router } from "express";
|
||||
import { ChannelModel, getPermission, MessageDeleteBulkEvent, MessageModel } from "@fosscord/server-util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import Config from "../../../../util/Config";
|
||||
import * as Config from "../../../../util/Config";
|
||||
import { emitEvent } from "../../../../util/Event";
|
||||
import { check } from "../../../../util/instanceOf";
|
||||
|
||||
@@ -20,7 +20,8 @@ router.post("/", check({ messages: [String] }), async (req, res) => {
|
||||
const permission = await getPermission(req.user_id, channel?.guild_id, channel_id, { channel });
|
||||
permission.hasThrow("MANAGE_MESSAGES");
|
||||
|
||||
const { maxBulkDelete } = Config.get().limits.message;
|
||||
const limitsProperties = Config.apiConfig.get('limits.message') as Config.DefaultOptions;
|
||||
const { maxBulkDelete } = limitsProperties.limits.message;
|
||||
|
||||
const { messages } = req.body as { messages: string[] };
|
||||
if (messages.length < 2) throw new HTTPError("You must at least specify 2 messages to bulk delete");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ChannelModel, getPermission, MessageModel, toObject } from "@fosscord/server-util";
|
||||
import { Router, Request, Response } from "express";
|
||||
import Config from "../../../util/Config";
|
||||
import * as Config from "../../../util/Config";
|
||||
import { HTTPError } from "lambert-server";
|
||||
|
||||
const router: Router = Router();
|
||||
@@ -18,7 +18,8 @@ router.put("/:message_id", async (req: Request, res: Response) => {
|
||||
if (channel.guild_id) permission.hasThrow("MANAGE_MESSAGES");
|
||||
|
||||
const pinned_count = await MessageModel.count({ channel_id, pinned: true }).exec();
|
||||
const { maxPins } = Config.get().limits.channel;
|
||||
const limitsProperties = Config.apiConfig.get('limits.channel') as Config.DefaultOptions;
|
||||
const { maxPins } = limitsProperties.limits.channel;
|
||||
if (pinned_count >= maxPins) throw new HTTPError("Max pin count reached: " + maxPins);
|
||||
|
||||
await MessageModel.updateOne({ id: message_id }, { pinned: true }).exec();
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { Router } from "express";
|
||||
import Config from "../util/Config"
|
||||
import * as Config from "../util/Config"
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
const { endpoint } = Config.getAll().gateway;
|
||||
res.send({ url: endpoint || "ws://localhost:3002" });
|
||||
const generalConfig = Config.apiConfig.get('gateway', 'ws://localhost:3002') as Config.DefaultOptions;
|
||||
const { gateway } = generalConfig;
|
||||
res.send({ url: gateway || "ws://localhost:3002" });
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { RoleModel, GuildModel, Snowflake, Guild, RoleDocument } from "@fosscord
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { check } from "./../../util/instanceOf";
|
||||
import { GuildCreateSchema } from "../../schema/Guild";
|
||||
import Config from "../../util/Config";
|
||||
import * as Config from "../../util/Config";
|
||||
import { getPublicUser } from "../../util/User";
|
||||
import { addMember } from "../../util/Member";
|
||||
|
||||
@@ -14,7 +14,8 @@ const router: Router = Router();
|
||||
router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) => {
|
||||
const body = req.body as GuildCreateSchema;
|
||||
|
||||
const { maxGuilds } = Config.get().limits.user;
|
||||
const limitsProperties = Config.apiConfig.get('limits.user') as Config.DefaultOptions;
|
||||
const { maxGuilds } = limitsProperties.limits.user;
|
||||
const user = await getPublicUser(req.user_id, { guilds: true });
|
||||
|
||||
if (user.guilds.length >= maxGuilds) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { HTTPError } from "lambert-server";
|
||||
import { GuildTemplateCreateSchema } from "../../../schema/Guild";
|
||||
import { getPublicUser } from "../../../util/User";
|
||||
import { check } from "../../../util/instanceOf";
|
||||
import Config from "../../../util/Config";
|
||||
import * as Config from "../../../util/Config";
|
||||
import { addMember } from "../../../util/Member";
|
||||
|
||||
router.get("/:code", async (req: Request, res: Response) => {
|
||||
@@ -21,7 +21,8 @@ router.post("/:code", check(GuildTemplateCreateSchema), async (req: Request, res
|
||||
const { code } = req.params;
|
||||
const body = req.body as GuildTemplateCreateSchema;
|
||||
|
||||
const { maxGuilds } = Config.get().limits.user;
|
||||
const limitsProperties = Config.apiConfig.get('limits.user') as Config.DefaultOptions;
|
||||
const { maxGuilds } = limitsProperties.limits.user;
|
||||
const user = await getPublicUser(req.user_id, { guilds: true });
|
||||
|
||||
if (user.guilds.length >= maxGuilds) {
|
||||
|
||||
Reference in New Issue
Block a user