From d869df150e2e49094fe25005a623f439c0500a3a Mon Sep 17 00:00:00 2001 From: 9gvuwu <130901666+9gvuwu@users.noreply.github.com> Date: Thu, 12 Feb 2026 15:04:58 +0200 Subject: [PATCH] fix FileUpload + userhash (#762) --- src/equicordplugins/fileUpload/native.ts | 70 ++++++++++++++++++- src/equicordplugins/fileUpload/settings.tsx | 17 +++++ .../fileUpload/utils/upload.ts | 59 +++++++--------- 3 files changed, 113 insertions(+), 33 deletions(-) diff --git a/src/equicordplugins/fileUpload/native.ts b/src/equicordplugins/fileUpload/native.ts index 487be09e7..cafd2f8cf 100644 --- a/src/equicordplugins/fileUpload/native.ts +++ b/src/equicordplugins/fileUpload/native.ts @@ -136,13 +136,81 @@ export async function uploadToS3( } } +export async function uploadToCatbox( + _: IpcMainInvokeEvent, + fileBuffer: ArrayBuffer, + filename: string, + userhash?: string +): Promise { + try { + const formData = new FormData(); + formData.append("reqtype", "fileupload"); + if (userhash) { + formData.append("userhash", userhash); + } + formData.append("fileToUpload", new Blob([fileBuffer]), filename); + + const response = await fetch("https://catbox.moe/user/api.php", { + method: "POST", + body: formData + }); + + if (!response.ok) { + const errorText = await response.text(); + return { success: false, error: `Upload failed: ${response.status} ${errorText}` }; + } + + const text = (await response.text()).trim(); + if (!text) { + return { success: false, error: "No URL returned from upload" }; + } + + return { success: true, url: text }; + } catch (e) { + return { success: false, error: e instanceof Error ? e.message : "Unknown error" }; + } +} + +export async function uploadToLitterbox( + _: IpcMainInvokeEvent, + fileBuffer: ArrayBuffer, + filename: string, + expiry: string +): Promise { + try { + const formData = new FormData(); + formData.append("reqtype", "fileupload"); + formData.append("time", expiry); + formData.append("fileToUpload", new Blob([fileBuffer]), filename); + + const response = await fetch("https://litterbox.catbox.moe/resources/internals/api.php", { + method: "POST", + body: formData + }); + + if (!response.ok) { + const errorText = await response.text(); + return { success: false, error: `Upload failed: ${response.status} ${errorText}` }; + } + + const text = (await response.text()).trim(); + if (!text) { + return { success: false, error: "No URL returned from upload" }; + } + + return { success: true, url: text }; + } catch (e) { + return { success: false, error: e instanceof Error ? e.message : "Unknown error" }; + } +} + export async function fetchFile( _: IpcMainInvokeEvent, url: string -): Promise<{ success: boolean; data?: ArrayBuffer; contentType?: string; error?: string }> { +): Promise<{ success: boolean; data?: ArrayBuffer; contentType?: string; error?: string; }> { try { diff --git a/src/equicordplugins/fileUpload/settings.tsx b/src/equicordplugins/fileUpload/settings.tsx index 7da397c98..118f5ce2a 100644 --- a/src/equicordplugins/fileUpload/settings.tsx +++ b/src/equicordplugins/fileUpload/settings.tsx @@ -128,6 +128,12 @@ export const settings = definePluginSettings({ default: "24h", hidden: true }, + catboxUserhash: { + type: OptionType.STRING, + description: "Catbox userhash for account binding", + default: "", + hidden: true + }, stripQueryParams: { type: OptionType.BOOLEAN, description: "Strip query params from uploaded URLs", @@ -180,6 +186,7 @@ export function SettingsComponent() { const isEzHost = store.serviceType === ServiceType.EZHOST; const isS3 = store.serviceType === ServiceType.S3; const isZipline = store.serviceType === ServiceType.ZIPLINE; + const isCatbox = store.serviceType === ServiceType.CATBOX; const isLitterbox = store.serviceType === ServiceType.LITTERBOX; return ( @@ -310,6 +317,16 @@ export function SettingsComponent() { )} + {isCatbox && ( + store.catboxUserhash = v} + placeholder="Your Catbox userhash" + /> + )} + {isLitterbox && (