-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhealth-server.js
More file actions
2196 lines (2095 loc) ยท 80 KB
/
health-server.js
File metadata and controls
2196 lines (2095 loc) ยท 80 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
// Single public entrypoint for HF Spaces: HuggingPost dashboard + reverse
// proxy to Postiz (which lives behind the container's internal nginx on
// port 5000 โ that nginx routes /api โ backend, /uploads โ file system,
// / โ frontend).
//
// Routing rules (in order):
// /health, /status, /uptimerobot/setup โ handled here
// / (exact) โ HuggingPost dashboard HTML
// /app, /app/ or /app/* โ Postiz (nginx :5000), /app prefix stripped
// /_next/* or /static/* โ 301 redirect to /app/<same path>
// (catches asset URLs Next.js may emit
// without basePath in edge cases)
// anything else โ 404
//
// Why strip /app: the Postiz frontend is built with basePath="/app" so it
// emits asset URLs prefixed with /app. The browser sends /app/_next/foo to
// us; we strip /app and forward /_next/foo to nginx :5000, which forwards
// to Next.js on :4200. nginx's own routes (/api, /uploads, /) are also
// reached after we strip the /app prefix.
const http = require("http");
const fs = require("fs");
const net = require("net");
const path = require("path");
const PORT = 7860;
// Static files in Next.js public/ directory are served directly from disk.
// The nginx proxy chain re-adds the /app basePath prefix when forwarding to
// Next.js:4200, making public file paths misalign. Serving from disk here
// is simpler and faster.
const NEXTJS_PUBLIC_DIR = "/app/apps/frontend/public";
const MIME_TYPES = {
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".gif": "image/gif",
".webp": "image/webp",
".svg": "image/svg+xml",
".ico": "image/x-icon",
".woff": "font/woff",
".woff2": "font/woff2",
".ttf": "font/ttf",
".eot": "application/vnd.ms-fontobject",
".txt": "text/plain; charset=utf-8",
".xml": "application/xml",
};
const POSTIZ_HOST = "127.0.0.1";
const POSTIZ_PORT = 5000;
const startTime = Date.now();
const HF_BACKUP_ENABLED = !!process.env.HF_TOKEN;
const SYNC_INTERVAL = process.env.SYNC_INTERVAL || "300";
const CLOUDFLARE_KEEPALIVE_STATUS_FILE =
"/tmp/huggingpost-cloudflare-keepalive-status.json";
// Social platform env-var presence check (for dashboard status grid).
// Each entry: { name, emoji, ready: bool, setupUrl, envVars, noOAuth }
function getSocialPlatforms() {
const e = process.env;
return [
// โโ Works immediately (connect inside Postiz UI, no env vars needed) โโโโโ
{
name: "Bluesky",
emoji: "๐ฆ",
noOAuth: true,
ready: true,
note: "Username + App Password in Postiz",
},
{
name: "Mastodon",
emoji: "๐",
noOAuth: true,
ready: true,
note: "Instance URL + credentials in Postiz",
},
{
name: "Telegram",
emoji: "โ๏ธ",
noOAuth: true,
ready: true,
note: "Bot token from @BotFather in Postiz",
},
{
name: "Nostr",
emoji: "๐",
noOAuth: true,
ready: true,
note: "Private key in Postiz",
},
{
name: "Lemmy",
emoji: "๐พ",
noOAuth: true,
ready: true,
note: "Instance + credentials in Postiz",
},
{
name: "Warpcast",
emoji: "๐ฃ",
noOAuth: true,
ready: true,
note: "FID + private key in Postiz",
},
{
name: "Dev.to",
emoji: "๐ป",
noOAuth: true,
ready: true,
note: "API key from dev.to settings",
},
{
name: "Hashnode",
emoji: "๐ฐ",
noOAuth: true,
ready: true,
note: "API token from Hashnode settings",
},
// โโ Needs OAuth app (env vars required) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
{
id: "google",
name: "Google Login",
emoji: "๐ต",
ready: !!(e.GOOGLE_CLIENT_ID || e.YOUTUBE_CLIENT_ID),
setupUrl: "https://console.cloud.google.com/apis/credentials",
envVars: ["GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET"],
},
{
id: "linkedin",
name: "LinkedIn",
emoji: "๐ผ",
ready: !!(e.LINKEDIN_CLIENT_ID && e.LINKEDIN_CLIENT_ID !== "undefined"),
setupUrl: "https://www.linkedin.com/developers/apps/new",
envVars: ["LINKEDIN_CLIENT_ID", "LINKEDIN_CLIENT_SECRET"],
},
{
id: "x",
name: "X / Twitter",
emoji: "๐ฆ",
ready: !!e.X_API_KEY,
setupUrl: "https://developer.twitter.com/en/portal/projects-and-apps",
envVars: ["X_API_KEY", "X_API_SECRET"],
},
{
id: "facebook",
name: "Facebook",
emoji: "๐",
ready: !!e.FACEBOOK_APP_ID,
setupUrl: "https://developers.facebook.com/apps/create/",
envVars: ["FACEBOOK_APP_ID", "FACEBOOK_APP_SECRET"],
},
{
id: "instagram",
name: "Instagram",
emoji: "๐ธ",
ready: !!e.FACEBOOK_APP_ID,
setupUrl: "https://developers.facebook.com/apps/create/",
envVars: ["FACEBOOK_APP_ID", "FACEBOOK_APP_SECRET"],
note: "Uses same app as Facebook",
},
{
id: "threads",
name: "Threads",
emoji: "๐งต",
ready: !!e.THREADS_APP_ID,
setupUrl: "https://developers.facebook.com/apps/create/",
envVars: ["THREADS_APP_ID", "THREADS_APP_SECRET"],
},
{
id: "youtube",
name: "YouTube",
emoji: "โถ๏ธ",
ready: !!(e.GOOGLE_CLIENT_ID || e.YOUTUBE_CLIENT_ID),
setupUrl: "https://console.cloud.google.com/apis/credentials",
envVars: ["GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET"],
note: "Uses same app as Google Login",
},
{
id: "tiktok",
name: "TikTok",
emoji: "๐ต",
ready: !!e.TIKTOK_CLIENT_ID,
setupUrl: "https://developers.tiktok.com/",
envVars: ["TIKTOK_CLIENT_ID", "TIKTOK_CLIENT_SECRET"],
},
{
id: "reddit",
name: "Reddit",
emoji: "๐ค",
ready: !!e.REDDIT_CLIENT_ID,
setupUrl: "https://www.reddit.com/prefs/apps",
envVars: ["REDDIT_CLIENT_ID", "REDDIT_CLIENT_SECRET"],
},
{
id: "pinterest",
name: "Pinterest",
emoji: "๐",
ready: !!e.PINTEREST_CLIENT_ID,
setupUrl: "https://developers.pinterest.com/apps/",
envVars: ["PINTEREST_CLIENT_ID", "PINTEREST_CLIENT_SECRET"],
},
{
id: "discord",
name: "Discord",
emoji: "๐ฎ",
ready: !!e.DISCORD_CLIENT_ID,
setupUrl: "https://discord.com/developers/applications",
envVars: [
"DISCORD_CLIENT_ID",
"DISCORD_CLIENT_SECRET",
"DISCORD_BOT_TOKEN_ID",
],
},
{
id: "slack",
name: "Slack",
emoji: "๐ฌ",
ready: !!e.SLACK_ID,
setupUrl: "https://api.slack.com/apps?new_app=1",
envVars: ["SLACK_ID", "SLACK_SECRET", "SLACK_SIGNING_SECRET"],
},
];
}
// Returns detailed per-platform "direct connect" guide data (no OAuth / no env vars).
// These platforms connect entirely inside the Postiz UI โ no developer portal needed.
function getDirectPlatformDetails(postizUrl) {
const postizIntegrations = `${postizUrl}/integrations`;
return [
{
id: "bluesky",
name: "Bluesky",
emoji: "๐ฆ",
docsUrl: "https://bsky.social",
postizUrl: postizIntegrations,
fields: [
{ label: "Service", value: "https://bsky.social", hint: "Default for bsky.social users. Custom instance: use your instance URL." },
{ label: "Identifier", value: "yourname.bsky.social", hint: "Your full Bluesky handle." },
{ label: "Password", value: "App Password", hint: "NOT your login password โ generate a dedicated App Password in Bluesky settings." },
],
steps: [
{ title: "Create a Bluesky account", body: "Sign up at <a href=\"https://bsky.app\" target=\"_blank\" rel=\"noopener\">bsky.app</a> if you don't have one. Custom PDS users: use your own instance URL." },
{ title: "Generate an App Password", body: "In Bluesky โ <strong>Settings โ Privacy and Security โ App Passwords โ Add App Password</strong>. Name it <em>HuggingPost</em>. Copy the generated password โ it's shown only once." },
{ title: "Open Postiz Integrations", body: "Click the button below to go to Postiz โ click <strong>Connect</strong> next to Bluesky." },
{ title: "Fill in credentials", body: "<strong>Service:</strong> <code>https://bsky.social</code> (or your instance URL)<br><strong>Identifier:</strong> your full handle (e.g. <code>yourname.bsky.social</code>)<br><strong>Password:</strong> the App Password from Step 2 โ <em>not</em> your login password." },
{ title: "Click Connect", body: "Postiz authenticates and adds your Bluesky account. You can post immediately." },
],
},
{
id: "mastodon",
name: "Mastodon",
emoji: "๐",
docsUrl: "https://joinmastodon.org",
postizUrl: postizIntegrations,
fields: [
{ label: "Service", value: "https://mastodon.social", hint: "Your Mastodon instance URL (e.g. https://fosstodon.org)." },
{ label: "Identifier", value: "yourhandle", hint: "Your username without the @instance part." },
{ label: "Password", value: "Your password", hint: "Your Mastodon account password." },
],
steps: [
{ title: "Find your Mastodon instance URL", body: "Check your profile URL โ it's the domain part (e.g. <code>mastodon.social</code>, <code>fosstodon.org</code>)." },
{ title: "Open Postiz Integrations", body: "Click the button below โ click <strong>Connect</strong> next to Mastodon." },
{ title: "Fill in credentials", body: "<strong>Service:</strong> your full instance URL with https (e.g. <code>https://mastodon.social</code>)<br><strong>Identifier:</strong> your username (the part before @instance)<br><strong>Password:</strong> your account password." },
{ title: "Click Connect", body: "Postiz will authenticate via Mastodon's API and add your account." },
],
},
{
id: "telegram",
name: "Telegram",
emoji: "โ๏ธ",
docsUrl: "https://core.telegram.org/bots#how-do-i-create-a-bot",
postizUrl: postizIntegrations,
fields: [
{ label: "Bot Token", value: "123456:ABC-DEF...", hint: "From @BotFather. Format: number:string." },
],
steps: [
{ title: "Create a Telegram Bot", body: "Open Telegram โ message <strong>@BotFather</strong> โ send <code>/newbot</code> โ follow prompts โ copy the <strong>Bot Token</strong> (format: <code>123456789:ABC-...</code>)." },
{ title: "(Optional) Add bot to a channel", body: "To post to a Telegram channel: add your bot as an <strong>Admin</strong> of the channel with post permission." },
{ title: "Open Postiz Integrations", body: "Click the button below โ click <strong>Connect</strong> next to Telegram." },
{ title: "Enter Bot Token", body: "Paste your Bot Token from @BotFather. Click Connect." },
],
},
{
id: "devto",
name: "Dev.to",
emoji: "๐ป",
docsUrl: "https://dev.to/settings/extensions",
postizUrl: postizIntegrations,
fields: [
{ label: "API Key", value: "Your Dev.to API key", hint: "From dev.to โ Settings โ Extensions โ DEV API Keys." },
],
steps: [
{ title: "Log in to Dev.to", body: "Go to <a href=\"https://dev.to\" target=\"_blank\" rel=\"noopener\">dev.to</a> and sign in." },
{ title: "Generate an API key", body: "Go to <strong>Settings โ Extensions โ DEV API Keys</strong>. Enter a description (e.g. <em>HuggingPost</em>) and click <strong>Generate API Key</strong>. Copy the key." },
{ title: "Open Postiz Integrations", body: "Click the button below โ click <strong>Connect</strong> next to Dev.to." },
{ title: "Enter API key", body: "Paste your API key. Click Connect." },
],
},
{
id: "hashnode",
name: "Hashnode",
emoji: "๐ฐ",
docsUrl: "https://hashnode.com/settings/developer",
postizUrl: postizIntegrations,
fields: [
{ label: "Personal Access Token", value: "Your Hashnode token", hint: "From hashnode.com โ Account Settings โ Developer โ Personal Access Token." },
],
steps: [
{ title: "Log in to Hashnode", body: "Go to <a href=\"https://hashnode.com\" target=\"_blank\" rel=\"noopener\">hashnode.com</a> and sign in." },
{ title: "Generate a Personal Access Token", body: "Go to <strong>Account Settings โ Developer โ Personal Access Token โ Generate new token</strong>. Name it <em>HuggingPost</em>. Copy the token." },
{ title: "Open Postiz Integrations", body: "Click the button below โ click <strong>Connect</strong> next to Hashnode." },
{ title: "Enter token", body: "Paste your Personal Access Token. Click Connect." },
],
},
{
id: "nostr",
name: "Nostr",
emoji: "๐",
docsUrl: "https://nostr.how/en/get-started",
postizUrl: postizIntegrations,
fields: [
{ label: "Private Key", value: "nsec1...", hint: "Your Nostr private key in nsec (bech32) format." },
],
steps: [
{ title: "Get a Nostr keypair", body: "Use a Nostr client like <a href=\"https://snort.social\" target=\"_blank\" rel=\"noopener\">Snort</a> or <a href=\"https://primal.net\" target=\"_blank\" rel=\"noopener\">Primal</a> to create or export your keys. You need the <strong>private key</strong> in <code>nsec1...</code> format." },
{ title: "โ ๏ธ Security note", body: "Your private key controls your entire Nostr identity. Only enter it in trusted apps. HuggingPost is self-hosted โ your key stays in your container." },
{ title: "Open Postiz Integrations", body: "Click the button below โ click <strong>Connect</strong> next to Nostr." },
{ title: "Enter private key", body: "Paste your <code>nsec1...</code> private key. Click Connect." },
],
},
{
id: "lemmy",
name: "Lemmy",
emoji: "๐พ",
docsUrl: "https://join-lemmy.org",
postizUrl: postizIntegrations,
fields: [
{ label: "Instance", value: "https://lemmy.world", hint: "Your Lemmy instance URL." },
{ label: "Username", value: "yourhandle", hint: "Your Lemmy username." },
{ label: "Password", value: "Your password", hint: "Your Lemmy account password." },
],
steps: [
{ title: "Find your Lemmy instance", body: "You need the full URL of your Lemmy instance (e.g. <code>https://lemmy.world</code>, <code>https://lemmy.ml</code>). Find it at <a href=\"https://join-lemmy.org\" target=\"_blank\" rel=\"noopener\">join-lemmy.org</a>." },
{ title: "Open Postiz Integrations", body: "Click the button below โ click <strong>Connect</strong> next to Lemmy." },
{ title: "Fill in credentials", body: "<strong>Instance:</strong> your instance URL<br><strong>Username:</strong> your account username<br><strong>Password:</strong> your account password." },
{ title: "Click Connect", body: "Postiz authenticates via Lemmy's API." },
],
},
{
id: "warpcast",
name: "Warpcast",
emoji: "๐ฃ",
docsUrl: "https://docs.farcaster.xyz",
postizUrl: postizIntegrations,
fields: [
{ label: "FID", value: "12345", hint: "Your Farcaster user ID (numeric)." },
{ label: "Private Key", value: "0x...", hint: "Your Farcaster custody private key (hex, 0x-prefixed)." },
],
steps: [
{ title: "Find your FID", body: "Your Farcaster ID (FID) is a numeric value. In Warpcast โ Profile โ the number in your profile URL, or use <a href=\"https://www.farcaster.xyz\" target=\"_blank\" rel=\"noopener\">farcaster.xyz</a> to look it up." },
{ title: "Export your private key", body: "In Warpcast โ <strong>Settings โ Advanced โ Recovery phrase</strong>, or use a Farcaster tool to derive your custody private key. The key is in hex format (<code>0x...</code>)." },
{ title: "Open Postiz Integrations", body: "Click the button below โ click <strong>Connect</strong> next to Warpcast." },
{ title: "Enter FID and private key", body: "Paste your FID and private key. Click Connect." },
],
},
];
}
// Returns detailed per-platform OAuth setup guide data.
// publicUrl: "https://somratpro-huggingpost.hf.space" (no trailing slash)
function getOAuthPlatformDetails(publicUrl) {
const cb = (provider) => `${publicUrl}/integrations/social/${provider}`;
const e = process.env;
return [
{
id: "linkedin",
name: "LinkedIn",
emoji: "๐ผ",
setupUrl: "https://www.linkedin.com/developers/apps/new",
docsUrl:
"https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow",
callbackUrl: cb("linkedin"),
envVars: [
{
name: "LINKEDIN_CLIENT_ID",
desc: "Client ID",
set: !!e.LINKEDIN_CLIENT_ID,
},
{
name: "LINKEDIN_CLIENT_SECRET",
desc: "Client Secret",
set: !!e.LINKEDIN_CLIENT_SECRET,
},
],
steps: [
{
title: "Create a LinkedIn App",
body: "Visit the developer portal. Create a new app; set <strong>App type = Web</strong>.",
},
{
title: "Add OAuth redirect URL",
body: "In the <strong>Auth</strong> tab โ OAuth 2.0 settings, paste the callback URL below.",
},
{
title: "Enable products",
body: "Add <strong>Sign In with LinkedIn using OpenID Connect</strong> and <strong>Share on LinkedIn</strong> products.",
},
{
title: "Copy credentials",
body: "From the Auth tab, copy <strong>Client ID</strong> and <strong>Client Secret</strong>.",
},
{
title: "Add to Space secrets",
body: "Open your HF Space settings, add both env vars below, then restart the Space.",
},
],
},
{
id: "x",
name: "X / Twitter",
emoji: "๐ฆ",
setupUrl: "https://developer.twitter.com/en/portal/projects-and-apps",
docsUrl:
"https://developer.twitter.com/en/docs/authentication/oauth-1-0a",
callbackUrl: cb("x"),
envVars: [
{
name: "X_API_KEY",
desc: "API Key (Consumer Key)",
set: !!e.X_API_KEY,
},
{
name: "X_API_SECRET",
desc: "API Secret (Consumer Secret)",
set: !!e.X_API_SECRET,
},
],
steps: [
{
title: "Create an X Developer App",
body: 'Go to <a href="https://developer.twitter.com" target="_blank" rel="noopener">developer.twitter.com</a>. Apply for a developer account if needed. Create a new project + app.',
},
{
title: "Configure User Authentication Settings",
body: "On your app page โ <strong>User authentication settings โ Set up</strong>. Set ALL THREE of these, then click Save:<br><br><strong>1. App permissions:</strong> <strong>Read and write</strong> (default is Read-only โ must change this)<br><strong>2. Type of App:</strong> <strong>Native App</strong> (Public client) โ โ ๏ธ NOT Web App, Web App causes error code 32<br><strong>3. Callback URI:</strong> paste the Callback URL shown below. Website URL = your HF Space URL.<br><br>Save when done.",
},
{
title: "Regenerate Consumer Keys (required after saving settings)",
body: "Go to <strong>Keys & Tokens</strong> tab โ <strong>OAuth 1.0 Keys</strong> section โ click <strong>Regenerate</strong> next to Consumer Key.<br><br><strong>โ ๏ธ You must regenerate after changing User Auth Settings</strong> โ existing keys don't pick up new permissions.<br><br>The Regenerate popup shows BOTH values together โ copy them immediately:<br>โข <strong>API Key</strong> = your <strong>X_API_KEY</strong><br>โข <strong>API Key Secret</strong> = your <strong>X_API_SECRET</strong><br><br>โ ๏ธ Do NOT use Bearer Token, Access Token/Secret, or OAuth 2.0 Client ID/Secret.",
},
{
title: "Add to Space secrets and restart",
body: "Add <strong>X_API_KEY</strong> and <strong>X_API_SECRET</strong> to HF Space โ Settings โ Variables & Secrets. Then <strong>Restart the Space</strong> to load the new values.",
},
],
},
{
id: "facebook",
name: "Facebook",
emoji: "๐",
setupUrl: "https://developers.facebook.com/apps/create/",
docsUrl: "https://developers.facebook.com/docs/facebook-login/web",
callbackUrl: cb("facebook"),
envVars: [
{ name: "FACEBOOK_APP_ID", desc: "App ID", set: !!e.FACEBOOK_APP_ID },
{
name: "FACEBOOK_APP_SECRET",
desc: "App Secret",
set: !!e.FACEBOOK_APP_SECRET,
},
],
steps: [
{
title: "Create a Meta App",
body: "Go to Meta for Developers. Create a new app with use case <strong>Authenticate and request data from users</strong>.",
},
{
title: "Add Facebook Login product",
body: "In the app dashboard, click <strong>Add Product</strong> โ Facebook Login โ Web.",
},
{
title: "Add callback URL",
body: "In Facebook Login settings โ Valid OAuth Redirect URIs, paste the callback URL below.",
},
{
title: "Request permissions",
body: "Add <strong>pages_manage_posts</strong>, <strong>pages_read_engagement</strong>, <strong>publish_to_groups</strong> permissions.",
},
{
title: "Copy credentials",
body: "From <strong>App Settings โ Basic</strong>, copy App ID and App Secret.",
},
{
title: "Add to Space secrets",
body: "Add both env vars below to your HF Space settings, then restart.",
},
],
},
{
id: "instagram",
name: "Instagram",
emoji: "๐ธ",
setupUrl: "https://developers.facebook.com/apps/create/",
docsUrl: "https://developers.facebook.com/docs/instagram-api",
callbackUrl: cb("instagram"),
envVars: [
{
name: "FACEBOOK_APP_ID",
desc: "App ID (same as Facebook app)",
set: !!e.FACEBOOK_APP_ID,
},
{
name: "FACEBOOK_APP_SECRET",
desc: "App Secret (same as Facebook app)",
set: !!e.FACEBOOK_APP_SECRET,
},
],
steps: [
{
title: "Use the Facebook app",
body: "Instagram uses the same Meta app as Facebook โ configure Facebook first.",
},
{
title: "Add Instagram Graph API product",
body: "In your Meta app dashboard, click <strong>Add Product</strong> โ Instagram Graph API.",
},
{
title: "Connect an Instagram Business account",
body: "Your Instagram account must be a <strong>Professional (Business or Creator)</strong> account linked to a Facebook Page.",
},
{
title: "Add callback URL",
body: "In Instagram Login settings โ Valid OAuth Redirect URIs, paste the callback URL below.",
},
{
title: "No extra env vars needed",
body: "Instagram and Facebook share <code>FACEBOOK_APP_ID</code> and <code>FACEBOOK_APP_SECRET</code>.",
},
],
},
{
id: "threads",
name: "Threads",
emoji: "๐งต",
setupUrl: "https://developers.facebook.com/apps/create/",
docsUrl: "https://developers.facebook.com/docs/threads",
callbackUrl: cb("threads"),
envVars: [
{ name: "THREADS_APP_ID", desc: "App ID", set: !!e.THREADS_APP_ID },
{
name: "THREADS_APP_SECRET",
desc: "App Secret",
set: !!e.THREADS_APP_SECRET,
},
],
steps: [
{
title: "Create a Meta App",
body: "Create a Meta Developer app (separate from Facebook/Instagram if you prefer clean separation).",
},
{
title: "Add Threads API product",
body: "In the app dashboard, click <strong>Add Product</strong> โ Threads API.",
},
{
title: "Add callback URL",
body: "In Threads API settings โ Redirect URI, paste the callback URL below.",
},
{
title: "Copy credentials",
body: "From <strong>App Settings โ Basic</strong>, copy App ID and App Secret.",
},
{
title: "Add to Space secrets",
body: "Add both env vars below to your HF Space settings, then restart.",
},
],
},
{
id: "google",
name: "Google Login",
emoji: "๐ต",
setupUrl: "https://console.cloud.google.com/apis/credentials",
docsUrl: "https://developers.google.com/identity/protocols/oauth2",
callbackUrl: cb("google"),
envVars: [
{
name: "GOOGLE_CLIENT_ID",
desc: "OAuth 2.0 Client ID",
set: !!(e.GOOGLE_CLIENT_ID || e.YOUTUBE_CLIENT_ID),
},
{
name: "GOOGLE_CLIENT_SECRET",
desc: "OAuth 2.0 Client Secret",
set: !!(e.GOOGLE_CLIENT_SECRET || e.YOUTUBE_CLIENT_SECRET),
},
],
steps: [
{
title: "Create a Google Cloud project",
body: 'Go to <a href="https://console.cloud.google.com" target="_blank" rel="noopener">console.cloud.google.com</a>. Create a new project (or use an existing one).',
},
{
title: "Configure OAuth consent screen",
body: "In <strong>APIs & Services โ OAuth consent screen</strong>, set User Type to <strong>External</strong>. Fill app name, support email, developer email. Add scopes: <code>email</code>, <code>profile</code>, <code>openid</code>. Add your own Google account as a test user.",
},
{
title: "Create OAuth 2.0 credentials",
body: "In <strong>APIs & Services โ Credentials</strong>, click <strong>Create Credentials โ OAuth client ID</strong>. Set type to <strong>Web application</strong>. Name it <em>HuggingPost</em>.",
},
{
title: "Add callback URLs",
body: "Under <strong>Authorized redirect URIs</strong>, add the callback URL below. Also add the YouTube callback URL if you plan to connect YouTube โ it is shown on the YouTube tab.",
},
{
title: "Copy credentials",
body: "Copy the <strong>Client ID</strong> and <strong>Client Secret</strong> shown in the dialog.",
},
{
title: "Add to Space secrets",
body: "Add <code>GOOGLE_CLIENT_ID</code> and <code>GOOGLE_CLIENT_SECRET</code> to HF Space โ Settings โ Variables & Secrets. Restart the Space. <br><br><strong>๐ก These same credentials also power YouTube channel connections</strong> โ no separate YouTube OAuth app needed.",
},
],
},
{
id: "youtube",
name: "YouTube",
emoji: "โถ๏ธ",
setupUrl: "https://console.cloud.google.com/apis/credentials",
docsUrl: "https://developers.google.com/youtube/v3/guides/auth/server-side-web-apps",
callbackUrl: cb("youtube"),
envVars: [
{
name: "GOOGLE_CLIENT_ID",
desc: "OAuth 2.0 Client ID (same as Google Login)",
set: !!(e.GOOGLE_CLIENT_ID || e.YOUTUBE_CLIENT_ID),
},
{
name: "GOOGLE_CLIENT_SECRET",
desc: "OAuth 2.0 Client Secret (same as Google Login)",
set: !!(e.GOOGLE_CLIENT_SECRET || e.YOUTUBE_CLIENT_SECRET),
},
],
steps: [
{
title: "Already set up Google Login?",
body: "โ
<strong>Skip to Step 2.</strong> YouTube uses the same <code>GOOGLE_CLIENT_ID</code> and <code>GOOGLE_CLIENT_SECRET</code> โ no new OAuth app needed. Just enable the YouTube API and add the callback URL.",
},
{
title: "Enable YouTube Data API v3",
body: "In <a href=\"https://console.cloud.google.com/apis/library\" target=\"_blank\" rel=\"noopener\">APIs & Services โ Library</a>, search for <strong>YouTube Data API v3</strong> and click <strong>Enable</strong>.",
},
{
title: "Add YouTube callback URL to your OAuth client",
body: "In <strong>Credentials โ your OAuth client โ Edit</strong>, add the callback URL below to <strong>Authorized redirect URIs</strong>. Save.",
},
{
title: "Add YouTube scopes to consent screen",
body: "In <strong>OAuth consent screen โ Edit App โ Scopes</strong>, add <code>https://www.googleapis.com/auth/youtube.upload</code> and <code>https://www.googleapis.com/auth/youtube</code>.",
},
{
title: "First time setup only: add GOOGLE_* secrets",
body: "If you haven't done Google Login yet โ add <code>GOOGLE_CLIENT_ID</code> and <code>GOOGLE_CLIENT_SECRET</code> to HF Space secrets and restart. If Google Login is already working, no new secrets needed.",
},
],
},
{
id: "tiktok",
name: "TikTok",
emoji: "๐ต",
setupUrl: "https://developers.tiktok.com/",
docsUrl: "https://developers.tiktok.com/doc/login-kit-web",
callbackUrl: cb("tiktok"),
envVars: [
{
name: "TIKTOK_CLIENT_ID",
desc: "Client Key",
set: !!e.TIKTOK_CLIENT_ID,
},
{
name: "TIKTOK_CLIENT_SECRET",
desc: "Client Secret",
set: !!e.TIKTOK_CLIENT_SECRET,
},
],
steps: [
{
title: "Apply for TikTok Developer access",
body: "Sign in at developers.tiktok.com. Apply for developer access (may take 1-2 days).",
},
{
title: "Create an app",
body: "Create a new app. Set <strong>Platform: Web</strong>.",
},
{
title: "Add Login Kit",
body: "Add <strong>Login Kit</strong> product. This enables OAuth for your app.",
},
{
title: "Add callback URL",
body: "In Login Kit settings โ Redirect domain, add your HF Space hostname. In redirect URI, paste the callback URL below.",
},
{
title: "Request Content Posting API",
body: "Add <strong>Content Posting API</strong> product for posting videos/photos.",
},
{
title: "Copy credentials",
body: "From app overview, copy <strong>Client Key</strong> (as CLIENT_ID) and <strong>Client Secret</strong>.",
},
{
title: "Add to Space secrets",
body: "Add both env vars below to your HF Space settings, then restart.",
},
],
},
{
id: "reddit",
name: "Reddit",
emoji: "๐ค",
setupUrl: "https://www.reddit.com/prefs/apps",
docsUrl: "https://github.com/reddit-archive/reddit/wiki/OAuth2",
callbackUrl: cb("reddit"),
envVars: [
{
name: "REDDIT_CLIENT_ID",
desc: "Client ID (under app name)",
set: !!e.REDDIT_CLIENT_ID,
},
{
name: "REDDIT_CLIENT_SECRET",
desc: "Secret",
set: !!e.REDDIT_CLIENT_SECRET,
},
],
steps: [
{
title: "Go to Reddit App Preferences",
body: "Visit reddit.com/prefs/apps while logged in.",
},
{
title: "Create a new app",
body: "Click <strong>create another appโฆ</strong>. Set type to <strong>web app</strong>.",
},
{
title: "Add callback URL",
body: "In the <strong>redirect uri</strong> field, paste the callback URL below.",
},
{
title: "Copy credentials",
body: 'The Client ID is the string below the app name. Client Secret is labelled "secret".',
},
{
title: "Add to Space secrets",
body: "Add both env vars below to your HF Space settings, then restart.",
},
],
},
{
id: "pinterest",
name: "Pinterest",
emoji: "๐",
setupUrl: "https://developers.pinterest.com/apps/",
docsUrl:
"https://developers.pinterest.com/docs/getting-started/set-up-app/",
callbackUrl: cb("pinterest"),
envVars: [
{
name: "PINTEREST_CLIENT_ID",
desc: "App ID",
set: !!e.PINTEREST_CLIENT_ID,
},
{
name: "PINTEREST_CLIENT_SECRET",
desc: "App Secret",
set: !!e.PINTEREST_CLIENT_SECRET,
},
],
steps: [
{
title: "Create a Pinterest App",
body: "Go to Pinterest Developer Portal and create a new app.",
},
{
title: "Add redirect URI",
body: "In app settings, add the callback URL below as a redirect URI.",
},
{
title: "Request scopes",
body: "Request <strong>boards:read</strong>, <strong>pins:read</strong>, <strong>pins:write</strong> scopes.",
},
{
title: "Copy credentials",
body: "Copy App ID and App Secret from the app settings.",
},
{
title: "Add to Space secrets",
body: "Add both env vars below to your HF Space settings, then restart.",
},
],
},
{
id: "discord",
name: "Discord",
emoji: "๐ฎ",
setupUrl: "https://discord.com/developers/applications",
docsUrl: "https://discord.com/developers/docs/topics/oauth2",
callbackUrl: cb("discord"),
envVars: [
{
name: "DISCORD_CLIENT_ID",
desc: "Application ID",
set: !!e.DISCORD_CLIENT_ID,
},
{
name: "DISCORD_CLIENT_SECRET",
desc: "Client Secret",
set: !!e.DISCORD_CLIENT_SECRET,
},
{
name: "DISCORD_BOT_TOKEN_ID",
desc: "Bot Token",
set: !!e.DISCORD_BOT_TOKEN_ID,
},
],
steps: [
{
title: "Create a Discord Application",
body: "Go to Discord Developer Portal โ New Application.",
},
{
title: "Add redirect URL",
body: "In <strong>OAuth2 โ Redirects</strong>, paste the callback URL below.",
},
{
title: "Create a Bot",
body: "In the <strong>Bot</strong> section, create a bot. Enable <strong>Message Content Intent</strong>.",
},
{
title: "Copy credentials",
body: "Copy Client ID and Client Secret from OAuth2 tab. Copy Bot Token from Bot tab.",
},
{
title: "Add to Space secrets",
body: "Add all three env vars below to your HF Space settings, then restart.",
},
],
},
{
id: "slack",
name: "Slack",
emoji: "๐ฌ",
setupUrl: "https://api.slack.com/apps?new_app=1",
docsUrl: "https://api.slack.com/authentication/oauth-v2",
callbackUrl: cb("slack"),
envVars: [
{ name: "SLACK_ID", desc: "Client ID", set: !!e.SLACK_ID },
{ name: "SLACK_SECRET", desc: "Client Secret", set: !!e.SLACK_SECRET },
{
name: "SLACK_SIGNING_SECRET",
desc: "Signing Secret",
set: !!e.SLACK_SIGNING_SECRET,
},
],
steps: [
{
title: "Create a Slack App",
body: "Go to api.slack.com/apps โ Create New App โ From scratch.",
},
{
title: "Add OAuth redirect URL",
body: "In <strong>OAuth & Permissions โ Redirect URLs</strong>, paste the callback URL below.",
},
{
title: "Add Bot Token Scopes",
body: "Under Bot Token Scopes, add: <code>channels:join</code>, <code>chat:write</code>, <code>channels:read</code>, <code>groups:read</code>.",
},
{
title: "Install to workspace",
body: "Click <strong>Install to Workspace</strong> to generate tokens.",
},
{
title: "Copy credentials",
body: "From <strong>Basic Information</strong>: App Credentials has Client ID, Client Secret, Signing Secret.",
},
{
title: "Add to Space secrets",
body: "Add all three env vars below to your HF Space settings, then restart.",
},
],
},
];
}
function renderSetupPage() {
const spaceHost = process.env.SPACE_HOST || null;
const spaceId = process.env.SPACE_ID || null;
const publicUrl = spaceHost
? `https://${spaceHost}`
: "http://localhost:7860";
const postizUrl = publicUrl + "/app";
const settingsUrl = spaceId
? `https://huggingface.co/spaces/${spaceId}/settings`
: "https://huggingface.co/settings/spaces";
const platforms = getOAuthPlatformDetails(publicUrl);
const directPlatforms = getDirectPlatformDetails(postizUrl);
const configuredCount = platforms.filter((p) =>
p.envVars.every((v) => v.set),
).length;
const totalPanels = platforms.length + directPlatforms.length;
// โโ Build sidebar โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
const oauthSidebarItems = platforms.map((p, i) => {
const allSet = p.envVars.every((v) => v.set);
const anySet = p.envVars.some((v) => v.set);
const dot = allSet
? `<span class="dot dot-ok"></span>`
: anySet
? `<span class="dot dot-warn"></span>`
: `<span class="dot dot-off"></span>`;
return `<button class="plat-tab${i === 0 ? " active" : ""}" onclick="show(${i})" id="tab-${i}">
<span class="tab-emoji">${p.emoji}</span>
<span class="tab-name">${p.name}</span>
${dot}
</button>`;
}).join("");
const directSidebarItems = directPlatforms.map((p, i) => {
const idx = platforms.length + i;
return `<button class="plat-tab" onclick="show(${idx})" id="tab-${idx}">
<span class="tab-emoji">${p.emoji}</span>
<span class="tab-name">${p.name}</span>
<span class="dot dot-ok"></span>
</button>`;
}).join("");
// โโ Build OAuth panels โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
const oauthPanels = platforms.map((p, i) => {
const allSet = p.envVars.every((v) => v.set);
const anySet = p.envVars.some((v) => v.set);
const stepsList = p.steps.map((s, si) =>
`<div class="step">
<div class="step-num">${si + 1}</div>
<div>
<div class="step-title">${s.title}</div>
<div class="step-body">${s.body}</div>
</div>
</div>`
).join("");
const envRows = p.envVars.map((v) =>
`<div class="env-row">
<div class="env-info">
<code class="env-name">${v.name}</code>
<span class="env-desc">${v.desc}</span>
</div>
<div class="env-actions">
${v.set
? `<span class="badge ok">SET</span>`
: `<span class="badge off">NOT SET</span>`}
<button class="btn-copy" onclick="copy('${v.name}',this)">Copy name</button>
</div>
</div>`
).join("");
const banner = allSet
? `<div class="banner banner-ok">All credentials configured โ restart Space if you just added them.</div>`
: anySet
? `<div class="banner banner-warn">Partially configured โ add the missing env vars below.</div>`
: `<div class="banner banner-info">Not yet configured โ follow the steps below.</div>`;
return `<div class="panel${i === 0 ? " active" : ""}" id="panel-${i}">
<div class="panel-head">
<span class="panel-emoji">${p.emoji}</span>
<div>
<div class="panel-title">${p.name}</div>
<div class="panel-links">
<a href="${p.setupUrl}" target="_blank" rel="noopener">Open Developer Portal โ</a>
${p.docsUrl ? `<a href="${p.docsUrl}" target="_blank" rel="noopener">Official Docs โ</a>` : ""}
</div>
</div>
</div>
${banner}
<div class="section-label">Setup Steps</div>
<div class="steps-list">${stepsList}</div>
<div class="section-label">Callback URL
<span class="section-hint">Paste this in the developer portal when asked for "Redirect URI" or "Callback URL"</span>
</div>
<div class="copy-block">
<span class="copy-block-text">${p.callbackUrl}</span>
<button class="btn-copy btn-copy-white" onclick="copy('${p.callbackUrl}',this)">Copy</button>
</div>
<div class="section-label">Space Secrets to Add
<span class="section-hint">HF Space โ Settings โ Variables & Secrets</span>