summary refs log tree commit diff
path: root/src/routes
diff options
context:
space:
mode:
authorDiego Magdaleno <diegomagdaleno@protonmail.com>2021-05-21 18:18:58 -0500
committerDiego Magdaleno <diegomagdaleno@protonmail.com>2021-05-21 18:18:58 -0500
commit05057b922a84c6b0331357867dfa50166320b318 (patch)
tree55b1ccb6e0ce0347a3f9e93932fa4acd81b5bf24 /src/routes
parentMeta: Clean up the format file (diff)
downloadserver-05057b922a84c6b0331357867dfa50166320b318.tar.xz
Config: Refactor config method, so we have a new get all option, fix issues in configurations
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/auth/login.ts5
-rw-r--r--src/routes/auth/register.ts3
-rw-r--r--src/routes/channels/#channel_id/messages/bulk-delete.ts3
-rw-r--r--src/routes/channels/#channel_id/pins.ts3
-rw-r--r--src/routes/gateway.ts3
-rw-r--r--src/routes/guilds/index.ts3
-rw-r--r--src/routes/guilds/templates/index.ts3
7 files changed, 8 insertions, 15 deletions
diff --git a/src/routes/auth/login.ts b/src/routes/auth/login.ts

index 218a56ae..1938b794 100644 --- a/src/routes/auth/login.ts +++ b/src/routes/auth/login.ts
@@ -27,7 +27,7 @@ router.post( // TODO: Rewrite this to have the proper config syntax on the new method - const config = Config.apiConfig.store as unknown as Config.DefaultOptions; + const config = Config.apiConfig.getAll(); if (config.login.requireCaptcha && config.security.captcha.enabled) { if (!captcha_key) { @@ -69,10 +69,9 @@ 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 }, - securityPropertiesSecret.security.jwtSecret, + Config.apiConfig.getAll().security.jwtSecret, { algorithm, }, diff --git a/src/routes/auth/register.ts b/src/routes/auth/register.ts
index 6389fb22..ca6351fa 100644 --- a/src/routes/auth/register.ts +++ b/src/routes/auth/register.ts
@@ -52,8 +52,7 @@ router.post( let discriminator = ""; // get register Config - const securityProperties = Config.apiConfig.store as unknown as Config.DefaultOptions; - const { register, security } = securityProperties; + const { register, security } = Config.apiConfig.getAll(); // check if registration is allowed if (!register.allowNewRegistration) { diff --git a/src/routes/channels/#channel_id/messages/bulk-delete.ts b/src/routes/channels/#channel_id/messages/bulk-delete.ts
index c469e495..c70e7ac1 100644 --- a/src/routes/channels/#channel_id/messages/bulk-delete.ts +++ b/src/routes/channels/#channel_id/messages/bulk-delete.ts
@@ -20,8 +20,7 @@ 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 limitsProperties = Config.apiConfig.get('limits.message') as Config.DefaultOptions; - const { maxBulkDelete } = limitsProperties.limits.message; + const { maxBulkDelete } = Config.apiConfig.getAll().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"); diff --git a/src/routes/channels/#channel_id/pins.ts b/src/routes/channels/#channel_id/pins.ts
index d8e2be9b..4d8f53b1 100644 --- a/src/routes/channels/#channel_id/pins.ts +++ b/src/routes/channels/#channel_id/pins.ts
@@ -18,8 +18,7 @@ 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 limitsProperties = Config.apiConfig.get('limits.channel') as Config.DefaultOptions; - const { maxPins } = limitsProperties.limits.channel; + const { maxPins } = Config.apiConfig.getAll().limits.channel; if (pinned_count >= maxPins) throw new HTTPError("Max pin count reached: " + maxPins); await MessageModel.updateOne({ id: message_id }, { pinned: true }).exec(); diff --git a/src/routes/gateway.ts b/src/routes/gateway.ts
index f92053e5..04ab1248 100644 --- a/src/routes/gateway.ts +++ b/src/routes/gateway.ts
@@ -4,8 +4,7 @@ import * as Config from "../util/Config" const router = Router(); router.get("/", (req, res) => { - const generalConfig = Config.apiConfig.get('gateway', 'ws://localhost:3002') as Config.DefaultOptions; - const { gateway } = generalConfig; + const { gateway } = Config.apiConfig.getAll(); res.send({ url: gateway || "ws://localhost:3002" }); }); diff --git a/src/routes/guilds/index.ts b/src/routes/guilds/index.ts
index 89f60ab2..e1fbd180 100644 --- a/src/routes/guilds/index.ts +++ b/src/routes/guilds/index.ts
@@ -14,8 +14,7 @@ const router: Router = Router(); router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) => { const body = req.body as GuildCreateSchema; - const limitsProperties = Config.apiConfig.get('limits.user') as Config.DefaultOptions; - const { maxGuilds } = limitsProperties.limits.user; + const { maxGuilds } = Config.apiConfig.getAll().limits.user; const user = await getPublicUser(req.user_id, { guilds: true }); if (user.guilds.length >= maxGuilds) { diff --git a/src/routes/guilds/templates/index.ts b/src/routes/guilds/templates/index.ts
index c314728d..a7af8295 100644 --- a/src/routes/guilds/templates/index.ts +++ b/src/routes/guilds/templates/index.ts
@@ -21,8 +21,7 @@ router.post("/:code", check(GuildTemplateCreateSchema), async (req: Request, res const { code } = req.params; const body = req.body as GuildTemplateCreateSchema; - const limitsProperties = Config.apiConfig.get('limits.user') as Config.DefaultOptions; - const { maxGuilds } = limitsProperties.limits.user; + const { maxGuilds } = Config.apiConfig.getAll().limits.user; const user = await getPublicUser(req.user_id, { guilds: true }); if (user.guilds.length >= maxGuilds) {