From 1ce122a28f2021b66ad50fe56cd26fd8a494e282 Mon Sep 17 00:00:00 2001 From: Temm Date: Thu, 25 Jul 2024 19:28:50 +0200 Subject: [PATCH] feat(AnonymizeFilenames): add file extension exceptions --- src/plugins/anonymiseFileNames/index.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/plugins/anonymiseFileNames/index.tsx b/src/plugins/anonymiseFileNames/index.tsx index 526ccd12e..284c5591e 100644 --- a/src/plugins/anonymiseFileNames/index.tsx +++ b/src/plugins/anonymiseFileNames/index.tsx @@ -36,12 +36,28 @@ const enum Methods { const tarExtMatcher = /\.tar\.\w+$/; +function shouldAnonymize(upload: AnonUpload) { + if (upload.anonymise != null) return upload.anonymise; + + let anonymize = settings.store.anonymiseByDefault; + const ext = upload.filename.split(".").at(-1) ?? ""; + const invertedExts = (settings.store.invertedBehaviorFileExtensions ?? "") + .split(",").map(s => s.trim()).filter(s => s !== ""); + if (invertedExts.includes(ext)) anonymize = !anonymize; + return anonymize; +} + const settings = definePluginSettings({ anonymiseByDefault: { description: "Whether to anonymise file names by default", type: OptionType.BOOLEAN, default: true, }, + invertedBehaviorFileExtensions: { + description: "File extensions for which to use the oppposite Anonymize by Default behavior", + type: OptionType.STRING, + placeholder: "pdf, zip" + }, method: { description: "Anonymising method", type: OptionType.SELECT, @@ -96,7 +112,7 @@ export default definePlugin({ settings, renderIcon: ErrorBoundary.wrap(({ upload, channelId, draftType }: { upload: AnonUpload; draftType: unknown; channelId: string; }) => { - const anonymise = upload.anonymise ?? settings.store.anonymiseByDefault; + const anonymise = shouldAnonymize(upload); return (