Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
thororen1234 2025-05-21 17:58:24 -04:00
commit 5621847709
No known key found for this signature in database
2 changed files with 45 additions and 38 deletions

View file

@ -23,12 +23,10 @@ import ErrorBoundary from "@components/ErrorBoundary";
import { reverseExtensionMap } from "@equicordplugins/fixFileExtensions"; import { reverseExtensionMap } from "@equicordplugins/fixFileExtensions";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy, findByPropsLazy } from "@webpack"; import { findByCodeLazy } from "@webpack";
import { useState } from "@webpack/common";
type AnonUpload = Upload & { anonymise?: boolean; };
const ActionBarIcon = findByCodeLazy(".actionBarIcon)"); const ActionBarIcon = findByCodeLazy(".actionBarIcon)");
const UploadDraft = findByPropsLazy("popFirstFile", "update");
const enum Methods { const enum Methods {
Random, Random,
@ -36,6 +34,7 @@ const enum Methods {
Timestamp, Timestamp,
} }
const ANONYMISE_UPLOAD_SYMBOL = Symbol("vcAnonymise");
export const tarExtMatcher = /\.tar\.\w+$/; export const tarExtMatcher = /\.tar\.\w+$/;
const settings = definePluginSettings({ const settings = definePluginSettings({
@ -76,41 +75,44 @@ export default definePlugin({
name: "AnonymiseFileNames", name: "AnonymiseFileNames",
authors: [Devs.fawn], authors: [Devs.fawn],
description: "Anonymise uploaded file names", description: "Anonymise uploaded file names",
settings,
patches: [ patches: [
{ {
find: "instantBatchUpload:", find: 'type:"UPLOAD_START"',
replacement: { replacement: {
match: /uploadFiles:(\i),/, match: /await \i\.uploadFiles\((\i),/,
replace: replace: "$1.forEach($self.anonymise),$&"
"uploadFiles:(...args)=>(args[0].uploads.forEach(f=>f.filename=$self.anonymise(f)),$1(...args)),",
}, },
}, },
{ {
find: 'addFilesTo:"message.attachments"', find: 'addFilesTo:"message.attachments"',
replacement: { replacement: {
match: /(\i.uploadFiles\((\i),)/, match: /\i.uploadFiles\((\i),/,
replace: "$2.forEach(f=>f.filename=$self.anonymise(f)),$1" replace: "$1.forEach($self.anonymise),$&"
} }
}, },
{ {
find: "#{intl::ATTACHMENT_UTILITIES_SPOILER}", find: "#{intl::ATTACHMENT_UTILITIES_SPOILER}",
replacement: { replacement: {
match: /(?<=children:\[)(?=.{10,80}tooltip:.{0,100}#{intl::ATTACHMENT_UTILITIES_SPOILER})/, match: /(?<=children:\[)(?=.{10,80}tooltip:.{0,100}#{intl::ATTACHMENT_UTILITIES_SPOILER})/,
replace: "arguments[0].canEdit!==false?$self.renderIcon(arguments[0]):null," replace: "arguments[0].canEdit!==false?$self.AnonymiseUploadButton(arguments[0]):null,"
}, },
}, },
], ],
settings,
renderIcon: ErrorBoundary.wrap(({ upload, channelId, draftType }: { upload: AnonUpload; draftType: unknown; channelId: string; }) => { AnonymiseUploadButton: ErrorBoundary.wrap(({ upload }: { upload: Upload; }) => {
const anonymise = upload.anonymise ?? settings.store.anonymiseByDefault; const [anonymise, setAnonymise] = useState(upload[ANONYMISE_UPLOAD_SYMBOL] ?? settings.store.anonymiseByDefault);
function onToggleAnonymise() {
upload[ANONYMISE_UPLOAD_SYMBOL] = !anonymise;
setAnonymise(!anonymise);
}
return ( return (
<ActionBarIcon <ActionBarIcon
tooltip={anonymise ? "Using anonymous file name" : "Using normal file name"} tooltip={anonymise ? "Using anonymous file name" : "Using normal file name"}
onClick={() => { onClick={onToggleAnonymise}
upload.anonymise = !anonymise;
UploadDraft.update(channelId, upload.id, draftType, {}); // dummy update so component rerenders
}}
> >
{anonymise {anonymise
? <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="currentColor" d="M17.06 13C15.2 13 13.64 14.33 13.24 16.1C12.29 15.69 11.42 15.8 10.76 16.09C10.35 14.31 8.79 13 6.94 13C4.77 13 3 14.79 3 17C3 19.21 4.77 21 6.94 21C9 21 10.68 19.38 10.84 17.32C11.18 17.08 12.07 16.63 13.16 17.34C13.34 19.39 15 21 17.06 21C19.23 21 21 19.21 21 17C21 14.79 19.23 13 17.06 13M6.94 19.86C5.38 19.86 4.13 18.58 4.13 17S5.39 14.14 6.94 14.14C8.5 14.14 9.75 15.42 9.75 17S8.5 19.86 6.94 19.86M17.06 19.86C15.5 19.86 14.25 18.58 14.25 17S15.5 14.14 17.06 14.14C18.62 14.14 19.88 15.42 19.88 17S18.61 19.86 17.06 19.86M22 10.5H2V12H22V10.5M15.53 2.63C15.31 2.14 14.75 1.88 14.22 2.05L12 2.79L9.77 2.05L9.72 2.04C9.19 1.89 8.63 2.17 8.43 2.68L6 9H18L15.56 2.68L15.53 2.63Z" /></svg> ? <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="currentColor" d="M17.06 13C15.2 13 13.64 14.33 13.24 16.1C12.29 15.69 11.42 15.8 10.76 16.09C10.35 14.31 8.79 13 6.94 13C4.77 13 3 14.79 3 17C3 19.21 4.77 21 6.94 21C9 21 10.68 19.38 10.84 17.32C11.18 17.08 12.07 16.63 13.16 17.34C13.34 19.39 15 21 17.06 21C19.23 21 21 19.21 21 17C21 14.79 19.23 13 17.06 13M6.94 19.86C5.38 19.86 4.13 18.58 4.13 17S5.39 14.14 6.94 14.14C8.5 14.14 9.75 15.42 9.75 17S8.5 19.86 6.94 19.86M17.06 19.86C15.5 19.86 14.25 18.58 14.25 17S15.5 14.14 17.06 14.14C18.62 14.14 19.88 15.42 19.88 17S18.61 19.86 17.06 19.86M22 10.5H2V12H22V10.5M15.53 2.63C15.31 2.14 14.75 1.88 14.22 2.05L12 2.79L9.77 2.05L9.72 2.04C9.19 1.89 8.63 2.17 8.43 2.68L6 9H18L15.56 2.68L15.53 2.63Z" /></svg>
@ -120,20 +122,21 @@ export default definePlugin({
); );
}, { noop: true }), }, { noop: true }),
anonymise(upload: AnonUpload) { anonymise(upload: Upload) {
const file = upload.filename;
const tarMatch = tarExtMatcher.exec(file); const originalFileName = upload.filename;
const extIdx = tarMatch?.index ?? file.lastIndexOf("."); const tarMatch = tarExtMatcher.exec(originalFileName);
const fileName = extIdx !== -1 ? file.substring(0, extIdx) : ""; const extIdx = tarMatch?.index ?? originalFileName.lastIndexOf(".");
let ext = extIdx !== -1 ? file.slice(extIdx) : ""; let ext = extIdx !== -1 ? originalFileName.slice(extIdx) : "";
const addSpoilerPrefix = (str: string) => settings.store.spoilerMessages ? "SPOILER_" + str : str; const addSpoilerPrefix = (str: string) => settings.store.spoilerMessages ? "SPOILER_" + str : str;
if (Settings.plugins.FixFileExtensions.enabled) { if (Settings.plugins.FixFileExtensions.enabled) {
ext = reverseExtensionMap[ext] || ext; ext = reverseExtensionMap[ext] || ext;
} }
if ((upload.anonymise ?? settings.store.anonymiseByDefault) === false) return addSpoilerPrefix(fileName + ext); if ((upload[ANONYMISE_UPLOAD_SYMBOL] ?? settings.store.anonymiseByDefault) === false) return addSpoilerPrefix(originalFileName + ext);
const newFilename = (() => {
switch (settings.store.method) { switch (settings.store.method) {
case Methods.Random: case Methods.Random:
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
@ -147,6 +150,9 @@ export default definePlugin({
case Methods.Timestamp: case Methods.Timestamp:
return addSpoilerPrefix(Date.now().toString() + ext); return addSpoilerPrefix(Date.now().toString() + ext);
} }
})();
upload.filename = newFilename;
}, },
commands: [{ commands: [{

View file

@ -107,6 +107,7 @@ export default definePlugin({
] ]
}, },
// User Profile Modal & User Profile Modal v2
...[".__invalid_connectedAccountOpenIconContainer", ".BLUESKY||"].map(find => ({ ...[".__invalid_connectedAccountOpenIconContainer", ".BLUESKY||"].map(find => ({
find, find,
replacement: { replacement: {