From c0032bf413cede1107ceb3f316fd488b681c30ac Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 27 Jun 2021 11:24:31 +0200 Subject: :sparkles: Config: ipdataApiKey + register.blockProxies --- src/util/Config.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/util/Config.ts') diff --git a/src/util/Config.ts b/src/util/Config.ts index f125bd18..30d216a4 100644 --- a/src/util/Config.ts +++ b/src/util/Config.ts @@ -88,6 +88,7 @@ export interface DefaultOptions { sitekey: string | null; secret: string | null; }; + ipdataApiKey: string | null; }; login: { requireCaptcha: boolean; @@ -107,6 +108,7 @@ export interface DefaultOptions { requireInvite: boolean; allowNewRegistration: boolean; allowMultipleAccounts: boolean; + blockProxies: boolean; password: { minLength: number; minNumbers: number; @@ -176,6 +178,7 @@ export const DefaultOptions: DefaultOptions = { sitekey: null, secret: null, }, + ipdataApiKey: "eca677b284b3bac29eb72f5e496aa9047f26543605efe99ff2ce35c9", }, login: { requireCaptcha: false, @@ -196,6 +199,7 @@ export const DefaultOptions: DefaultOptions = { requireCaptcha: true, allowNewRegistration: true, allowMultipleAccounts: true, + blockProxies: true, password: { minLength: 8, minNumbers: 2, -- cgit 1.5.1 From 7efdbe4027e39c6cc2571b4eba8ba174dd177962 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 27 Jun 2021 23:11:04 +0200 Subject: :bug: fix mongoose cache --- src/util/Config.ts | 2 +- src/util/Database.ts | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'src/util/Config.ts') diff --git a/src/util/Config.ts b/src/util/Config.ts index 30d216a4..bd8559a8 100644 --- a/src/util/Config.ts +++ b/src/util/Config.ts @@ -4,7 +4,7 @@ import db, { MongooseCache } from "./Database"; import { Snowflake } from "./Snowflake"; import crypto from "crypto"; -var Config = new MongooseCache(db.collection("config"), [], { onlyEvents: false }); +var Config = new MongooseCache(db.collection("config"), [], { onlyEvents: false, array: false }); export default { init: async function init(defaultOpts: any = DefaultOptions) { diff --git a/src/util/Database.ts b/src/util/Database.ts index 3a0f0157..1b77629f 100644 --- a/src/util/Database.ts +++ b/src/util/Database.ts @@ -52,9 +52,11 @@ export class MongooseCache extends EventEmitter { public pipeline: Array>, public opts: { onlyEvents: boolean; + array?: boolean; } ) { super(); + if (this.opts.array == null) this.opts.array = true; } init = async () => { @@ -67,7 +69,8 @@ export class MongooseCache extends EventEmitter { if (!this.opts.onlyEvents) { const arr = await this.collection.aggregate(this.pipeline).toArray(); - this.data = arr.length ? arr[0] : arr; + if (this.opts.array) this.data = arr || []; + else this.data = arr?.[0]; } }; @@ -90,23 +93,34 @@ export class MongooseCache extends EventEmitter { change = (doc: ChangeEvent) => { try { - // @ts-ignore - if (doc.fullDocument) { - // @ts-ignore - if (!this.opts.onlyEvents) this.data = doc.fullDocument; - } - switch (doc.operationType) { case "dropDatabase": return this.destroy(); case "drop": return this.destroy(); case "delete": + if (!this.opts.onlyEvents) { + if (this.opts.array) { + this.data = this.data.filter((x: any) => doc.documentKey?._id?.equals(x._id)); + } else this.data = null; + } return this.emit("delete", doc.documentKey._id.toHexString()); case "insert": + if (!this.opts.onlyEvents) { + if (this.opts.array) this.data.push(doc.fullDocument); + else this.data = doc.fullDocument; + } return this.emit("insert", doc.fullDocument); case "update": case "replace": + if (!this.opts.onlyEvents) { + if (this.opts.array) { + const i = this.data.findIndex((x: any) => doc.fullDocument?._id?.equals(x._id)); + if (i == -1) this.data.push(doc.fullDocument); + else this.data[i] = doc.fullDocument; + } else this.data = doc.fullDocument; + } + return this.emit("change", doc.fullDocument); case "invalidate": return this.destroy(); @@ -119,6 +133,7 @@ export class MongooseCache extends EventEmitter { }; destroy = () => { + this.data = null; this.stream?.off("change", this.change); this.emit("close"); -- cgit 1.5.1 From 137d719ecfad4529169d96d5f45cac9f263edbe8 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:21:30 +0200 Subject: :bug: fix Config --- src/util/Config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/util/Config.ts') diff --git a/src/util/Config.ts b/src/util/Config.ts index bd8559a8..dfa942e7 100644 --- a/src/util/Config.ts +++ b/src/util/Config.ts @@ -9,7 +9,7 @@ var Config = new MongooseCache(db.collection("config"), [], { onlyEvents: false, export default { init: async function init(defaultOpts: any = DefaultOptions) { await Config.init(); - return this.set(Config.data.merge(defaultOpts)); + return this.set((Config.data || {}).merge(defaultOpts)); }, get: function get() { return Config.data; -- cgit 1.5.1