Skip to content

Commit 5f9762f

Browse files
committed
fix: token & xshare app compatibility
1 parent da875e4 commit 5f9762f

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/components/pages/settings/parts/SettingsGenerators/GeneratorButton.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Response } from '@/lib/api/response';
12
import type { Config } from '@/lib/config/validate';
23
import {
34
Anchor,
@@ -16,10 +17,10 @@ import {
1617
import { IconDownload, IconEyeFilled, IconGlobe, IconPercentage, IconWriting } from '@tabler/icons-react';
1718
import Link from 'next/link';
1819
import React, { useReducer, useState } from 'react';
20+
import useSWR from 'swr';
1921
import { flameshot } from './generators/flameshot';
2022
import { sharex } from './generators/sharex';
2123
import { shell } from './generators/shell';
22-
import { useUserStore } from '@/lib/store/user';
2324

2425
export type GeneratorOptions = {
2526
deletesAt: string | null;
@@ -30,6 +31,9 @@ export type GeneratorOptions = {
3031
overrides_returnDomain: string | null;
3132
noJson: boolean | null;
3233

34+
// changes {json:...} to $json:...$ for the Xshare app on Android
35+
sharex_xshareCompatibility: boolean | null;
36+
3337
// echo instead of copying
3438
unix_useEcho: boolean | null;
3539
// uses pbcopy instead of xclip
@@ -69,6 +73,8 @@ export const defaultGeneratorOptions: GeneratorOptions = {
6973
overrides_returnDomain: null,
7074
noJson: null,
7175

76+
sharex_xshareCompatibility: null,
77+
7278
unix_useEcho: null,
7379
mac_enableCompatibility: null,
7480
wl_enableCompatibility: null,
@@ -90,7 +96,6 @@ export default function GeneratorButton({
9096
icon: React.ReactNode;
9197
desc?: React.ReactNode;
9298
}) {
93-
const user = useUserStore((state) => state.user);
9499
const [opened, setOpen] = useState(false);
95100

96101
const [generatorType, setGeneratorType] = useState('file');
@@ -99,6 +104,8 @@ export default function GeneratorButton({
99104
defaultGeneratorOptions,
100105
);
101106

107+
const { data: tokenData, isLoading, error } = useSWR<Response['/api/user/token']>('/api/user/token');
108+
102109
const isUnixLike = name === 'Flameshot' || name === 'Shell Script';
103110
const onlyFile = generatorType === 'file';
104111

@@ -204,6 +211,16 @@ export default function GeneratorButton({
204211
disabled={!onlyFile}
205212
/>
206213

214+
{name === 'ShareX' && (
215+
<Switch
216+
label='Xshare Compatibility'
217+
description='If you choose to use the Xshare app on Android, enable this option for compatibility. The genereated config will not work with ShareX.'
218+
checked={options.sharex_xshareCompatibility ?? false}
219+
onChange={(event) => setOption({ sharex_xshareCompatibility: event.currentTarget.checked })}
220+
disabled={!onlyFile}
221+
/>
222+
)}
223+
207224
{isUnixLike && (
208225
<>
209226
<Switch
@@ -281,7 +298,7 @@ export default function GeneratorButton({
281298

282299
<Button
283300
onClick={() =>
284-
generators[name as keyof typeof generators](user!.token!, generatorType as any, options)
301+
generators[name as keyof typeof generators](tokenData!.token!, generatorType as any, options)
285302
}
286303
fullWidth
287304
leftSection={<IconDownload size='1rem' />}
@@ -292,7 +309,7 @@ export default function GeneratorButton({
292309
</Stack>
293310
</Modal>
294311

295-
<Button size='sm' leftSection={icon} onClick={() => setOpen(true)}>
312+
<Button size='sm' leftSection={icon} onClick={() => setOpen(true)} disabled={isLoading || error}>
296313
{name}
297314
</Button>
298315
</>

src/components/pages/settings/parts/SettingsGenerators/generators/sharex.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ export function sharex(token: string, type: 'file' | 'url', options: GeneratorOp
88
DestinationType: 'ImageUploader, TextUploader, FileUploader',
99
RequestMethod: 'POST',
1010
RequestURL: `${window.location.origin}/api/upload`,
11-
Headers: {
12-
authorization: token,
13-
},
14-
URL: '{json:files[0].url}',
11+
Headers: {},
12+
URL: options.sharex_xshareCompatibility ? '$json:files[0].url$' : '{json:files[0].url}',
1513
Body: 'MultipartFormData',
1614
FileFormName: 'file',
1715
Data: undefined,
@@ -27,7 +25,9 @@ export function sharex(token: string, type: 'file' | 'url', options: GeneratorOp
2725
(config as any).Data = JSON.stringify({ url: '{input}' });
2826
}
2927

30-
const toAddHeaders: UploadHeaders = {};
28+
const toAddHeaders: UploadHeaders = {
29+
authorization: token,
30+
};
3131

3232
if (options.deletesAt !== null && type === 'file') {
3333
toAddHeaders['x-zipline-deletes-at'] = options.deletesAt;

src/lib/uploader/parseHeaders.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export type UploadHeaders = {
6060
'x-zipline-p-identifier'?: string;
6161
'x-zipline-p-lastchunk'?: StringBoolean;
6262
'x-zipline-p-content-length'?: string;
63+
64+
authorization?: string;
6365
};
6466

6567
export type UploadOptions = {

0 commit comments

Comments
 (0)