-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.tsx
More file actions
1642 lines (1472 loc) · 67.1 KB
/
index.tsx
File metadata and controls
1642 lines (1472 loc) · 67.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import "./styles.css";
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { definePluginSettings } from "@api/Settings";
import { Divider } from "@components/Divider";
import { Flex } from "@components/Flex";
import { FormSwitch } from "@components/FormSwitch";
import { Heading } from "@components/Heading";
import { OpenExternalIcon } from "@components/Icons";
import { Paragraph } from "@components/Paragraph";
import { Devs } from "@utils/constants";
import { insertTextIntoChatInputBox, sendMessage } from "@utils/discord";
import { Margins } from "@utils/margins";
import definePlugin, { OptionType, PluginNative } from "@utils/types";
import { Button, createRoot, DraftType, Menu, PermissionsBits, PermissionStore, React, Select, SelectedChannelStore, showToast, TextInput, Toasts, UploadManager, useEffect, useState } from "@webpack/common";
import { LoggingLevel, pluginLogger as log, setLoggingLevelProvider } from "./logging";
import { UploadProgressBar } from "./renderer/components/UploadProgressBar";
import { disableDragDropOverride, enableDragDropOverride, isForumOrSlashCommandContextForChannel, setNitroLimitChecker, setUploadFunction } from "./renderer/dragDrop";
import { formatFileSize } from "./renderer/formatting";
import { showUploadNotification } from "./renderer/notifications";
import { clearAndForceHide, completeAndDispatch, completeUpload as completeUploadTracking, markDispatched, startProgressPolling, startUploadBatch, stopProgressPolling } from "./renderer/progress";
const Native = VencordNative.pluginHelpers.BigFileUpload as PluginNative<typeof import("./native")>;
// Check if native module is available (not available in browser extension)
function isNativeAvailable(): boolean {
return Native != null && typeof Native.uploadFileBuffer === "function";
}
// Type for upload result from native functions
interface UploadResult {
success: boolean;
url?: string;
fileName?: string;
fileSize?: number;
uploadId?: string;
actualUploader?: string;
attemptedUploaders?: string[];
error?: string;
}
// Progress tracking - use centralized module
function generateUploadId(): string {
return `upload-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
}
function createCloneableStore(initialState: any) {
const store = { ...initialState };
const listeners: (() => void)[] = [];
function get() {
return { ...store };
}
function set(newState: Partial<typeof store>) {
Object.assign(store, newState);
listeners.forEach(listener => listener());
}
function subscribe(listener: () => void) {
listeners.push(listener);
return () => {
const index = listeners.indexOf(listener);
if (index > -1) {
listeners.splice(index, 1);
}
};
}
return {
get,
set,
subscribe
};
}
// Helper function to safely get error messages
function getErrorMessage(error: unknown): string {
if (error instanceof Error) {
return error.message;
}
if (typeof error === "string") {
return error;
}
return String(error);
}
function sendTextToChat(text: string) {
if (settings.store.autoSend === "No") {
insertTextIntoChatInputBox(text);
} else {
const channelId = SelectedChannelStore.getChannelId();
sendMessage(channelId, { content: text });
}
}
// showUploadNotification moved to ./renderer/notifications.ts for sharing with UploadProgressBar
function notifyFallbackInfo(result: any) {
const attempted: string[] | undefined = result?.attemptedUploaders;
const uploader: string | undefined = result?.actualUploader;
if (!attempted || attempted.length <= 1 || !uploader) return;
const failed = attempted.slice(0, -1);
if (!failed.length) return;
const message = `Fallback used: ${failed.join(", ")} failed, uploaded via ${uploader}.`;
log.info(message);
showUploadNotification(message, Toasts.Type.MESSAGE);
}
type NativeNotification = { type: string; message: string; timestamp?: number; };
function handleNativeNotification(notification: NativeNotification) {
const toastType = notification.type === "failure"
? Toasts.Type.FAILURE
: notification.type === "success"
? Toasts.Type.SUCCESS
: Toasts.Type.MESSAGE;
// Log native events to renderer console (native logs go to main process, not visible in DevTools)
if (notification.type === "failure") {
log.error(notification.message);
} else if (notification.type === "success") {
log.info(notification.message);
} else {
log.info(notification.message);
}
showUploadNotification(notification.message, toastType);
}
let nativeNotificationInterval: number | null = null;
async function pollNativeNotifications() {
try {
const notifications = await Native.getPendingNotifications?.();
if (!notifications?.length) return;
for (const notification of notifications) {
handleNativeNotification(notification);
}
} catch (error) {
log.warn("Failed to poll native notifications:", error);
}
}
function startNativeNotificationPolling() {
if (nativeNotificationInterval !== null) return;
// Poll immediately once to catch queued notifications
void pollNativeNotifications();
// Poll every 500ms for faster fallback notifications
nativeNotificationInterval = window.setInterval(() => {
void pollNativeNotifications();
}, 500);
}
function stopNativeNotificationPolling() {
if (nativeNotificationInterval !== null) {
clearInterval(nativeNotificationInterval);
nativeNotificationInterval = null;
}
}
// Format ETA seconds into human-readable string
function SettingsComponent(props: { setValue(v: any): void; }) {
const initialUploader = settings.store.fileUploader || "Catbox";
const [fileUploader, setFileUploader] = useState(initialUploader);
const [customUploaderStore] = useState(() => createCloneableStore({
name: settings.store.customUploaderName || "",
requestURL: settings.store.customUploaderRequestURL || "",
fileFormName: settings.store.customUploaderFileFormName || "",
responseType: settings.store.customUploaderResponseType || "",
url: settings.store.customUploaderURL || "",
thumbnailURL: settings.store.customUploaderThumbnailURL || "",
headers: (() => {
const parsedHeaders = JSON.parse(settings.store.customUploaderHeaders || "{}");
if (Object.keys(parsedHeaders).length === 0) {
parsedHeaders[""] = "";
}
return parsedHeaders;
})(),
args: (() => {
const parsedArgs = JSON.parse(settings.store.customUploaderArgs || "{}");
if (Object.keys(parsedArgs).length === 0) {
parsedArgs[""] = "";
}
return parsedArgs;
})(),
requestMethod: settings.store.customUploaderRequestMethod || "POST",
bodyType: settings.store.customUploaderBodyType || "MultipartFormData",
}));
const fileInputRef = React.useRef<HTMLInputElement>(null);
useEffect(() => {
if (!settings.store.fileUploader || settings.store.fileUploader.trim() === "") {
updateSetting("fileUploader", "Catbox");
}
const unsubscribe = customUploaderStore.subscribe(() => {
const state = customUploaderStore.get();
updateSetting("customUploaderName", state.name);
updateSetting("customUploaderRequestURL", state.requestURL);
updateSetting("customUploaderFileFormName", state.fileFormName);
updateSetting("customUploaderResponseType", state.responseType);
updateSetting("customUploaderURL", state.url);
updateSetting("customUploaderThumbnailURL", state.thumbnailURL);
updateSetting("customUploaderHeaders", JSON.stringify(state.headers));
updateSetting("customUploaderArgs", JSON.stringify(state.args));
updateSetting("customUploaderRequestMethod", state.requestMethod);
updateSetting("customUploaderBodyType", state.bodyType);
});
return unsubscribe;
}, []);
function updateSetting(key: keyof typeof settings.store, value: any) {
if (key in settings.store) {
(settings.store as any)[key] = value;
} else {
log.error(`Invalid setting key: ${key}`);
}
}
function handleShareXConfigUpload(event: React.ChangeEvent<HTMLInputElement>) {
const file = event.target.files?.[0];
if (file) {
const reader = new FileReader();
reader.onload = (e: ProgressEvent<FileReader>) => {
try {
const result = e.target?.result;
if (typeof result !== "string") {
throw new Error("FileReader did not return a string");
}
const config = JSON.parse(result);
// Detect body type from ShareX config
const bodyType = config.Body === "Binary" ? "Binary" : "MultipartFormData";
customUploaderStore.set({
name: "",
requestURL: "",
fileFormName: "",
responseType: "Text",
url: "",
thumbnailURL: "",
headers: { "": "" },
args: { "": "" },
requestMethod: "POST",
bodyType: "MultipartFormData"
});
customUploaderStore.set({
name: config.Name || "",
requestURL: config.RequestURL || "",
fileFormName: config.FileFormName || "",
responseType: config.ResponseType || "Text",
url: config.URL || "",
thumbnailURL: config.ThumbnailURL || "",
headers: config.Headers || { "": "" },
args: config.Arguments || { "": "" },
requestMethod: config.RequestMethod || "POST",
bodyType: bodyType
});
updateSetting("customUploaderName", config.Name || "");
updateSetting("customUploaderRequestURL", config.RequestURL || "");
updateSetting("customUploaderFileFormName", config.FileFormName || "");
updateSetting("customUploaderResponseType", config.ResponseType || "Text");
updateSetting("customUploaderURL", config.URL || "");
updateSetting("customUploaderThumbnailURL", config.ThumbnailURL || "");
updateSetting("customUploaderHeaders", JSON.stringify(config.Headers || { "": "" }));
updateSetting("customUploaderArgs", JSON.stringify(config.Arguments || { "": "" }));
updateSetting("customUploaderRequestMethod", config.RequestMethod || "POST");
updateSetting("customUploaderBodyType", bodyType);
setFileUploader("Custom");
updateSetting("fileUploader", "Custom");
showToast("ShareX config imported successfully");
} catch (error) {
log.error("Error parsing ShareX config:", error);
showToast("Invalid ShareX config. Ensure it's valid JSON.");
}
};
reader.readAsText(file);
event.target.value = "";
}
}
const validateCustomUploaderSettings = () => {
if (fileUploader === "Custom") {
if (!settings.store.customUploaderRequestURL || settings.store.customUploaderRequestURL.trim() === "") {
showToast("Custom uploader: Request URL is required");
return false;
}
if (!settings.store.customUploaderFileFormName || settings.store.customUploaderFileFormName.trim() === "") {
showToast("Custom uploader: File form name is required");
return false;
}
if (!settings.store.customUploaderURL || settings.store.customUploaderURL.trim() === "") {
showToast("Custom uploader: Response URL path is required");
return false;
}
// Check for placeholder values that shouldn't be there
if (settings.store.customUploaderURL.includes("$json:") || settings.store.customUploaderURL.includes("$")) {
showToast("Custom uploader: Replace $json:... placeholders with actual JSON paths");
return false;
}
}
return true;
};
const handleFileUploaderChange = (v: string) => {
if (!v || v.trim() === "") {
log.warn("Attempted to select empty uploader, keeping current selection");
return;
}
if (v === "Custom" && !validateCustomUploaderSettings()) {
return;
}
setFileUploader(v);
updateSetting("fileUploader", v);
};
const handleArgChange = (oldKey: string, newKey: string, value: any) => {
const state = customUploaderStore.get();
const newArgs = { ...state.args };
if (oldKey !== newKey) {
delete newArgs[oldKey];
}
if (value === "" && newKey === "") {
delete newArgs[oldKey];
} else {
newArgs[newKey] = value;
}
// Only add empty key-value pair if all current ones are filled
if (Object.values(newArgs).every(v => v !== "") && Object.keys(newArgs).every(k => k !== "")) {
newArgs[""] = "";
}
// Single set() call to avoid double-write
customUploaderStore.set({ args: newArgs });
};
const handleHeaderChange = (oldKey: string, newKey: string, value: string) => {
const state = customUploaderStore.get();
const newHeaders = { ...state.headers };
if (oldKey !== newKey) {
delete newHeaders[oldKey];
}
if (value === "" && newKey === "") {
delete newHeaders[oldKey];
} else {
newHeaders[newKey] = value;
}
// Only add empty key-value pair if all current ones are filled
if (Object.values(newHeaders).every(v => v !== "") && Object.keys(newHeaders).every(k => k !== "")) {
newHeaders[""] = "";
}
// Single set() call to avoid double-write
customUploaderStore.set({ headers: newHeaders });
};
const triggerFileUpload = () => {
if (fileInputRef.current) {
fileInputRef.current.click();
}
};
return (
<Flex flexDirection="column" style={{ gap: "12px" }}>
{/* Main Settings */}
<Heading tag="h5">File Uploader Service</Heading>
<Paragraph className={Margins.bottom8}>
Choose where your files will be uploaded. If one service fails, the plugin will automatically try fallback options.
</Paragraph>
<Select
className={Margins.bottom20}
options={[
{ label: "Catbox (Up to 200MB, Permanent, Embeds)", value: "Catbox" },
{ label: "Litterbox (Up to 1GB, 3 days, Embeds)", value: "Litterbox" },
{ label: "0x0.st (Up to 512MB, 1 year, Embeds)", value: "0x0.st" },
{ label: "GoFile (Unlimited, 10 days)", value: "GoFile" },
{ label: "tmpfiles.org (Up to 100MB, 60 min)", value: "tmpfiles.org" },
{ label: "buzzheavier.com (Unlimited, 60 days)", value: "buzzheavier.com" },
{ label: "temp.sh (Up to 4GB, 3 days)", value: "temp.sh" },
{ label: "filebin.net (Unlimited, 6 days)", value: "filebin.net" },
{ label: "Custom Uploader", value: "Custom" },
]}
select={handleFileUploaderChange}
isSelected={v => v === fileUploader}
serialize={v => v}
closeOnSelect={true}
clearable={false}
/>
<Divider />
{/* Behavior Settings */}
<Heading tag="h5">Upload Behavior</Heading>
<Paragraph className={Margins.bottom8}>
Configure how uploaded file links are handled and displayed in Discord.
</Paragraph>
<FormSwitch
title="Enable Paste"
description="Intercept file paste events. Disable to let Discord handle pastes natively."
value={settings.store.pasteEnabled !== "No"}
onChange={(enabled: boolean) => {
updateSetting("pasteEnabled", enabled ? "Yes" : "No");
// Dynamically enable/disable paste handler
// Always remove first to prevent listener accumulation
document.removeEventListener("paste", handlePaste, { capture: true });
if (enabled) {
document.addEventListener("paste", handlePaste, { capture: true });
log.info("Paste interception enabled");
} else {
log.info("Paste interception disabled");
}
}}
/>
<FormSwitch
title="Enable Drag and Drop"
description="Intercept drag and drop file uploads (up to 1GB). Disable to let Discord handle drag and drop natively."
value={settings.store.dragAndDropEnabled !== "No"}
onChange={(enabled: boolean) => {
updateSetting("dragAndDropEnabled", enabled ? "Yes" : "No");
// Dynamically enable/disable drag and drop
if (enabled) {
enableDragDropOverride();
log.info("Drag-and-drop enabled");
} else {
disableDragDropOverride();
log.info("Drag-and-drop disabled");
}
}}
/>
<FormSwitch
title="Respect Nitro Upload Limit"
description="Let Discord handle files under your Nitro limit natively. Only intercept files that exceed Discord's limit."
value={settings.store.respectNitroLimit === "Yes"}
onChange={(enabled: boolean) => updateSetting("respectNitroLimit", enabled ? "Yes" : "No")}
hideBorder={settings.store.respectNitroLimit === "Yes"}
/>
{settings.store.respectNitroLimit === "Yes" && (
<>
<Select
className={Margins.bottom20}
options={[
{ label: "No Nitro (10MB limit)", value: "none" },
{ label: "Nitro Basic (50MB limit)", value: "basic" },
{ label: "Nitro (500MB limit)", value: "full" },
]}
placeholder="Select your Nitro tier..."
select={value => updateSetting("nitroType", value)}
isSelected={value => value === (settings.store.nitroType || "none")}
serialize={value => value}
closeOnSelect={true}
clearable={false}
/>
<Divider />
</>
)}
<FormSwitch
title="Disable Fallback Uploaders"
description="Only use your selected uploader. If it fails, the upload will fail instead of trying other services. Useful for custom uploaders."
value={settings.store.disableFallbacks === "Yes"}
onChange={(enabled: boolean) => updateSetting("disableFallbacks", enabled ? "Yes" : "No")}
/>
<FormSwitch
title="Embed Video Files"
description="Wrap uploaded video file links with an embed service to embed videos that Discord might not embed. Only applies to video files (mp4, webm, mkv, etc.)."
value={settings.store.useEmbedsVideo === "Yes"}
onChange={(enabled: boolean) => updateSetting("useEmbedsVideo", enabled ? "Yes" : "No")}
/>
{settings.store.useEmbedsVideo === "Yes" && (
<>
<Paragraph className={Margins.bottom8}>
Choose which embed service to use for video files:
</Paragraph>
<Select
className={Margins.bottom20}
options={[
{ label: "x266.mov", value: "x266" },
{ label: "embeddr.top", value: "embeddr" },
{ label: "discord.nfp.is", value: "nfp" },
]}
placeholder="Choose an embed service..."
select={value => updateSetting("embedService", value)}
isSelected={value => value === (settings.store.embedService || "x266")}
serialize={value => value}
closeOnSelect={true}
clearable={false}
/>
</>
)}
<FormSwitch
title="Display Original Filename"
description="Format upload links as clickable text showing the original filename. Example: [vacation_video.mp4](link) instead of the raw link."
value={settings.store.autoFormat === "Yes"}
onChange={(enabled: boolean) => updateSetting("autoFormat", enabled ? "Yes" : "No")}
/>
<FormSwitch
title="Auto-Send Links"
description="Automatically send uploaded file links to chat immediately after upload completes."
value={settings.store.autoSend === "Yes"}
onChange={(enabled: boolean) => updateSetting("autoSend", enabled ? "Yes" : "No")}
/>
<FormSwitch
title="Use Notifications Instead of Toasts"
description="Show Vencord notifications instead of inline toasts."
value={settings.store.useNotifications === "Yes"}
onChange={(enabled: boolean) => updateSetting("useNotifications", enabled ? "Yes" : "No")}
/>
<Heading tag="h5">Console Logging</Heading>
<Paragraph className={Margins.bottom8}>
Control how much information BigFileUpload prints to the console. Errors only keeps the log quiet, while verbose is useful for debugging.
</Paragraph>
<Select
className={Margins.bottom20}
options={[
{ label: "Errors only (quiet)", value: "errors" },
{ label: "Important info", value: "info" },
{ label: "Verbose debug", value: "debug" },
]}
placeholder="Choose how chatty the logs should be..."
select={value => updateSetting("loggingLevel", value as LoggingLevel)}
isSelected={value => value === (settings.store.loggingLevel || "errors")}
serialize={value => value}
closeOnSelect={true}
clearable={false}
/>
{/* Service-Specific Settings */}
{fileUploader === "GoFile" && (
<>
<Divider />
<Heading tag="h5">GoFile Account (Optional)</Heading>
<Paragraph className={Margins.bottom8}>
Link your GoFile account to save all uploads to your personal storage.
</Paragraph>
<TextInput
className={Margins.bottom20}
type="text"
value={settings.store.gofileToken || ""}
placeholder="Enter your GoFile token here..."
onChange={newValue => updateSetting("gofileToken", newValue)}
/>
</>
)}
{fileUploader === "Catbox" && (
<>
<Divider />
<Heading tag="h5">Catbox Account (Optional)</Heading>
<Paragraph className={Margins.bottom8}>
Save uploads to your Catbox account by providing your user hash.
</Paragraph>
<TextInput
className={Margins.bottom20}
type="text"
value={settings.store.catboxUserHash || ""}
placeholder="Enter your Catbox user hash..."
onChange={newValue => updateSetting("catboxUserHash", newValue)}
/>
</>
)}
{fileUploader === "Litterbox" && (
<>
<Divider />
<Heading tag="h5">File Expiration</Heading>
<Paragraph className={Margins.bottom8}>
Choose how long files should remain available before automatic deletion.
</Paragraph>
<Select
className={Margins.bottom20}
options={[
{ label: "1 hour", value: "1h" },
{ label: "12 hours", value: "12h" },
{ label: "24 hours (1 day)", value: "24h" },
{ label: "72 hours (3 days)", value: "72h" },
]}
placeholder="Select expiration time..."
select={newValue => updateSetting("litterboxTime", newValue)}
isSelected={v => v === settings.store.litterboxTime}
serialize={v => v}
/>
</>
)}
{fileUploader === "0x0.st" && (
<>
<Divider />
<Heading tag="h5">0x0.st Expiration (Optional)</Heading>
<Paragraph className={Margins.bottom8}>
Set expiration time using flexible format: 1y 2w 3d 4h 5m 6s (or combined like 1y2w3d4h5m6s). Examples: "7d" (7 days), "1y" (1 year), "30d" (30 days), "168h" (7 days). Maximum: 1 year. Leave empty for automatic retention based on file size: smaller files kept longer (up to 1 year), larger files shorter retention (minimum 30 days).
</Paragraph>
<TextInput
className={Margins.bottom20}
type="text"
value={settings.store.zeroX0Expires || ""}
placeholder="e.g., 7d or 1y2w or 168h"
onChange={newValue => updateSetting("zeroX0Expires", newValue)}
/>
</>
)}
{fileUploader === "Custom" && (
<>
<Divider />
<Heading tag="h5">Custom Uploader</Heading>
<Paragraph className={Margins.bottom8}>
Configure your own upload service. Compatible with ShareX custom uploaders and can bypass CSP restrictions. This uploader is exclusive (no fallbacks to other services).
</Paragraph>
<Heading tag="h5">Uploader Name</Heading>
<TextInput
className={Margins.bottom20}
type="text"
value={customUploaderStore.get().name}
placeholder="e.g., My Custom Uploader"
onChange={(newValue: string) => customUploaderStore.set({ name: newValue })}
/>
<Heading tag="h5">API Endpoint</Heading>
<TextInput
className={Margins.bottom20}
type="text"
value={customUploaderStore.get().requestURL}
placeholder="https://example.com/api/upload"
onChange={(newValue: string) => customUploaderStore.set({ requestURL: newValue })}
/>
<Heading tag="h5">File Form Field Name</Heading>
<TextInput
className={Margins.bottom20}
type="text"
value={customUploaderStore.get().fileFormName}
placeholder="e.g., file, image, upload"
onChange={(newValue: string) => customUploaderStore.set({ fileFormName: newValue })}
/>
<Heading tag="h5">HTTP Method</Heading>
<Paragraph className={Margins.bottom8}>
Most uploaders use POST. Use PUT for raw binary uploads (like transfer.sh style APIs).
</Paragraph>
<Select
className={Margins.bottom20}
options={[
{ label: "POST", value: "POST" },
{ label: "PUT", value: "PUT" },
{ label: "PATCH", value: "PATCH" },
]}
placeholder="Select HTTP method..."
select={(newValue: string) => customUploaderStore.set({ requestMethod: newValue })}
isSelected={(v: string) => v === customUploaderStore.get().requestMethod}
serialize={(v: string) => v}
/>
<Heading tag="h5">Body Type</Heading>
<Paragraph className={Margins.bottom8}>
Multipart for form uploads with fields. Binary for raw file uploads (PUT-style APIs).
</Paragraph>
<Select
className={Margins.bottom20}
options={[
{ label: "Multipart Form Data", value: "MultipartFormData" },
{ label: "Binary (raw file)", value: "Binary" },
]}
placeholder="Select body type..."
select={(newValue: string) => customUploaderStore.set({ bodyType: newValue })}
isSelected={(v: string) => v === customUploaderStore.get().bodyType}
serialize={(v: string) => v}
/>
<Heading tag="h5">Response Format</Heading>
<Select
className={Margins.bottom20}
options={[
{ label: "Plain Text", value: "Text" },
{ label: "JSON", value: "JSON" },
]}
placeholder="Select response type..."
select={(newValue: string) => customUploaderStore.set({ responseType: newValue })}
isSelected={(v: string) => v === customUploaderStore.get().responseType}
serialize={(v: string) => v}
/>
<Heading tag="h5">URL Path (JSON)</Heading>
<Paragraph className={Margins.bottom8}>
Extract URL from JSON response. Examples: "url", "data.file_url", "result.download_link" (NOT a full URL!)
</Paragraph>
<TextInput
className={Margins.bottom20}
type="text"
value={customUploaderStore.get().url}
placeholder="url"
onChange={(newValue: string) => customUploaderStore.set({ url: newValue })}
/>
<Heading tag="h5">Thumbnail Path (Optional)</Heading>
<TextInput
className={Margins.bottom20}
type="text"
value={customUploaderStore.get().thumbnailURL}
placeholder="thumbnail_url"
onChange={(newValue: string) => customUploaderStore.set({ thumbnailURL: newValue })}
/>
<Divider />
<Heading tag="h5">Request Arguments</Heading>
<div className={Margins.bottom20}>
{Object.entries(customUploaderStore.get().args).map(([key, value], index) => (
<div key={index} style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "8px", marginBottom: "8px" }}>
<TextInput
type="text"
value={key}
placeholder="Key"
onChange={(newKey: string) => handleArgChange(key, newKey, value as string)}
/>
<TextInput
type="text"
value={value as string}
placeholder="Value"
onChange={(newValue: string) => handleArgChange(key, key, newValue)}
/>
</div>
))}
</div>
<Divider />
<Heading tag="h5">Custom Headers</Heading>
<div className={Margins.bottom20}>
{Object.entries(customUploaderStore.get().headers).map(([key, value], index) => (
<div key={index} style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "8px", marginBottom: "8px" }}>
<TextInput
type="text"
value={key}
placeholder="Header Key"
onChange={(newKey: string) => handleHeaderChange(key, newKey, value as string)}
/>
<TextInput
type="text"
value={value as string}
placeholder="Header Value"
onChange={(newValue: string) => handleHeaderChange(key, key, newValue)}
/>
</div>
))}
</div>
<Divider />
<Heading tag="h5">ShareX Import</Heading>
<Paragraph className={Margins.bottom8}>
Quickly import configuration from a ShareX custom uploader file (.sxcu)
</Paragraph>
<Button
onClick={triggerFileUpload}
color={Button.Colors.BRAND}
size={Button.Sizes.MEDIUM}
>
Import ShareX Config
</Button>
<input
ref={fileInputRef}
type="file"
accept=".sxcu"
style={{ display: "none" }}
onChange={handleShareXConfigUpload}
/>
</>
)}
</Flex>
);
}
export const settings = definePluginSettings({
fileUploader: {
type: OptionType.SELECT,
options: [
{ label: "Catbox (Up to 200MB, Permanent)", value: "Catbox", default: true },
{ label: "Litterbox (Up to 1GB, 3 days)", value: "Litterbox" },
{ label: "0x0.st (Up to 512MB, Up to 1 year)", value: "0x0.st" },
{ label: "tmpfiles.org (100MB, 60 min)", value: "tmpfiles.org" },
{ label: "GoFile (Unlimited, +10 days)", value: "GoFile" },
{ label: "buzzheavier.com (Unlimited, +60 days)", value: "buzzheavier.com" },
{ label: "temp.sh (Up to 4GB, 3 days)", value: "temp.sh" },
{ label: "filebin.net (Unlimited, 6 days)", value: "filebin.net" },
{ label: "Custom Uploader", value: "Custom" },
],
description: "Select the file uploader service",
hidden: true
},
gofileToken: {
type: OptionType.STRING,
default: "",
description: "GoFile Token (optional)",
hidden: true
},
autoSend: {
type: OptionType.SELECT,
options: [
{ label: "Yes", value: "Yes" },
{ label: "No", value: "No", default: true },
],
description: "Auto-Send",
hidden: true
},
autoFormat: {
type: OptionType.SELECT,
options: [
{ label: "Yes", value: "Yes" },
{ label: "No", value: "No", default: true },
],
description: "Auto-Format",
hidden: true
},
uploadTimeout: {
type: OptionType.SELECT,
options: [
{ label: "1 minute", value: "60000" },
{ label: "2 minutes", value: "120000" },
{ label: "5 minutes (Recommended)", value: "300000", default: true },
{ label: "10 minutes", value: "600000" },
],
description: "How long to wait for the server to respond. Lower values may cause uploads to fail for large files or slow connections.",
},
catboxUserHash: {
type: OptionType.STRING,
default: "",
description: "User hash for Catbox uploader (optional)",
hidden: true
},
litterboxTime: {
type: OptionType.SELECT,
options: [
{ label: "1 hour", value: "1h" },
{ label: "12 hours", value: "12h" },
{ label: "24 hours", value: "24h" },
{ label: "72 hours (3 days)", value: "72h", default: true },
],
description: "Duration for files on Litterbox before they are deleted",
hidden: true
},
zeroX0Expires: {
type: OptionType.STRING,
default: "1y",
description: "Expiration for 0x0.st uploads (optional, e.g., '7d', '1y', '1y2w3d4h5m6s')",
hidden: true
},
customUploaderName: {
type: OptionType.STRING,
default: "",
description: "Name of the custom uploader",
hidden: true
},
customUploaderRequestURL: {
type: OptionType.STRING,
default: "",
description: "Request URL for the custom uploader",
hidden: true
},
customUploaderFileFormName: {
type: OptionType.STRING,
default: "",
description: "File form name for the custom uploader",
hidden: true
},
customUploaderResponseType: {
type: OptionType.SELECT,
options: [
{ label: "Text", value: "Text", default: true },
{ label: "JSON", value: "JSON" },
],
description: "Response type for the custom uploader",
hidden: true
},
customUploaderURL: {
type: OptionType.STRING,
default: "",
description: "URL (JSON path) for the custom uploader",
hidden: true
},
customUploaderThumbnailURL: {
type: OptionType.STRING,
default: "",
description: "Thumbnail URL (JSON path) for the custom uploader",
hidden: true
},
customUploaderHeaders: {
type: OptionType.STRING,
default: JSON.stringify({}),
description: "Headers for the custom uploader (JSON string)",
hidden: true
},
customUploaderArgs: {
type: OptionType.STRING,
default: JSON.stringify({}),
description: "Arguments for the custom uploader (JSON string)",
hidden: true
},
customUploaderRequestMethod: {
type: OptionType.SELECT,
options: [
{ label: "POST", value: "POST", default: true },
{ label: "PUT", value: "PUT" },
{ label: "PATCH", value: "PATCH" },
],
description: "HTTP method for the custom uploader",
hidden: true
},
customUploaderBodyType: {
type: OptionType.SELECT,
options: [
{ label: "Multipart Form Data", value: "MultipartFormData", default: true },
{ label: "Binary (raw file)", value: "Binary" },
],
description: "Request body type for the custom uploader",
hidden: true
},
useNotifications: {
type: OptionType.SELECT,
options: [
{ label: "Yes", value: "Yes" },
{ label: "No", value: "No", default: true },
],
description: "Use desktop notifications instead of toasts",
hidden: true
},
useEmbedsVideo: {
type: OptionType.SELECT,
options: [
{ label: "Yes", value: "Yes", default: true },
{ label: "No", value: "No" },
],
description: "Wrap uploaded video URLs with an embed service for better embedding",
hidden: true
},
embedService: {
type: OptionType.SELECT,
options: [
{ label: "x266.mov", value: "x266", default: true },
{ label: "embeddr.top", value: "embeddr" },
{ label: "discord.nfp.is", value: "nfp" },
],
description: "Which embed service to use for video files",
hidden: true
},
dragAndDropEnabled: {
type: OptionType.SELECT,
options: [
{ label: "Yes", value: "Yes", default: true },
{ label: "No", value: "No" },
],
description: "Enable drag and drop file uploads",
hidden: true
},
pasteEnabled: {
type: OptionType.SELECT,
options: [
{ label: "Yes", value: "Yes", default: true },
{ label: "No", value: "No" },
],
description: "Enable paste file uploads",
hidden: true
},
respectNitroLimit: {
type: OptionType.SELECT,
options: [
{ label: "Yes", value: "Yes", default: true },
{ label: "No", value: "No" },
],
description: "Use Discord native upload for files under Nitro limit",
hidden: true
},
nitroType: {
type: OptionType.SELECT,