mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-23 23:15:10 +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+$/;
|
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({
|
const settings = definePluginSettings({
|
||||||
anonymiseByDefault: {
|
anonymiseByDefault: {
|
||||||
description: "Whether to anonymise file names by default",
|
description: "Whether to anonymise file names by default",
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
invertedBehaviorFileExtensions: {
|
||||||
|
description: "File extensions for which to use the oppposite Anonymize by Default behavior",
|
||||||
|
type: OptionType.STRING,
|
||||||
|
placeholder: "pdf, zip"
|
||||||
|
},
|
||||||
method: {
|
method: {
|
||||||
description: "Anonymising method",
|
description: "Anonymising method",
|
||||||
type: OptionType.SELECT,
|
type: OptionType.SELECT,
|
||||||
|
@ -96,7 +112,7 @@ export default definePlugin({
|
||||||
settings,
|
settings,
|
||||||
|
|
||||||
renderIcon: ErrorBoundary.wrap(({ upload, channelId, draftType }: { upload: AnonUpload; draftType: unknown; channelId: string; }) => {
|
renderIcon: ErrorBoundary.wrap(({ upload, channelId, draftType }: { upload: AnonUpload; draftType: unknown; channelId: string; }) => {
|
||||||
const anonymise = upload.anonymise ?? settings.store.anonymiseByDefault;
|
const anonymise = shouldAnonymize(upload);
|
||||||
return (
|
return (
|
||||||
<ActionBarIcon
|
<ActionBarIcon
|
||||||
tooltip={anonymise ? "Using anonymous file name" : "Using normal file name"}
|
tooltip={anonymise ? "Using anonymous file name" : "Using normal file name"}
|
||||||
|
@ -114,7 +130,7 @@ export default definePlugin({
|
||||||
}, { noop: true }),
|
}, { noop: true }),
|
||||||
|
|
||||||
anonymise(upload: AnonUpload) {
|
anonymise(upload: AnonUpload) {
|
||||||
if ((upload.anonymise ?? settings.store.anonymiseByDefault) === false) return upload.filename;
|
if (!shouldAnonymize(upload)) return upload.filename;
|
||||||
|
|
||||||
const file = upload.filename;
|
const file = upload.filename;
|
||||||
const tarMatch = tarExtMatcher.exec(file);
|
const tarMatch = tarExtMatcher.exec(file);
|
||||||
|
|
Loading…
Add table
Reference in a new issue