diff --git a/src/equicordplugins/fileUpload/index.tsx b/src/equicordplugins/fileUpload/index.tsx index 08f1f0a22..6e7586165 100644 --- a/src/equicordplugins/fileUpload/index.tsx +++ b/src/equicordplugins/fileUpload/index.tsx @@ -21,6 +21,7 @@ export const settings = definePluginSettings({ description: "", options: [ { label: "Zipline", value: ServiceType.ZIPLINE, default: true }, + { label: "E-Z Host", value: ServiceType.EZHOST }, ...(IS_DISCORD_DESKTOP ? [{ label: "Nest", value: ServiceType.NEST }] : []) ], hidden: true @@ -31,6 +32,12 @@ export const settings = definePluginSettings({ default: "", hidden: true }, + ezHostKey: { + type: OptionType.STRING, + description: "E-Z Host API key", + default: "", + hidden: true + }, ziplineToken: { type: OptionType.STRING, description: "", diff --git a/src/equicordplugins/fileUpload/settings.tsx b/src/equicordplugins/fileUpload/settings.tsx index 0d16446f6..24d012346 100644 --- a/src/equicordplugins/fileUpload/settings.tsx +++ b/src/equicordplugins/fileUpload/settings.tsx @@ -16,9 +16,12 @@ export function SettingsComponent() { const update = useForceUpdater(); const { store } = settings; const isNest = store.serviceType === ServiceType.NEST; + const isEzHost = store.serviceType === ServiceType.EZHOST; + const isZipline = store.serviceType === ServiceType.ZIPLINE; const serviceOptions = [ { label: "Zipline", value: ServiceType.ZIPLINE }, + { label: "E-Z Host", value: ServiceType.EZHOST }, ...(IS_DISCORD_DESKTOP ? [{ label: "Nest", value: ServiceType.NEST }] : []) ]; @@ -37,7 +40,7 @@ export function SettingsComponent() { /> - {!isNest && ( + {isZipline && ( )} - {!isNest && ( + {isZipline && ( )} + {isEzHost && ( + + (store as { ezHostKey?: string }).ezHostKey = v} + placeholder="Your E-Z Host API key" + /> + + )} + {isNest && ( )} - {!isNest && ( + {isZipline && ( = { [ServiceType.ZIPLINE]: "Zipline", [ServiceType.NEST]: "Nest" + , + [ServiceType.EZHOST]: "E-Z Host" }; export interface UploadResponse { diff --git a/src/equicordplugins/fileUpload/utils/getMediaUrl.ts b/src/equicordplugins/fileUpload/utils/getMediaUrl.ts index 393186e21..cc1caab65 100644 --- a/src/equicordplugins/fileUpload/utils/getMediaUrl.ts +++ b/src/equicordplugins/fileUpload/utils/getMediaUrl.ts @@ -113,7 +113,7 @@ export function isSupported(url: string): boolean { return ext ? supportedExtensions.includes(ext) : false; } -export function getMediaUrl(props: any): string | null { +export function getMediaUrl(props: { src?: string; href?: string; itemSrc?: string; itemHref?: string; target?: any }): string | null { const url = props.src || props.href || props.itemSrc || props.itemHref; if (url && isSupported(url)) return url; diff --git a/src/equicordplugins/fileUpload/utils/upload.ts b/src/equicordplugins/fileUpload/utils/upload.ts index e2e2bb8e7..36349fa82 100644 --- a/src/equicordplugins/fileUpload/utils/upload.ts +++ b/src/equicordplugins/fileUpload/utils/upload.ts @@ -91,10 +91,44 @@ async function uploadToNest(fileBlob: Blob, filename: string): Promise { export function isConfigured(): boolean { const { serviceType, serviceUrl, ziplineToken, nestToken } = settings.store; - if (serviceType === ServiceType.NEST) { - return Boolean(nestToken); + switch (serviceType) { + case ServiceType.NEST: + return Boolean(nestToken); + case ServiceType.EZHOST: + return Boolean((settings.store as { ezHostKey?: string }).ezHostKey); + case ServiceType.ZIPLINE: + default: + return Boolean(serviceUrl && ziplineToken); } - return Boolean(serviceUrl && ziplineToken); +} + +async function uploadToEzHost(fileBlob: Blob, filename: string): Promise { + const ezHostKey = (settings.store as { ezHostKey?: string }).ezHostKey; + + if (!ezHostKey) throw new Error("E-Z Host API key is required"); + + const formData = new FormData(); + formData.append("file", fileBlob, filename); + + const headers: Record = { key: ezHostKey }; + + const response = await fetch("https://api.e-z.host/files", { + method: "POST", + headers, + body: formData + }); + + if (!response.ok) { + const text = await response.text(); + throw new Error(`Upload failed: ${response.status} ${text}`); + } + + const data = await response.json(); + if (!data || !data.success) { + throw new Error(data?.error || "Upload failed"); + } + + return data.imageUrl || data.rawUrl; } export async function uploadFile(url: string): Promise { @@ -150,6 +184,9 @@ export async function uploadFile(url: string): Promise { case ServiceType.NEST: uploadedUrl = await uploadToNest(typedBlob, filename); break; + case ServiceType.EZHOST: + uploadedUrl = await uploadToEzHost(typedBlob, filename); + break; default: throw new Error("Unknown service type"); }