feat(anonymiseFileNames): fixOpusExtensions setting

This commit is contained in:
thororen1234 2024-09-06 17:24:48 -04:00
parent 86bee7731c
commit 05c699c81e

View file

@ -19,7 +19,7 @@
import { Upload } from "@api/MessageEvents";
import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { Devs, EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy, findByPropsLazy } from "@webpack";
@ -42,6 +42,11 @@ const settings = definePluginSettings({
type: OptionType.BOOLEAN,
default: true,
},
fixOpusExtensions: {
description: "Whether to fix file extensions by default",
type: OptionType.BOOLEAN,
default: true,
},
method: {
description: "Anonymising method",
type: OptionType.SELECT,
@ -67,7 +72,7 @@ const settings = definePluginSettings({
export default definePlugin({
name: "AnonymiseFileNames",
authors: [Devs.fawn],
authors: [Devs.fawn, EquicordDevs.thororen],
description: "Anonymise uploaded file names",
patches: [
{
@ -119,7 +124,19 @@ export default definePlugin({
const file = upload.filename;
const tarMatch = tarExtMatcher.exec(file);
const extIdx = tarMatch?.index ?? file.lastIndexOf(".");
const ext = extIdx !== -1 ? file.slice(extIdx) : "";
let ext = extIdx !== -1 ? file.slice(extIdx) : "";
const matchList = [
".ogv",
".oga",
".ogx",
".ogm",
".spx",
".opus"
];
if (settings.store.fixOpusExtensions && ext !== "ogg" && matchList.includes(ext)) {
ext = ".ogg";
}
switch (settings.store.method) {
case Methods.Random: