From 3be348c48487b708aaeec2735a5aaf2e43a156c5 Mon Sep 17 00:00:00 2001 From: TheCodedProf Date: Sat, 22 Apr 2023 20:59:14 -0400 Subject: [PATCH] added yarn.lock to git --- .gitignore | 1 - src/utils/database.ts | 56 +++++++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 9eaba59..03b27c2 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,6 @@ src/config/main.ts .vscode/ .vim/ yarn-error.log -yarn.lock src/utils/temp/*.png src/utils/temp/*.webp src/utils/temp/*.jpeg diff --git a/src/utils/database.ts b/src/utils/database.ts index 5ae2523..7353ff7 100644 --- a/src/utils/database.ts +++ b/src/utils/database.ts @@ -618,33 +618,37 @@ export class ScanCache { } async write(hash: string, type: "nsfw" | "malware" | "bad_link", data: boolean, tags?: string[]) { - await this.scanCache.updateOne( - { hash: hash }, - { - $set: (() => { - switch (type) { - case "nsfw": { - return { nsfw: data, addedAt: new Date() }; - } - case "malware": { - return { malware: data, addedAt: new Date() }; - } - case "bad_link": { - return { bad_link: data, tags: tags ?? [], addedAt: new Date() }; - } - default: { - throw new Error("Invalid type"); - } - } - })() - // No you can't just do { [type]: data }, yes it's a typescript error, no I don't know how to fix it - // cleanly, yes it would be marginally more elegant, no it's not essential, yes I'd be happy to review - // PRs that did improve this snippet - // Made an attempt... Gave up... Just Leave It - // Counter: 2 - }, - Object.assign({ upsert: true }, collectionOptions) + await this.scanCache.insertOne( + { hash: hash, [type]: data, tags: tags ?? [], addedAt: new Date() }, + collectionOptions ); + // await this.scanCache.updateOne( + // { hash: hash }, + // { + // $set: (() => { + // switch (type) { + // case "nsfw": { + // return { nsfw: data, addedAt: new Date() }; + // } + // case "malware": { + // return { malware: data, addedAt: new Date() }; + // } + // case "bad_link": { + // return { bad_link: data, tags: tags ?? [], addedAt: new Date() }; + // } + // default: { + // throw new Error("Invalid type"); + // } + // } + // })() + // // No you can't just do { [type]: data }, yes it's a typescript error, no I don't know how to fix it + // // cleanly, yes it would be marginally more elegant, no it's not essential, yes I'd be happy to review + // // PRs that did improve this snippet + // // Made an attempt... Gave up... Just Leave It + // // Counter: 2 + // }, + // Object.assign({ upsert: true }, collectionOptions) + // ); } async cleanup() {