From 4c0776cb62be91de4ddfe7dbc746ea238456c58e Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Thu, 9 Oct 2025 13:47:58 -0400 Subject: [PATCH] Fix ZipPreview --- src/equicordplugins/zipPreview/index.tsx | 7 +++++-- src/main/csp/index.ts | 9 +-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/equicordplugins/zipPreview/index.tsx b/src/equicordplugins/zipPreview/index.tsx index 45b818335..b8a05c0a4 100644 --- a/src/equicordplugins/zipPreview/index.tsx +++ b/src/equicordplugins/zipPreview/index.tsx @@ -15,7 +15,7 @@ import ZipPreview from "./ZipPreview"; async function fetchBlobWithDebug(url: string) { try { - const res = await fetch(url); + const res = await fetch("https://corsproxy.io/?url=" + encodeURIComponent(url)); if (!res.ok) { console.error("ZipPreview: fetch failed", url, res.status, res.statusText); return null; @@ -114,6 +114,9 @@ const blobCache = new Map(); // Component to render inside each zip attachment function ZipAttachmentPreview({ attachment }: { attachment: any; }) { + const ext = attachment.fileName.match(/\.tar\.\w+$|(\.\w+)$/)?.[0] ?? ""; + if (ext !== ".zip") return; + const [blob, setBlob] = useState(() => blobCache.get(attachment.id) || null); const [error, setError] = useState(null); const [expanded, setExpanded] = useState(() => { @@ -174,7 +177,7 @@ export default definePlugin({ find: "#{intl::ATTACHMENT_PROCESSING}", replacement: { match: /null!=\i&&\i\(\)(?<=renderAdjacentContent.*?\}=(\i);.*?)/, - replace: "$self.ZipAttachmentPreview({ attachment: $1 })" + replace: "$&,$self.ZipAttachmentPreview({ attachment: $1 })" } } ], diff --git a/src/main/csp/index.ts b/src/main/csp/index.ts index 1c8287428..813e47010 100644 --- a/src/main/csp/index.ts +++ b/src/main/csp/index.ts @@ -131,7 +131,7 @@ const patchCsp = (headers: PolicyMap) => { }; export function initCsp() { - session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, resourceType, url }, cb) => { + session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, resourceType }, cb) => { if (responseHeaders) { if (resourceType === "mainFrame") patchCsp(responseHeaders); @@ -143,13 +143,6 @@ export function initCsp() { if (header) responseHeaders[header] = ["text/css"]; } - - const parsedUrl = new URL(url); - if (parsedUrl.hostname === "cdn.discordapp.com" && parsedUrl.pathname.startsWith("/attachments")) { - responseHeaders["Access-Control-Allow-Origin"] = ["*"]; - responseHeaders["Access-Control-Allow-Methods"] = ["*"]; - responseHeaders["Access-Control-Allow-Headers"] = ["*"]; - } } cb({ cancel: false, responseHeaders });