diff --git a/package-lock.json b/package-lock.json index 21c011a..c3419ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@fosscord/server-util": "^1.3.0", + "@fosscord/server-util": "^1.3.1", "@types/jest": "^26.0.22", "@types/json-schema": "^7.0.7", "ajv": "^8.4.0", @@ -498,9 +498,9 @@ } }, "node_modules/@fosscord/server-util": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.0.tgz", - "integrity": "sha512-GBU1XLAQKylr76Vb5kGEkYInj0qPkz/D9oAVSPISMIWbYeo6RIfARVneg6FdreWC+WK7UNcpGr+JFJpvMfSeOA==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.1.tgz", + "integrity": "sha512-NmrJ8HcZmOHyIUDMoQ+UnjoeMMi/HSbN2p/EMt1penTDSBvWcD8YS5m2NljuH0QxSmhuA2yLgSEpV1ydvJmOIw==", "dependencies": { "@types/jsonwebtoken": "^8.5.0", "@types/mongoose-autopopulate": "^0.10.1", @@ -12664,9 +12664,9 @@ } }, "@fosscord/server-util": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.0.tgz", - "integrity": "sha512-GBU1XLAQKylr76Vb5kGEkYInj0qPkz/D9oAVSPISMIWbYeo6RIfARVneg6FdreWC+WK7UNcpGr+JFJpvMfSeOA==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.1.tgz", + "integrity": "sha512-NmrJ8HcZmOHyIUDMoQ+UnjoeMMi/HSbN2p/EMt1penTDSBvWcD8YS5m2NljuH0QxSmhuA2yLgSEpV1ydvJmOIw==", "requires": { "@types/jsonwebtoken": "^8.5.0", "@types/mongoose-autopopulate": "^0.10.1", diff --git a/package.json b/package.json index 76fdcb8..ee3f085 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ }, "homepage": "https://github.com/fosscord/fosscord-api#readme", "dependencies": { - "@fosscord/server-util": "^1.3.0", + "@fosscord/server-util": "^1.3.1", "@types/jest": "^26.0.22", "@types/json-schema": "^7.0.7", "ajv": "^8.4.0", diff --git a/src/middlewares/Authentication.ts b/src/middlewares/Authentication.ts index 7853348..050c427 100644 --- a/src/middlewares/Authentication.ts +++ b/src/middlewares/Authentication.ts @@ -29,7 +29,7 @@ try { - const { jwtSecret } = (Config.apiConfig.getAll() as Config.DefaultOptions).security; + const { jwtSecret } = Config.apiConfig.getAll().security; const decoded: any = await checkToken(req.headers.authorization, jwtSecret); diff --git a/src/middlewares/GlobalRateLimit.ts b/src/middlewares/GlobalRateLimit.ts index ce2bfa5..3809898 100644 --- a/src/middlewares/GlobalRateLimit.ts +++ b/src/middlewares/GlobalRateLimit.ts @@ -44,7 +44,7 @@ } export function getIpAdress(req: Request): string { - const { forwadedFor } = (Config.apiConfig.getAll() as Config.DefaultOptions).security; + const { forwadedFor } = Config.apiConfig.getAll().security; const ip = forwadedFor ? req.headers[forwadedFor] : req.ip; return ip.replaceAll(".", "_").replaceAll(":", "_"); } diff --git a/src/routes/auth/login.ts b/src/routes/auth/login.ts index 275f78c..1938b79 100644 --- a/src/routes/auth/login.ts +++ b/src/routes/auth/login.ts @@ -27,7 +27,7 @@ // TODO: Rewrite this to have the proper config syntax on the new method - const config = Config.apiConfig.getAll() as Config.DefaultOptions; + const config = Config.apiConfig.getAll(); if (config.login.requireCaptcha && config.security.captcha.enabled) { if (!captcha_key) { @@ -71,7 +71,7 @@ return new Promise((res, rej) => { jwt.sign( { id: id, iat }, - (Config.apiConfig.getAll() as Config.DefaultOptions).security.jwtSecret, + Config.apiConfig.getAll().security.jwtSecret, { algorithm, }, diff --git a/src/routes/auth/register.ts b/src/routes/auth/register.ts index eeef961..98fa768 100644 --- a/src/routes/auth/register.ts +++ b/src/routes/auth/register.ts @@ -52,7 +52,7 @@ let discriminator = ""; // get register Config - const { register, security } = Config.apiConfig.getAll() as Config.DefaultOptions; + const { register, security } = Config.apiConfig.getAll(); // check if registration is allowed if (!register.allowNewRegistration) { diff --git "a/src/routes/channels/\043channel_id/messages/bulk-delete.ts" "b/src/routes/channels/\043channel_id/messages/bulk-delete.ts" index 615a0d7..8a11475 100644 --- "a/src/routes/channels/\043channel_id/messages/bulk-delete.ts" +++ "b/src/routes/channels/\043channel_id/messages/bulk-delete.ts" @@ -20,7 +20,7 @@ const permission = await getPermission(req.user_id, channel?.guild_id, channel_id, { channel }); permission.hasThrow("MANAGE_MESSAGES"); - const { maxBulkDelete } = (Config.apiConfig.getAll() as Config.DefaultOptions).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/\043channel_id/pins.ts" "b/src/routes/channels/\043channel_id/pins.ts" index 6d938b7..ccb909b 100644 --- "a/src/routes/channels/\043channel_id/pins.ts" +++ "b/src/routes/channels/\043channel_id/pins.ts" @@ -18,7 +18,7 @@ if (channel.guild_id) permission.hasThrow("MANAGE_MESSAGES"); const pinned_count = await MessageModel.count({ channel_id, pinned: true }).exec(); - const { maxPins } = (Config.apiConfig.getAll() as Config.DefaultOptions).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 8d0eb06..04ab124 100644 --- a/src/routes/gateway.ts +++ b/src/routes/gateway.ts @@ -4,7 +4,7 @@ const router = Router(); router.get("/", (req, res) => { - const { gateway } = Config.apiConfig.getAll() as Config.DefaultOptions; + 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 9e787e5..8860bcd 100644 --- a/src/routes/guilds/index.ts +++ b/src/routes/guilds/index.ts @@ -15,7 +15,7 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) => { const body = req.body as GuildCreateSchema; - const { maxGuilds } = (Config.apiConfig.getAll() as Config.DefaultOptions).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 21a3a6a..a7af829 100644 --- a/src/routes/guilds/templates/index.ts +++ b/src/routes/guilds/templates/index.ts @@ -21,7 +21,7 @@ const { code } = req.params; const body = req.body as GuildTemplateCreateSchema; - const { maxGuilds } = (Config.apiConfig.getAll() as Config.DefaultOptions).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/util/Config.ts b/src/util/Config.ts index 6054166..89f3590 100644 --- a/src/util/Config.ts +++ b/src/util/Config.ts @@ -362,4 +362,4 @@ const configPath = getConfigPathForFile("fosscord", "api", ".json"); -export const apiConfig = new Config({path: configPath, schemaValidator: validator, schema: schema}); \ No newline at end of file +export const apiConfig = new Config({path: configPath, schemaValidator: validator, schema: schema}); \ No newline at end of file diff --git a/src/util/Member.ts b/src/util/Member.ts index b15eef6..d03a8f1 100644 --- a/src/util/Member.ts +++ b/src/util/Member.ts @@ -39,7 +39,7 @@ export async function addMember(user_id: string, guild_id: string, cache?: { guild?: GuildDocument }) { const user = await getPublicUser(user_id, { guilds: true }); - const { maxGuilds } = (Config.apiConfig.getAll() as Config.DefaultOptions).limits.user; + const { maxGuilds } = Config.apiConfig.getAll().limits.user; if (user.guilds.length >= maxGuilds) { throw new HTTPError(`You are at the ${maxGuilds} server limit.`, 403); } diff --git a/src/util/passwordStrength.ts b/src/util/passwordStrength.ts index bc8ce2c..7196f79 100644 --- a/src/util/passwordStrength.ts +++ b/src/util/passwordStrength.ts @@ -23,7 +23,7 @@ minUpperCase, minSymbols, blockInsecureCommonPasswords, - } = (Config.apiConfig.getAll() as Config.DefaultOptions).register.password; + } = Config.apiConfig.getAll().register.password; var strength = 0; // checks for total password len