feat: add ishare support

This commit is contained in:
diced
2025-02-21 12:28:43 -08:00
parent ef53a11bdf
commit eae5d755f6
4 changed files with 93 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ import useSWR from 'swr';
import { flameshot } from './generators/flameshot';
import { sharex } from './generators/sharex';
import { shell } from './generators/shell';
import { ishare } from './generators/ishare';
export type GeneratorOptions = {
deletesAt: string | null;
@@ -84,6 +85,7 @@ const generators = {
Flameshot: flameshot,
ShareX: sharex,
'Shell Script': shell,
ishare,
};
export default function GeneratorButton({
@@ -110,7 +112,7 @@ export default function GeneratorButton({
return (
<>
<Modal opened={opened} onClose={() => setOpen(false)} title={`Generate ${name}`}>
<Modal opened={opened} onClose={() => setOpen(false)} title={`Generate ${name} Uploader`}>
{desc && (
<Text size='sm' c='dimmed'>
{desc}
@@ -121,7 +123,7 @@ export default function GeneratorButton({
<Select
data={[
{ label: 'Upload File', value: 'file' },
{ label: 'Shorten URL', value: 'url' },
{ label: 'Shorten URL', value: 'url', disabled: name === 'ishare' },
]}
description='Select which type of destination you want to generate'
label='Destination Type'

View File

@@ -0,0 +1,70 @@
import { UploadHeaders } from '@/lib/uploader/parseHeaders';
import { GeneratorOptions, download } from '../GeneratorButton';
export function ishare(token: string, type: 'file' | 'url', options: GeneratorOptions) {
if (type === 'url') {
// unsupported in ishare
return;
}
const config = {
name: `Zipline - ${window.location.origin} - ${type === 'file' ? 'File' : 'URL'}`,
requestURL: `${window.location.origin}/api/upload`,
headers: {},
fileFormName: 'file',
requestBodyType: 'multipartFormData',
responseURL: `{{files[0].url}}`,
};
const toAddHeaders: UploadHeaders = {
authorization: token,
};
if (options.deletesAt !== null && type === 'file') {
toAddHeaders['x-zipline-deletes-at'] = options.deletesAt;
} else {
delete toAddHeaders['x-zipline-deletes-at'];
}
if (options.format !== 'default' && type === 'file') {
toAddHeaders['x-zipline-format'] = options.format;
} else {
delete toAddHeaders['x-zipline-format'];
}
if (options.imageCompressionPercent !== null && type === 'file') {
toAddHeaders['x-zipline-image-compression-percent'] = options.imageCompressionPercent.toString();
} else {
delete toAddHeaders['x-zipline-image-compression-percent'];
}
if (options.maxViews !== null) {
toAddHeaders['x-zipline-max-views'] = options.maxViews.toString();
} else {
delete toAddHeaders['x-zipline-max-views'];
}
// if (options.noJson === true) {
// // unsupported in ishare
// } else {
// delete toAddHeaders['x-zipline-no-json'];
// }
if (options.addOriginalName === true && type === 'file') {
toAddHeaders['x-zipline-original-name'] = 'true';
} else {
delete toAddHeaders['x-zipline-original-name'];
}
if (options.overrides_returnDomain !== null) {
toAddHeaders['x-zipline-domain'] = options.overrides_returnDomain;
} else {
delete toAddHeaders['x-zipline-domain'];
}
for (const [key, value] of Object.entries(toAddHeaders)) {
(config as any).headers[key] = value;
}
return download(`zipline-${type}.iscu`, JSON.stringify(config, null, 2));
}

View File

@@ -3,7 +3,7 @@ import { GeneratorOptions, download } from '../GeneratorButton';
export function sharex(token: string, type: 'file' | 'url', options: GeneratorOptions) {
const config = {
Version: '14.1.0',
Version: '17.0.0',
Name: `Zipline - ${window.location.origin} - ${type === 'file' ? 'File' : 'URL'}`,
DestinationType: 'ImageUploader, TextUploader, FileUploader',
RequestMethod: 'POST',

View File

@@ -1,4 +1,4 @@
import { Anchor, Code, Group, Paper, Text, Title } from '@mantine/core';
import { Anchor, Code, Group, Paper, Text, Title, Image as MantineImage } from '@mantine/core';
import { IconPrompt } from '@tabler/icons-react';
import Image from 'next/image';
import GeneratorButton from './GeneratorButton';
@@ -52,6 +52,23 @@ export default function SettingsGenerators() {
</>
}
/>
<GeneratorButton
name='ishare'
icon={
<MantineImage
width={24}
height={24}
alt='ishare logo'
src='https://isharemac.app/ishare/Util/Assets.xcassets/AppIcon.appiconset/AppIcon-128.png'
/>
}
desc={
<>
This generator requires <Anchor href='https://isharemac.app/'>ishare</Anchor> to be installed on
macOS. This uploader is intended for use on macOS only.
</>
}
/>
<GeneratorButton
name='Shell Script'
icon={<IconPrompt size={24} />}