feat(FileUpload): add E-Z to hosts (#687)
This commit is contained in:
parent
e5d30caaf3
commit
a31e38d466
5 changed files with 68 additions and 8 deletions
|
|
@ -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: "",
|
||||
|
|
|
|||
|
|
@ -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() {
|
|||
/>
|
||||
</SettingsSection>
|
||||
|
||||
{!isNest && (
|
||||
{isZipline && (
|
||||
<SettingsSection name="Service URL" description="The URL of your Zipline instance">
|
||||
<TextInput
|
||||
value={store.serviceUrl}
|
||||
|
|
@ -47,7 +50,7 @@ export function SettingsComponent() {
|
|||
</SettingsSection>
|
||||
)}
|
||||
|
||||
{!isNest && (
|
||||
{isZipline && (
|
||||
<SettingsSection name="Zipline Token" description="Your Zipline API authorization token">
|
||||
<TextInput
|
||||
value={store.ziplineToken}
|
||||
|
|
@ -57,6 +60,16 @@ export function SettingsComponent() {
|
|||
</SettingsSection>
|
||||
)}
|
||||
|
||||
{isEzHost && (
|
||||
<SettingsSection name="E-Z Host API Key" description="Your E-Z Host API key">
|
||||
<TextInput
|
||||
value={(store as { ezHostKey?: string }).ezHostKey || ""}
|
||||
onChange={v => (store as { ezHostKey?: string }).ezHostKey = v}
|
||||
placeholder="Your E-Z Host API key"
|
||||
/>
|
||||
</SettingsSection>
|
||||
)}
|
||||
|
||||
{isNest && (
|
||||
<SettingsSection name="Nest Token" description="Your Nest API authorization token">
|
||||
<TextInput
|
||||
|
|
@ -67,7 +80,7 @@ export function SettingsComponent() {
|
|||
</SettingsSection>
|
||||
)}
|
||||
|
||||
{!isNest && (
|
||||
{isZipline && (
|
||||
<SettingsSection name="Folder ID" description="Folder ID for uploads (leave empty for no folder)">
|
||||
<TextInput
|
||||
value={store.folderId}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,15 @@
|
|||
|
||||
export enum ServiceType {
|
||||
ZIPLINE = "zipline",
|
||||
NEST = "nest"
|
||||
NEST = "nest",
|
||||
EZHOST = "ezhost"
|
||||
}
|
||||
|
||||
export const serviceLabels: Record<ServiceType, string> = {
|
||||
[ServiceType.ZIPLINE]: "Zipline",
|
||||
[ServiceType.NEST]: "Nest"
|
||||
,
|
||||
[ServiceType.EZHOST]: "E-Z Host"
|
||||
};
|
||||
|
||||
export interface UploadResponse {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -91,10 +91,44 @@ async function uploadToNest(fileBlob: Blob, filename: string): Promise<string> {
|
|||
|
||||
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<string> {
|
||||
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<string, string> = { 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<void> {
|
||||
|
|
@ -150,6 +184,9 @@ export async function uploadFile(url: string): Promise<void> {
|
|||
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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue