mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-23 15:05:11 +00:00
feat(AnonymizeFilenames): add file extension exceptions
This commit is contained in:
parent
5e9a9fe836
commit
1ce122a28f
1 changed files with 18 additions and 2 deletions
|
@ -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 (
|
||||
<ActionBarIcon
|
||||
tooltip={anonymise ? "Using anonymous file name" : "Using normal file name"}
|
||||
|
@ -114,7 +130,7 @@ export default definePlugin({
|
|||
}, { noop: true }),
|
||||
|
||||
anonymise(upload: AnonUpload) {
|
||||
if ((upload.anonymise ?? settings.store.anonymiseByDefault) === false) return upload.filename;
|
||||
if (!shouldAnonymize(upload)) return upload.filename;
|
||||
|
||||
const file = upload.filename;
|
||||
const tarMatch = tarExtMatcher.exec(file);
|
||||
|
|
Loading…
Add table
Reference in a new issue