From 8f87546aeb5c14539601ab25c0e07630a5e5043a Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Mon, 24 May 2021 20:47:06 +0200 Subject: :sparkles: use new config --- src/util/Config.ts | 37 ++++++++++++++++++++++--------------- src/util/Member.ts | 6 +++--- src/util/passwordStrength.ts | 15 ++------------- 3 files changed, 27 insertions(+), 31 deletions(-) (limited to 'src/util') diff --git a/src/util/Config.ts b/src/util/Config.ts index 89f35901..e2e0d312 100644 --- a/src/util/Config.ts +++ b/src/util/Config.ts @@ -1,6 +1,7 @@ -import Ajv, { JSONSchemaType } from "ajv" +// @ts-nocheck +import Ajv, { JSONSchemaType } from "ajv"; import { getConfigPathForFile } from "@fosscord/server-util/dist/util/Config"; -import {Config} from "@fosscord/server-util" +import { Config } from "@fosscord/server-util"; export interface RateLimitOptions { count: number; @@ -95,11 +96,10 @@ export interface DefaultOptions { }; } - const schema: JSONSchemaType & { definitions: { - rateLimitOptions: JSONSchemaType - } + rateLimitOptions: JSONSchemaType; + }; } = { type: "object", definitions: { @@ -107,10 +107,10 @@ const schema: JSONSchemaType & { type: "object", properties: { count: { type: "number" }, - timespan: { type: "number" }, + timespan: { type: "number" } }, - required: ["count", "timespan"], - }, + required: ["count", "timespan"] + } }, properties: { gateway: { @@ -238,8 +238,8 @@ const schema: JSONSchemaType & { auth: { type: "object", properties: { - login: { $ref: '#/definitions/rateLimitOptions' }, - register: { $ref: '#/definitions/rateLimitOptions' } + login: { $ref: "#/definitions/rateLimitOptions" }, + register: { $ref: "#/definitions/rateLimitOptions" } }, nullable: true, required: [], @@ -348,18 +348,25 @@ const schema: JSONSchemaType & { additionalProperties: false } }, - required: ["allowMultipleAccounts", "allowNewRegistration", "dateOfBirth", "email", "password", "requireCaptcha", "requireInvite"], + required: [ + "allowMultipleAccounts", + "allowNewRegistration", + "dateOfBirth", + "email", + "password", + "requireCaptcha", + "requireInvite" + ], additionalProperties: false - }, + } }, required: ["gateway", "general", "limits", "login", "permissions", "register", "security"], additionalProperties: false -} - +}; const ajv = new Ajv(); const validator = ajv.compile(schema); 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 }); diff --git a/src/util/Member.ts b/src/util/Member.ts index d03a8f12..7b06720b 100644 --- a/src/util/Member.ts +++ b/src/util/Member.ts @@ -10,11 +10,11 @@ import { RoleModel, toObject, UserModel, - GuildDocument + GuildDocument, + Config } from "@fosscord/server-util"; import { HTTPError } from "lambert-server"; -import * as Config from "./Config"; import { emitEvent } from "./Event"; import { getPublicUser } from "./User"; @@ -39,7 +39,7 @@ export async function isMember(user_id: string, guild_id: string) { 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().limits.user; + const { maxGuilds } = Config.get().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 7196f797..cc503843 100644 --- a/src/util/passwordStrength.ts +++ b/src/util/passwordStrength.ts @@ -1,5 +1,5 @@ +import { Config } from "@fosscord/server-util"; import "missing-native-js-functions"; -import * as Config from "./Config"; const reNUMBER = /[0-9]/g; const reUPPERCASELETTER = /[A-Z]/g; @@ -17,13 +17,7 @@ const blocklist: string[] = []; // TODO: update ones passwordblocklist is stored * Returns: 0 > pw > 1 */ export function check(password: string): number { - const { - minLength, - minNumbers, - minUpperCase, - minSymbols, - blockInsecureCommonPasswords, - } = Config.apiConfig.getAll().register.password; + const { minLength, minNumbers, minUpperCase, minSymbols } = Config.get().register.password; var strength = 0; // checks for total password len @@ -51,10 +45,5 @@ export function check(password: string): number { strength = 0; } - if (blockInsecureCommonPasswords) { - if (blocklist.includes(password)) { - strength = 0; - } - } return strength; } -- cgit 1.5.1