fix: shell script uploader/shorten (#786)

* fix filenames with spaces + fix mime type uploads

* Add proper MIME type for uploads (especially videos)
  in shell script

* Few fixes for shell script uploader

* encapsulating all headers
* tr not needed (anymore?)
* removing `echo` as it is not returning anything
  because it is already printing on stdout
* parsing correct key for url uploader

* `echo` string seems like not needed anymore

also passed prettier

---------

Co-authored-by: dicedtomato <35403473+diced@users.noreply.github.com>
This commit is contained in:
rlko
2025-04-29 20:49:18 +02:00
committed by GitHub
parent 2e59f5bd7f
commit 567a855ba1
3 changed files with 12 additions and 7 deletions

View File

@@ -45,7 +45,6 @@ export type GeneratorOptions = {
};
export const copier = (options: GeneratorOptions) => {
if (options.unix_useEcho) return 'echo';
if (options.mac_enableCompatibility) return 'pbcopy';
if (options.wl_enableCompatibility) return 'wl-copy';
return 'xclip -selection clipboard';

View File

@@ -10,7 +10,7 @@ export function shell(token: string, type: 'file' | 'url', options: GeneratorOpt
];
if (type === 'file') {
curl.push('-F', 'file=@$1');
curl.push('-F', '"file=@$1;type=$(file --mime-type -b "$1")"');
curl.push('-H', "'content-type: multipart/form-data'");
} else {
curl.push('-H', "'content-type: application/json'");
@@ -61,20 +61,22 @@ export function shell(token: string, type: 'file' | 'url', options: GeneratorOpt
}
for (const [key, value] of Object.entries(toAddHeaders)) {
curl.push('-H', `${key}: ${value}`);
curl.push('-H', `"${key}: ${value}"`);
}
let script;
if (type === 'file') {
script = `#!/bin/bash
${curl.join(' ')}${options.noJson ? '' : ' | jq -r .files[0].url'} | tr -d '\\n' | ${copier(options)}
${curl.join(' ')}${options.noJson ? '' : ' | jq -r .files[0].url'}${
options.unix_useEcho ? '' : ` | ${copier(options)}`
}
`;
} else {
script = `#!/bin/bash
${curl.join(' ')} -d "{\\"url\\": \\"$1\\"}"${
options.noJson ? '' : ' | jq -r .files[0].url'
} | tr -d '\\n' | ${copier(options)}
${curl.join(' ')} -d "{\\"destination\\": \\"$1\\"}"${
options.noJson ? '' : ' | jq -r .url'
}${options.unix_useEcho ? '' : ` | ${copier(options)}`}
`;
}

View File

@@ -79,6 +79,10 @@ export default function SettingsGenerators() {
<Code>curl</Code>
</Anchor>
,{' '}
<Anchor component={Link} href='https://darwinsys.com/file/'>
<Code>file</Code>
</Anchor>
,{' '}
<Anchor component={Link} href='https://github.com/stedolan/jq'>
<Code>jq</Code>
</Anchor>