feat(plugin): FixFileExtensions

This commit is contained in:
thororen1234 2024-10-27 02:07:41 -04:00
parent 2c773ec7d1
commit 0d4cfd5e3b
3 changed files with 67 additions and 20 deletions

View file

@ -17,9 +17,9 @@
*/
import { Upload } from "@api/MessageEvents";
import { definePluginSettings } from "@api/Settings";
import { definePluginSettings, Settings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs, EquicordDevs } from "@utils/constants";
import { Devs, reverseExtensionMap } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy, findByPropsLazy } from "@webpack";
@ -42,11 +42,6 @@ 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,
@ -72,7 +67,7 @@ const settings = definePluginSettings({
export default definePlugin({
name: "AnonymiseFileNames",
authors: [Devs.fawn, EquicordDevs.thororen],
authors: [Devs.fawn],
description: "Anonymise uploaded file names",
patches: [
{
@ -125,17 +120,8 @@ export default definePlugin({
const tarMatch = tarExtMatcher.exec(file);
const extIdx = tarMatch?.index ?? file.lastIndexOf(".");
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";
if (Settings.plugins.FixFileExtensions.enabled) {
ext = reverseExtensionMap[ext];
}
switch (settings.store.method) {