Spaces:
Running
Running
feat: document platform architecture and enhance health server dashboard with OAuth setup guides
Browse files- context.md +107 -0
- health-server.js +476 -14
context.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## HuggingPost โ Full Context
|
| 2 |
+
|
| 3 |
+
**What it is:** Self-hosted Postiz v2.11.3 on Hugging Face Spaces. Social media scheduler with multi-channel posting (8 platforms work immediately, 12+ need OAuth setup).
|
| 4 |
+
|
| 5 |
+
**Architecture:**
|
| 6 |
+
|
| 7 |
+
- HF Space: single public port 7860 (health-server.js)
|
| 8 |
+
- Internal: nginx:5000 โ Postiz 4 PM2 procs (backend:3000, frontend:4200, workers, cron)
|
| 9 |
+
- Postgres + Redis internal
|
| 10 |
+
- Optional HF Dataset backup + sync loop
|
| 11 |
+
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
## Critical Issues Fixed
|
| 15 |
+
|
| 16 |
+
### 1. **Font build hang** (FIXED)
|
| 17 |
+
|
| 18 |
+
**Problem:** `next build` tried to fetch fonts from `fonts.gstatic.com` โ blocked/throttled on HF โ timeout โ build never completes โ container won't start.
|
| 19 |
+
|
| 20 |
+
**Solution:** Vendor 4 woff2 files + runtime patch in `start.sh`:
|
| 21 |
+
|
| 22 |
+
- Fonts: `vendor/fonts/PlusJakartaSans-{500,600}-{normal,italic}.woff2`
|
| 23 |
+
- Patch script: `vendor/patch-jakarta-font.js` rewrites two layout.tsx files from `next/font/google` to `next/font/local`
|
| 24 |
+
- Dockerfile Stage 2: copies fonts + patch script to `/opt/vendor/`
|
| 25 |
+
- start.sh: detects if patch not applied (old cached image), applies it before frontend build
|
| 26 |
+
|
| 27 |
+
**Commit:** `fd4cae0` (font patch)
|
| 28 |
+
|
| 29 |
+
### 2. **Blank white page at /app/** (FIXED)
|
| 30 |
+
|
| 31 |
+
**Root cause:** HF Spaces reverse proxy intercepts absolute redirects to its own hostname, resolves them server-side, returns 200 (not 307). Next.js redirects to `/auth` as `https://somratpro-huggingpost.hf.space/auth` โ proxy resolves it โ blank 200 page.
|
| 32 |
+
|
| 33 |
+
**Solution:** Two fixes in health-server.js + Dockerfile:
|
| 34 |
+
|
| 35 |
+
1. `rewriteLocation()` function converts absolute URLs (internal or SPACE_HOST) to relative `/app` paths so browser does the navigation
|
| 36 |
+
2. Nginx patch: fix `proxy_set_header X-Forwarded-Proto` to use HF proxy's value, not internal scheme
|
| 37 |
+
|
| 38 |
+
**Commits:** `57b8b04` (Location rewrite + nginx fix), `245f89d` (dashboard rewrite)
|
| 39 |
+
|
| 40 |
+
### 3. **OAuth `client_id=undefined`** (NOT A BUG)
|
| 41 |
+
|
| 42 |
+
LinkedIn/X/etc. OAuth links show `client_id=undefined` because env vars not set as HF Space secrets. User needs to create developer apps, add keys as secrets, restart. New dashboard guides users through this.
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
## Files Changed
|
| 47 |
+
|
| 48 |
+
### `Dockerfile`
|
| 49 |
+
|
| 50 |
+
- Stage 2, after postiz-builder COPY block: copy vendor fonts + patch script to `/opt/vendor/`
|
| 51 |
+
- nginx.conf patch:
|
| 52 |
+
- Add `/app` prefix when proxying to Next.js (line 160: `proxy_pass http://127.0.0.1:4200/app/;`)
|
| 53 |
+
- Fix x-forwarded-proto (line 162: use `$http_x_forwarded_proto` not `$scheme`)
|
| 54 |
+
|
| 55 |
+
### `start.sh`
|
| 56 |
+
|
| 57 |
+
- Lines 172โ187: Runtime font patch block
|
| 58 |
+
- If layout.tsx still has `next/font/google`, copy fonts, run patch script
|
| 59 |
+
- Idempotent โ skips if already patched
|
| 60 |
+
- Happens before `next build` so no network calls
|
| 61 |
+
|
| 62 |
+
### `health-server.js`
|
| 63 |
+
|
| 64 |
+
- `getSocialPlatforms()` (lines 51โ98): Array of all channels with ready status, setup URLs, env var names
|
| 65 |
+
- 8 "works immediately" (Bluesky, Mastodon, Telegram, Dev.to, Hashnode, Nostr, Lemmy, Warpcast)
|
| 66 |
+
- 12 "needs OAuth" (LinkedIn, X, Facebook, Instagram, Threads, YouTube, TikTok, Reddit, Pinterest, Discord, Slack)
|
| 67 |
+
- `rewriteLocation()` (lines 465โ505): Converts Location headers from Postiz
|
| 68 |
+
- Matches internal hosts (127.0.0.1, localhost) or SPACE_HOST
|
| 69 |
+
- Converts absolute URLs to `/app`-prefixed relative paths
|
| 70 |
+
- `renderDashboard()` (lines 176โ446): Complete rewrite
|
| 71 |
+
- Open Postiz button (disabled during boot, auto-activates when running)
|
| 72 |
+
- Status badges: Postiz, Uptime, Backup
|
| 73 |
+
- 4-step getting-started guide
|
| 74 |
+
- "Works immediately" section (8 platforms, collapsible)
|
| 75 |
+
- "Needs API keys" section (OAuth platforms, shows count configured, direct links to dev portals)
|
| 76 |
+
- "System & Backup" section (sync status, uptime monitor)
|
| 77 |
+
- Auto-refresh JS every 30s updates button state + badge states
|
| 78 |
+
- Deep-link to HF Space settings using SPACE_ID env var
|
| 79 |
+
|
| 80 |
+
**Vendor files (new):**
|
| 81 |
+
|
| 82 |
+
- `vendor/fonts/PlusJakartaSans-500-normal.woff2`, `-500-italic`, `-600-normal`, `-600-italic`
|
| 83 |
+
- `vendor/patch-jakarta-font.js`
|
| 84 |
+
|
| 85 |
+
---
|
| 86 |
+
|
| 87 |
+
## Current State
|
| 88 |
+
|
| 89 |
+
โ
**Working:**
|
| 90 |
+
|
| 91 |
+
- Font patch applied at build time (Dockerfile) + runtime fallback (start.sh)
|
| 92 |
+
- Next.js frontend builds successfully (~5 min first boot, <1 min with cached .next from backup)
|
| 93 |
+
- Blank `/app/` screen fixed โ middleware redirects work, browser navigates correctly
|
| 94 |
+
- nginx routes work: /api โ backend, /uploads โ fs, / โ frontend
|
| 95 |
+
- Dashboard shows platform status, guides users through setup
|
| 96 |
+
- HF_TOKEN secret no longer leaks in startup banner
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
## Deployment
|
| 101 |
+
|
| 102 |
+
All changes pushed to:
|
| 103 |
+
|
| 104 |
+
- GitHub: `somratpro/HuggingPost` (main branch)
|
| 105 |
+
- HF Space: `somratpro/HuggingPost` (auto-synced)
|
| 106 |
+
|
| 107 |
+
HF rebuilds automatically when Dockerfile or start.sh changes.
|
health-server.js
CHANGED
|
@@ -61,43 +61,495 @@ function getSocialPlatforms() {
|
|
| 61 |
{ name: "Dev.to", emoji: "๐ป", noOAuth: true, ready: true, note: "API key from dev.to settings" },
|
| 62 |
{ name: "Hashnode", emoji: "๐ฐ", noOAuth: true, ready: true, note: "API token from Hashnode settings" },
|
| 63 |
// โโ Needs OAuth app (env vars required) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 64 |
-
{ name: "LinkedIn", emoji: "๐ผ", ready: !!(e.LINKEDIN_CLIENT_ID && e.LINKEDIN_CLIENT_ID !== "undefined"),
|
| 65 |
setupUrl: "https://www.linkedin.com/developers/apps/new",
|
| 66 |
envVars: ["LINKEDIN_CLIENT_ID", "LINKEDIN_CLIENT_SECRET"] },
|
| 67 |
-
{ name: "X / Twitter",emoji: "๐ฆ", ready: !!(e.X_API_KEY),
|
| 68 |
setupUrl: "https://developer.twitter.com/en/portal/projects-and-apps",
|
| 69 |
envVars: ["X_API_KEY", "X_API_SECRET"] },
|
| 70 |
-
{ name: "Facebook", emoji: "๐", ready: !!(e.FACEBOOK_APP_ID),
|
| 71 |
setupUrl: "https://developers.facebook.com/apps/create/",
|
| 72 |
envVars: ["FACEBOOK_APP_ID", "FACEBOOK_APP_SECRET"] },
|
| 73 |
-
{ name: "Instagram", emoji: "๐ธ", ready: !!(e.FACEBOOK_APP_ID),
|
| 74 |
setupUrl: "https://developers.facebook.com/apps/create/",
|
| 75 |
envVars: ["FACEBOOK_APP_ID", "FACEBOOK_APP_SECRET"],
|
| 76 |
note: "Uses same app as Facebook" },
|
| 77 |
-
{ name: "Threads", emoji: "๐งต", ready: !!(e.THREADS_APP_ID),
|
| 78 |
setupUrl: "https://developers.facebook.com/apps/create/",
|
| 79 |
envVars: ["THREADS_APP_ID", "THREADS_APP_SECRET"] },
|
| 80 |
-
{ name: "YouTube", emoji: "โถ๏ธ", ready: !!(e.YOUTUBE_CLIENT_ID),
|
| 81 |
setupUrl: "https://console.cloud.google.com/apis/credentials",
|
| 82 |
envVars: ["YOUTUBE_CLIENT_ID", "YOUTUBE_CLIENT_SECRET"] },
|
| 83 |
-
{ name: "TikTok", emoji: "๐ต", ready: !!(e.TIKTOK_CLIENT_ID),
|
| 84 |
setupUrl: "https://developers.tiktok.com/",
|
| 85 |
envVars: ["TIKTOK_CLIENT_ID", "TIKTOK_CLIENT_SECRET"] },
|
| 86 |
-
{ name: "Reddit", emoji: "๐ค", ready: !!(e.REDDIT_CLIENT_ID),
|
| 87 |
setupUrl: "https://www.reddit.com/prefs/apps",
|
| 88 |
envVars: ["REDDIT_CLIENT_ID", "REDDIT_CLIENT_SECRET"] },
|
| 89 |
-
{ name: "Pinterest", emoji: "๐", ready: !!(e.PINTEREST_CLIENT_ID),
|
| 90 |
setupUrl: "https://developers.pinterest.com/apps/",
|
| 91 |
envVars: ["PINTEREST_CLIENT_ID", "PINTEREST_CLIENT_SECRET"] },
|
| 92 |
-
{ name: "Discord", emoji: "๐ฎ", ready: !!(e.DISCORD_CLIENT_ID),
|
| 93 |
setupUrl: "https://discord.com/developers/applications",
|
| 94 |
envVars: ["DISCORD_CLIENT_ID", "DISCORD_CLIENT_SECRET", "DISCORD_BOT_TOKEN_ID"] },
|
| 95 |
-
{ name: "Slack", emoji: "๐ฌ", ready: !!(e.SLACK_ID),
|
| 96 |
setupUrl: "https://api.slack.com/apps?new_app=1",
|
| 97 |
envVars: ["SLACK_ID", "SLACK_SECRET", "SLACK_SIGNING_SECRET"] },
|
| 98 |
];
|
| 99 |
}
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
// ============================================================================
|
| 102 |
// URL helpers
|
| 103 |
// ============================================================================
|
|
@@ -112,7 +564,9 @@ function isLocalRoute(pathname) {
|
|
| 112 |
pathname === "/health" ||
|
| 113 |
pathname === "/status" ||
|
| 114 |
pathname === "/" ||
|
| 115 |
-
pathname === ""
|
|
|
|
|
|
|
| 116 |
);
|
| 117 |
}
|
| 118 |
|
|
@@ -206,7 +660,7 @@ function renderDashboard(initialData) {
|
|
| 206 |
return `<div class="plat-row">
|
| 207 |
<span class="plat-icon" style="filter:grayscale(1);opacity:.5">${p.emoji}</span>
|
| 208 |
<span class="plat-name" style="color:var(--dim)">${p.name}</span>
|
| 209 |
-
<a class="setup-link" href="${p.
|
| 210 |
</div>`;
|
| 211 |
}).join("");
|
| 212 |
|
|
@@ -329,7 +783,7 @@ code{background:rgba(255,255,255,.08);padding:1px 5px;border-radius:4px;font-siz
|
|
| 329 |
<li>
|
| 330 |
<div>
|
| 331 |
<div class="s-title">Enable LinkedIn, X, YouTubeโฆ (optional)</div>
|
| 332 |
-
<div class="s-note">These require a free API key from each platform.
|
| 333 |
</div>
|
| 334 |
</li>
|
| 335 |
<li>
|
|
@@ -364,6 +818,7 @@ code{background:rgba(255,255,255,.08);padding:1px 5px;border-radius:4px;font-siz
|
|
| 364 |
<div class="sync-note" style="margin-top:10px">
|
| 365 |
After getting API keys: go to your <a href="https://huggingface.co/spaces/${process.env.SPACE_ID || "your-space"}/settings" target="_blank" style="color:#f472b6">Space Settings โ Variables & Secrets</a>, add the keys, then restart the Space.
|
| 366 |
</div>
|
|
|
|
| 367 |
</div>
|
| 368 |
</div>
|
| 369 |
|
|
@@ -602,6 +1057,13 @@ const server = http.createServer((req, res) => {
|
|
| 602 |
return;
|
| 603 |
}
|
| 604 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 605 |
// โโ Dashboard at exact / โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 606 |
if (pathname === "/" || pathname === "") {
|
| 607 |
void (async () => {
|
|
|
|
| 61 |
{ name: "Dev.to", emoji: "๐ป", noOAuth: true, ready: true, note: "API key from dev.to settings" },
|
| 62 |
{ name: "Hashnode", emoji: "๐ฐ", noOAuth: true, ready: true, note: "API token from Hashnode settings" },
|
| 63 |
// โโ Needs OAuth app (env vars required) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 64 |
+
{ id: "linkedin", name: "LinkedIn", emoji: "๐ผ", ready: !!(e.LINKEDIN_CLIENT_ID && e.LINKEDIN_CLIENT_ID !== "undefined"),
|
| 65 |
setupUrl: "https://www.linkedin.com/developers/apps/new",
|
| 66 |
envVars: ["LINKEDIN_CLIENT_ID", "LINKEDIN_CLIENT_SECRET"] },
|
| 67 |
+
{ id: "x", name: "X / Twitter",emoji: "๐ฆ", ready: !!(e.X_API_KEY),
|
| 68 |
setupUrl: "https://developer.twitter.com/en/portal/projects-and-apps",
|
| 69 |
envVars: ["X_API_KEY", "X_API_SECRET"] },
|
| 70 |
+
{ id: "facebook", name: "Facebook", emoji: "๐", ready: !!(e.FACEBOOK_APP_ID),
|
| 71 |
setupUrl: "https://developers.facebook.com/apps/create/",
|
| 72 |
envVars: ["FACEBOOK_APP_ID", "FACEBOOK_APP_SECRET"] },
|
| 73 |
+
{ id: "instagram", name: "Instagram", emoji: "๐ธ", ready: !!(e.FACEBOOK_APP_ID),
|
| 74 |
setupUrl: "https://developers.facebook.com/apps/create/",
|
| 75 |
envVars: ["FACEBOOK_APP_ID", "FACEBOOK_APP_SECRET"],
|
| 76 |
note: "Uses same app as Facebook" },
|
| 77 |
+
{ id: "threads", name: "Threads", emoji: "๐งต", ready: !!(e.THREADS_APP_ID),
|
| 78 |
setupUrl: "https://developers.facebook.com/apps/create/",
|
| 79 |
envVars: ["THREADS_APP_ID", "THREADS_APP_SECRET"] },
|
| 80 |
+
{ id: "youtube", name: "YouTube", emoji: "โถ๏ธ", ready: !!(e.YOUTUBE_CLIENT_ID),
|
| 81 |
setupUrl: "https://console.cloud.google.com/apis/credentials",
|
| 82 |
envVars: ["YOUTUBE_CLIENT_ID", "YOUTUBE_CLIENT_SECRET"] },
|
| 83 |
+
{ id: "tiktok", name: "TikTok", emoji: "๐ต", ready: !!(e.TIKTOK_CLIENT_ID),
|
| 84 |
setupUrl: "https://developers.tiktok.com/",
|
| 85 |
envVars: ["TIKTOK_CLIENT_ID", "TIKTOK_CLIENT_SECRET"] },
|
| 86 |
+
{ id: "reddit", name: "Reddit", emoji: "๐ค", ready: !!(e.REDDIT_CLIENT_ID),
|
| 87 |
setupUrl: "https://www.reddit.com/prefs/apps",
|
| 88 |
envVars: ["REDDIT_CLIENT_ID", "REDDIT_CLIENT_SECRET"] },
|
| 89 |
+
{ id: "pinterest", name: "Pinterest", emoji: "๐", ready: !!(e.PINTEREST_CLIENT_ID),
|
| 90 |
setupUrl: "https://developers.pinterest.com/apps/",
|
| 91 |
envVars: ["PINTEREST_CLIENT_ID", "PINTEREST_CLIENT_SECRET"] },
|
| 92 |
+
{ id: "discord", name: "Discord", emoji: "๐ฎ", ready: !!(e.DISCORD_CLIENT_ID),
|
| 93 |
setupUrl: "https://discord.com/developers/applications",
|
| 94 |
envVars: ["DISCORD_CLIENT_ID", "DISCORD_CLIENT_SECRET", "DISCORD_BOT_TOKEN_ID"] },
|
| 95 |
+
{ id: "slack", name: "Slack", emoji: "๐ฌ", ready: !!(e.SLACK_ID),
|
| 96 |
setupUrl: "https://api.slack.com/apps?new_app=1",
|
| 97 |
envVars: ["SLACK_ID", "SLACK_SECRET", "SLACK_SIGNING_SECRET"] },
|
| 98 |
];
|
| 99 |
}
|
| 100 |
|
| 101 |
+
// Returns detailed per-platform OAuth setup guide data.
|
| 102 |
+
// publicUrl: "https://somratpro-huggingpost.hf.space" (no trailing slash)
|
| 103 |
+
function getOAuthPlatformDetails(publicUrl) {
|
| 104 |
+
const cb = (provider) => `${publicUrl}/app/api/auth/connect/${provider}/callback`;
|
| 105 |
+
const e = process.env;
|
| 106 |
+
return [
|
| 107 |
+
{
|
| 108 |
+
id: "linkedin",
|
| 109 |
+
name: "LinkedIn",
|
| 110 |
+
emoji: "๐ผ",
|
| 111 |
+
setupUrl: "https://www.linkedin.com/developers/apps/new",
|
| 112 |
+
docsUrl: "https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow",
|
| 113 |
+
callbackUrl: cb("linkedin"),
|
| 114 |
+
envVars: [
|
| 115 |
+
{ name: "LINKEDIN_CLIENT_ID", desc: "Client ID", set: !!e.LINKEDIN_CLIENT_ID },
|
| 116 |
+
{ name: "LINKEDIN_CLIENT_SECRET", desc: "Client Secret", set: !!e.LINKEDIN_CLIENT_SECRET },
|
| 117 |
+
],
|
| 118 |
+
steps: [
|
| 119 |
+
{ title: "Create a LinkedIn App", body: 'Visit the developer portal. Create a new app; set <strong>App type = Web</strong>.' },
|
| 120 |
+
{ title: "Add OAuth redirect URL", body: 'In the <strong>Auth</strong> tab โ OAuth 2.0 settings, paste the callback URL below.' },
|
| 121 |
+
{ title: "Enable products", body: 'Add <strong>Sign In with LinkedIn using OpenID Connect</strong> and <strong>Share on LinkedIn</strong> products.' },
|
| 122 |
+
{ title: "Copy credentials", body: 'From the Auth tab, copy <strong>Client ID</strong> and <strong>Client Secret</strong>.' },
|
| 123 |
+
{ title: "Add to Space secrets", body: 'Open your HF Space settings, add both env vars below, then restart the Space.' },
|
| 124 |
+
],
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
id: "x",
|
| 128 |
+
name: "X / Twitter",
|
| 129 |
+
emoji: "๐ฆ",
|
| 130 |
+
setupUrl: "https://developer.twitter.com/en/portal/projects-and-apps",
|
| 131 |
+
docsUrl: "https://developer.twitter.com/en/docs/authentication/oauth-1-0a",
|
| 132 |
+
callbackUrl: cb("x"),
|
| 133 |
+
envVars: [
|
| 134 |
+
{ name: "X_API_KEY", desc: "API Key (Consumer Key)", set: !!e.X_API_KEY },
|
| 135 |
+
{ name: "X_API_SECRET", desc: "API Secret (Consumer Secret)", set: !!e.X_API_SECRET },
|
| 136 |
+
],
|
| 137 |
+
steps: [
|
| 138 |
+
{ title: "Create an X Developer App", body: 'Apply for a developer account if you don\'t have one. Create a new project + app.' },
|
| 139 |
+
{ title: "Enable OAuth 1.0a", body: 'In <strong>User authentication settings</strong>, enable <strong>OAuth 1.0a</strong>. Set type to <strong>Web App</strong>.' },
|
| 140 |
+
{ title: "Add callback URL", body: 'Under Callback URI / Redirect URL, paste the callback URL below.' },
|
| 141 |
+
{ title: "Set permissions", body: 'Set app permissions to <strong>Read and Write</strong> (or Read, Write and Direct Messages).' },
|
| 142 |
+
{ title: "Copy credentials", body: 'From Keys and Tokens tab, copy <strong>API Key</strong> and <strong>API Key Secret</strong>.' },
|
| 143 |
+
{ title: "Add to Space secrets", body: 'Add both env vars below to your HF Space settings, then restart.' },
|
| 144 |
+
],
|
| 145 |
+
},
|
| 146 |
+
{
|
| 147 |
+
id: "facebook",
|
| 148 |
+
name: "Facebook",
|
| 149 |
+
emoji: "๐",
|
| 150 |
+
setupUrl: "https://developers.facebook.com/apps/create/",
|
| 151 |
+
docsUrl: "https://developers.facebook.com/docs/facebook-login/web",
|
| 152 |
+
callbackUrl: cb("facebook"),
|
| 153 |
+
envVars: [
|
| 154 |
+
{ name: "FACEBOOK_APP_ID", desc: "App ID", set: !!e.FACEBOOK_APP_ID },
|
| 155 |
+
{ name: "FACEBOOK_APP_SECRET", desc: "App Secret", set: !!e.FACEBOOK_APP_SECRET },
|
| 156 |
+
],
|
| 157 |
+
steps: [
|
| 158 |
+
{ 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>.' },
|
| 159 |
+
{ title: "Add Facebook Login product", body: 'In the app dashboard, click <strong>Add Product</strong> โ Facebook Login โ Web.' },
|
| 160 |
+
{ title: "Add callback URL", body: 'In Facebook Login settings โ Valid OAuth Redirect URIs, paste the callback URL below.' },
|
| 161 |
+
{ title: "Request permissions", body: 'Add <strong>pages_manage_posts</strong>, <strong>pages_read_engagement</strong>, <strong>publish_to_groups</strong> permissions.' },
|
| 162 |
+
{ title: "Copy credentials", body: 'From <strong>App Settings โ Basic</strong>, copy App ID and App Secret.' },
|
| 163 |
+
{ title: "Add to Space secrets", body: 'Add both env vars below to your HF Space settings, then restart.' },
|
| 164 |
+
],
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
id: "instagram",
|
| 168 |
+
name: "Instagram",
|
| 169 |
+
emoji: "๐ธ",
|
| 170 |
+
setupUrl: "https://developers.facebook.com/apps/create/",
|
| 171 |
+
docsUrl: "https://developers.facebook.com/docs/instagram-api",
|
| 172 |
+
callbackUrl: cb("instagram"),
|
| 173 |
+
envVars: [
|
| 174 |
+
{ name: "FACEBOOK_APP_ID", desc: "App ID (same as Facebook app)", set: !!e.FACEBOOK_APP_ID },
|
| 175 |
+
{ name: "FACEBOOK_APP_SECRET", desc: "App Secret (same as Facebook app)", set: !!e.FACEBOOK_APP_SECRET },
|
| 176 |
+
],
|
| 177 |
+
steps: [
|
| 178 |
+
{ title: "Use the Facebook app", body: 'Instagram uses the same Meta app as Facebook โ configure Facebook first.' },
|
| 179 |
+
{ title: "Add Instagram Graph API product", body: 'In your Meta app dashboard, click <strong>Add Product</strong> โ Instagram Graph API.' },
|
| 180 |
+
{ 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.' },
|
| 181 |
+
{ title: "Add callback URL", body: 'In Instagram Login settings โ Valid OAuth Redirect URIs, paste the callback URL below.' },
|
| 182 |
+
{ title: "No extra env vars needed", body: 'Instagram and Facebook share <code>FACEBOOK_APP_ID</code> and <code>FACEBOOK_APP_SECRET</code>.' },
|
| 183 |
+
],
|
| 184 |
+
},
|
| 185 |
+
{
|
| 186 |
+
id: "threads",
|
| 187 |
+
name: "Threads",
|
| 188 |
+
emoji: "๐งต",
|
| 189 |
+
setupUrl: "https://developers.facebook.com/apps/create/",
|
| 190 |
+
docsUrl: "https://developers.facebook.com/docs/threads",
|
| 191 |
+
callbackUrl: cb("threads"),
|
| 192 |
+
envVars: [
|
| 193 |
+
{ name: "THREADS_APP_ID", desc: "App ID", set: !!e.THREADS_APP_ID },
|
| 194 |
+
{ name: "THREADS_APP_SECRET", desc: "App Secret", set: !!e.THREADS_APP_SECRET },
|
| 195 |
+
],
|
| 196 |
+
steps: [
|
| 197 |
+
{ title: "Create a Meta App", body: 'Create a Meta Developer app (separate from Facebook/Instagram if you prefer clean separation).' },
|
| 198 |
+
{ title: "Add Threads API product", body: 'In the app dashboard, click <strong>Add Product</strong> โ Threads API.' },
|
| 199 |
+
{ title: "Add callback URL", body: 'In Threads API settings โ Redirect URI, paste the callback URL below.' },
|
| 200 |
+
{ title: "Copy credentials", body: 'From <strong>App Settings โ Basic</strong>, copy App ID and App Secret.' },
|
| 201 |
+
{ title: "Add to Space secrets", body: 'Add both env vars below to your HF Space settings, then restart.' },
|
| 202 |
+
],
|
| 203 |
+
},
|
| 204 |
+
{
|
| 205 |
+
id: "youtube",
|
| 206 |
+
name: "YouTube",
|
| 207 |
+
emoji: "โถ๏ธ",
|
| 208 |
+
setupUrl: "https://console.cloud.google.com/apis/credentials",
|
| 209 |
+
docsUrl: "https://developers.google.com/youtube/v3/guides/auth/server-side-web-apps",
|
| 210 |
+
callbackUrl: cb("youtube"),
|
| 211 |
+
envVars: [
|
| 212 |
+
{ name: "YOUTUBE_CLIENT_ID", desc: "OAuth 2.0 Client ID", set: !!e.YOUTUBE_CLIENT_ID },
|
| 213 |
+
{ name: "YOUTUBE_CLIENT_SECRET", desc: "OAuth 2.0 Client Secret", set: !!e.YOUTUBE_CLIENT_SECRET },
|
| 214 |
+
],
|
| 215 |
+
steps: [
|
| 216 |
+
{ title: "Create a Google Cloud project", body: 'Go to Google Cloud Console. Create a new project (or use existing).' },
|
| 217 |
+
{ title: "Enable YouTube Data API v3", body: 'In APIs & Services โ Library, search for <strong>YouTube Data API v3</strong> and enable it.' },
|
| 218 |
+
{ title: "Create OAuth credentials", body: 'In APIs & Services โ Credentials, click <strong>Create Credentials โ OAuth client ID</strong>. Set type to <strong>Web application</strong>.' },
|
| 219 |
+
{ title: "Add callback URL", body: 'Under Authorized redirect URIs, paste the callback URL below.' },
|
| 220 |
+
{ title: "Configure OAuth consent screen", body: 'Set up consent screen with your app name. Add <strong>YouTube</strong> scopes.' },
|
| 221 |
+
{ title: "Copy credentials", body: 'Download or copy the <strong>Client ID</strong> and <strong>Client Secret</strong>.' },
|
| 222 |
+
{ title: "Add to Space secrets", body: 'Add both env vars below to your HF Space settings, then restart.' },
|
| 223 |
+
],
|
| 224 |
+
},
|
| 225 |
+
{
|
| 226 |
+
id: "tiktok",
|
| 227 |
+
name: "TikTok",
|
| 228 |
+
emoji: "๐ต",
|
| 229 |
+
setupUrl: "https://developers.tiktok.com/",
|
| 230 |
+
docsUrl: "https://developers.tiktok.com/doc/login-kit-web",
|
| 231 |
+
callbackUrl: cb("tiktok"),
|
| 232 |
+
envVars: [
|
| 233 |
+
{ name: "TIKTOK_CLIENT_ID", desc: "Client Key", set: !!e.TIKTOK_CLIENT_ID },
|
| 234 |
+
{ name: "TIKTOK_CLIENT_SECRET", desc: "Client Secret", set: !!e.TIKTOK_CLIENT_SECRET },
|
| 235 |
+
],
|
| 236 |
+
steps: [
|
| 237 |
+
{ title: "Apply for TikTok Developer access", body: 'Sign in at developers.tiktok.com. Apply for developer access (may take 1-2 days).' },
|
| 238 |
+
{ title: "Create an app", body: 'Create a new app. Set <strong>Platform: Web</strong>.' },
|
| 239 |
+
{ title: "Add Login Kit", body: 'Add <strong>Login Kit</strong> product. This enables OAuth for your app.' },
|
| 240 |
+
{ title: "Add callback URL", body: 'In Login Kit settings โ Redirect domain, add your HF Space hostname. In redirect URI, paste the callback URL below.' },
|
| 241 |
+
{ title: "Request Content Posting API", body: 'Add <strong>Content Posting API</strong> product for posting videos/photos.' },
|
| 242 |
+
{ title: "Copy credentials", body: 'From app overview, copy <strong>Client Key</strong> (as CLIENT_ID) and <strong>Client Secret</strong>.' },
|
| 243 |
+
{ title: "Add to Space secrets", body: 'Add both env vars below to your HF Space settings, then restart.' },
|
| 244 |
+
],
|
| 245 |
+
},
|
| 246 |
+
{
|
| 247 |
+
id: "reddit",
|
| 248 |
+
name: "Reddit",
|
| 249 |
+
emoji: "๐ค",
|
| 250 |
+
setupUrl: "https://www.reddit.com/prefs/apps",
|
| 251 |
+
docsUrl: "https://github.com/reddit-archive/reddit/wiki/OAuth2",
|
| 252 |
+
callbackUrl: cb("reddit"),
|
| 253 |
+
envVars: [
|
| 254 |
+
{ name: "REDDIT_CLIENT_ID", desc: "Client ID (under app name)", set: !!e.REDDIT_CLIENT_ID },
|
| 255 |
+
{ name: "REDDIT_CLIENT_SECRET", desc: "Secret", set: !!e.REDDIT_CLIENT_SECRET },
|
| 256 |
+
],
|
| 257 |
+
steps: [
|
| 258 |
+
{ title: "Go to Reddit App Preferences", body: 'Visit reddit.com/prefs/apps while logged in.' },
|
| 259 |
+
{ title: "Create a new app", body: 'Click <strong>create another appโฆ</strong>. Set type to <strong>web app</strong>.' },
|
| 260 |
+
{ title: "Add callback URL", body: 'In the <strong>redirect uri</strong> field, paste the callback URL below.' },
|
| 261 |
+
{ title: "Copy credentials", body: 'The Client ID is the string below the app name. Client Secret is labelled "secret".' },
|
| 262 |
+
{ title: "Add to Space secrets", body: 'Add both env vars below to your HF Space settings, then restart.' },
|
| 263 |
+
],
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
id: "pinterest",
|
| 267 |
+
name: "Pinterest",
|
| 268 |
+
emoji: "๐",
|
| 269 |
+
setupUrl: "https://developers.pinterest.com/apps/",
|
| 270 |
+
docsUrl: "https://developers.pinterest.com/docs/getting-started/set-up-app/",
|
| 271 |
+
callbackUrl: cb("pinterest"),
|
| 272 |
+
envVars: [
|
| 273 |
+
{ name: "PINTEREST_CLIENT_ID", desc: "App ID", set: !!e.PINTEREST_CLIENT_ID },
|
| 274 |
+
{ name: "PINTEREST_CLIENT_SECRET", desc: "App Secret", set: !!e.PINTEREST_CLIENT_SECRET },
|
| 275 |
+
],
|
| 276 |
+
steps: [
|
| 277 |
+
{ title: "Create a Pinterest App", body: 'Go to Pinterest Developer Portal and create a new app.' },
|
| 278 |
+
{ title: "Add redirect URI", body: 'In app settings, add the callback URL below as a redirect URI.' },
|
| 279 |
+
{ title: "Request scopes", body: 'Request <strong>boards:read</strong>, <strong>pins:read</strong>, <strong>pins:write</strong> scopes.' },
|
| 280 |
+
{ title: "Copy credentials", body: 'Copy App ID and App Secret from the app settings.' },
|
| 281 |
+
{ title: "Add to Space secrets", body: 'Add both env vars below to your HF Space settings, then restart.' },
|
| 282 |
+
],
|
| 283 |
+
},
|
| 284 |
+
{
|
| 285 |
+
id: "discord",
|
| 286 |
+
name: "Discord",
|
| 287 |
+
emoji: "๐ฎ",
|
| 288 |
+
setupUrl: "https://discord.com/developers/applications",
|
| 289 |
+
docsUrl: "https://discord.com/developers/docs/topics/oauth2",
|
| 290 |
+
callbackUrl: cb("discord"),
|
| 291 |
+
envVars: [
|
| 292 |
+
{ name: "DISCORD_CLIENT_ID", desc: "Application ID", set: !!e.DISCORD_CLIENT_ID },
|
| 293 |
+
{ name: "DISCORD_CLIENT_SECRET", desc: "Client Secret", set: !!e.DISCORD_CLIENT_SECRET },
|
| 294 |
+
{ name: "DISCORD_BOT_TOKEN_ID", desc: "Bot Token", set: !!e.DISCORD_BOT_TOKEN_ID },
|
| 295 |
+
],
|
| 296 |
+
steps: [
|
| 297 |
+
{ title: "Create a Discord Application", body: 'Go to Discord Developer Portal โ New Application.' },
|
| 298 |
+
{ title: "Add redirect URL", body: 'In <strong>OAuth2 โ Redirects</strong>, paste the callback URL below.' },
|
| 299 |
+
{ title: "Create a Bot", body: 'In the <strong>Bot</strong> section, create a bot. Enable <strong>Message Content Intent</strong>.' },
|
| 300 |
+
{ title: "Copy credentials", body: 'Copy Client ID and Client Secret from OAuth2 tab. Copy Bot Token from Bot tab.' },
|
| 301 |
+
{ title: "Add to Space secrets", body: 'Add all three env vars below to your HF Space settings, then restart.' },
|
| 302 |
+
],
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
id: "slack",
|
| 306 |
+
name: "Slack",
|
| 307 |
+
emoji: "๐ฌ",
|
| 308 |
+
setupUrl: "https://api.slack.com/apps?new_app=1",
|
| 309 |
+
docsUrl: "https://api.slack.com/authentication/oauth-v2",
|
| 310 |
+
callbackUrl: cb("slack"),
|
| 311 |
+
envVars: [
|
| 312 |
+
{ name: "SLACK_ID", desc: "Client ID", set: !!e.SLACK_ID },
|
| 313 |
+
{ name: "SLACK_SECRET", desc: "Client Secret", set: !!e.SLACK_SECRET },
|
| 314 |
+
{ name: "SLACK_SIGNING_SECRET", desc: "Signing Secret", set: !!e.SLACK_SIGNING_SECRET },
|
| 315 |
+
],
|
| 316 |
+
steps: [
|
| 317 |
+
{ title: "Create a Slack App", body: 'Go to api.slack.com/apps โ Create New App โ From scratch.' },
|
| 318 |
+
{ title: "Add OAuth redirect URL", body: 'In <strong>OAuth & Permissions โ Redirect URLs</strong>, paste the callback URL below.' },
|
| 319 |
+
{ 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>.' },
|
| 320 |
+
{ title: "Install to workspace", body: 'Click <strong>Install to Workspace</strong> to generate tokens.' },
|
| 321 |
+
{ title: "Copy credentials", body: 'From <strong>Basic Information</strong>: App Credentials has Client ID, Client Secret, Signing Secret.' },
|
| 322 |
+
{ title: "Add to Space secrets", body: 'Add all three env vars below to your HF Space settings, then restart.' },
|
| 323 |
+
],
|
| 324 |
+
},
|
| 325 |
+
];
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
function renderSetupPage() {
|
| 329 |
+
const spaceHost = process.env.SPACE_HOST || null;
|
| 330 |
+
const spaceId = process.env.SPACE_ID || null;
|
| 331 |
+
const publicUrl = spaceHost ? `https://${spaceHost}` : "http://localhost:7860";
|
| 332 |
+
const settingsUrl = spaceId
|
| 333 |
+
? `https://huggingface.co/spaces/${spaceId}/settings`
|
| 334 |
+
: "https://huggingface.co/settings/spaces";
|
| 335 |
+
|
| 336 |
+
const platforms = getOAuthPlatformDetails(publicUrl);
|
| 337 |
+
const configuredCount = platforms.filter(p => p.envVars.every(v => v.set)).length;
|
| 338 |
+
|
| 339 |
+
// Build sidebar items
|
| 340 |
+
const sidebarItems = platforms.map((p, i) => {
|
| 341 |
+
const allSet = p.envVars.every(v => v.set);
|
| 342 |
+
const anySet = p.envVars.some(v => v.set);
|
| 343 |
+
const indicator = allSet ? "โ
" : anySet ? "โ ๏ธ" : "โช";
|
| 344 |
+
return `<button class="plat-tab${i === 0 ? " active" : ""}" onclick="show(${i})" id="tab-${i}">
|
| 345 |
+
<span class="tab-emoji">${p.emoji}</span>
|
| 346 |
+
<span class="tab-name">${p.name}</span>
|
| 347 |
+
<span class="tab-indicator">${indicator}</span>
|
| 348 |
+
</button>`;
|
| 349 |
+
}).join("");
|
| 350 |
+
|
| 351 |
+
// Build detail panels
|
| 352 |
+
const panels = platforms.map((p, i) => {
|
| 353 |
+
const allSet = p.envVars.every(v => v.set);
|
| 354 |
+
|
| 355 |
+
const stepsList = p.steps.map((s, si) =>
|
| 356 |
+
`<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>`
|
| 357 |
+
).join("");
|
| 358 |
+
|
| 359 |
+
const envRows = p.envVars.map(v =>
|
| 360 |
+
`<div class="env-row">
|
| 361 |
+
<div class="env-info">
|
| 362 |
+
<code class="env-name">${v.name}</code>
|
| 363 |
+
<span class="env-desc">${v.desc}</span>
|
| 364 |
+
</div>
|
| 365 |
+
<div class="env-actions">
|
| 366 |
+
${v.set ? '<span class="badge badge-on" style="font-size:.7rem">Set โ</span>' : '<span class="badge badge-off" style="font-size:.7rem">Not set</span>'}
|
| 367 |
+
<button class="copy-btn" onclick="copy('${v.name}', this)">Copy name</button>
|
| 368 |
+
</div>
|
| 369 |
+
</div>`
|
| 370 |
+
).join("");
|
| 371 |
+
|
| 372 |
+
const statusBanner = allSet
|
| 373 |
+
? `<div class="status-banner banner-ok">โ
All credentials configured โ restart Space if you just added them.</div>`
|
| 374 |
+
: p.envVars.some(v => v.set)
|
| 375 |
+
? `<div class="status-banner banner-warn">โ ๏ธ Partially configured โ check missing env vars below.</div>`
|
| 376 |
+
: `<div class="status-banner banner-info">โน๏ธ Not yet configured โ follow the steps below.</div>`;
|
| 377 |
+
|
| 378 |
+
return `<div class="panel${i === 0 ? " active" : ""}" id="panel-${i}">
|
| 379 |
+
<div class="panel-header">
|
| 380 |
+
<span class="panel-emoji">${p.emoji}</span>
|
| 381 |
+
<div>
|
| 382 |
+
<h2 class="panel-title">${p.name}</h2>
|
| 383 |
+
<a class="portal-link" href="${p.setupUrl}" target="_blank" rel="noopener">Open ${p.name} Developer Portal โ</a>
|
| 384 |
+
${p.docsUrl ? `<a class="portal-link" href="${p.docsUrl}" target="_blank" rel="noopener" style="margin-left:12px">Docs โ</a>` : ""}
|
| 385 |
+
</div>
|
| 386 |
+
</div>
|
| 387 |
+
|
| 388 |
+
${statusBanner}
|
| 389 |
+
|
| 390 |
+
<h3 class="section-label">Setup Steps</h3>
|
| 391 |
+
<div class="steps-list">${stepsList}</div>
|
| 392 |
+
|
| 393 |
+
<h3 class="section-label">Callback URL</h3>
|
| 394 |
+
<div class="copy-block">
|
| 395 |
+
<span class="copy-block-text" id="cb-${i}">${p.callbackUrl}</span>
|
| 396 |
+
<button class="copy-btn copy-btn-primary" onclick="copy('${p.callbackUrl}', this)">Copy</button>
|
| 397 |
+
</div>
|
| 398 |
+
<p class="hint">Paste this URL wherever the developer portal asks for "Redirect URI", "Callback URL", or "OAuth Redirect URL".</p>
|
| 399 |
+
|
| 400 |
+
<h3 class="section-label">Space Secrets to Add</h3>
|
| 401 |
+
<div class="env-list">${envRows}</div>
|
| 402 |
+
<div class="settings-cta">
|
| 403 |
+
<a href="${settingsUrl}" target="_blank" rel="noopener" class="settings-btn">Open Space Settings โ Variables & Secrets</a>
|
| 404 |
+
<p class="hint">After adding secrets, click <strong>Restart Space</strong> for them to take effect.</p>
|
| 405 |
+
</div>
|
| 406 |
+
</div>`;
|
| 407 |
+
}).join("");
|
| 408 |
+
|
| 409 |
+
return `<!DOCTYPE html>
|
| 410 |
+
<html lang="en">
|
| 411 |
+
<head>
|
| 412 |
+
<meta charset="UTF-8">
|
| 413 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 414 |
+
<title>Platform Setup โ HuggingPost</title>
|
| 415 |
+
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600&display=swap" rel="stylesheet">
|
| 416 |
+
<style>
|
| 417 |
+
:root{--bg:#0f172a;--sidebar:#0d1829;--card:rgba(30,41,59,.75);--border:rgba(255,255,255,.08);--accent:linear-gradient(135deg,#ec4899,#8b5cf6);--text:#f8fafc;--dim:#94a3b8;--ok:#10b981;--warn:#f59e0b;--err:#ef4444;--blue:#3b82f6;--pink:#f472b6}
|
| 418 |
+
*{box-sizing:border-box;margin:0;padding:0}
|
| 419 |
+
body{font-family:'Outfit',sans-serif;background:var(--bg);color:var(--text);height:100vh;display:flex;flex-direction:column;overflow:hidden;
|
| 420 |
+
background-image:radial-gradient(at 0% 0%,rgba(236,72,153,.12) 0,transparent 50%),radial-gradient(at 100% 100%,rgba(139,92,246,.12) 0,transparent 50%)}
|
| 421 |
+
/* Top bar */
|
| 422 |
+
.topbar{display:flex;align-items:center;gap:16px;padding:14px 20px;border-bottom:1px solid var(--border);background:rgba(15,23,42,.8);backdrop-filter:blur(8px);flex-shrink:0}
|
| 423 |
+
.topbar a{color:var(--dim);text-decoration:none;font-size:.85rem;display:flex;align-items:center;gap:6px}
|
| 424 |
+
.topbar a:hover{color:var(--text)}
|
| 425 |
+
.topbar h1{font-size:1.1rem;font-weight:600;background:var(--accent);-webkit-background-clip:text;-webkit-text-fill-color:transparent}
|
| 426 |
+
.topbar-right{margin-left:auto;font-size:.8rem;color:var(--dim)}
|
| 427 |
+
/* Layout */
|
| 428 |
+
.layout{display:flex;flex:1;overflow:hidden}
|
| 429 |
+
/* Sidebar */
|
| 430 |
+
.sidebar{width:220px;flex-shrink:0;background:var(--sidebar);border-right:1px solid var(--border);overflow-y:auto;padding:12px 8px}
|
| 431 |
+
.sidebar-label{font-size:.65rem;text-transform:uppercase;color:var(--dim);letter-spacing:.1em;padding:4px 10px 8px}
|
| 432 |
+
.plat-tab{width:100%;background:none;border:none;color:var(--text);font:inherit;font-size:.88rem;display:flex;align-items:center;gap:8px;padding:9px 10px;border-radius:10px;cursor:pointer;text-align:left;transition:background .15s}
|
| 433 |
+
.plat-tab:hover{background:rgba(255,255,255,.05)}
|
| 434 |
+
.plat-tab.active{background:rgba(236,72,153,.12);color:var(--pink)}
|
| 435 |
+
.tab-emoji{font-size:1rem;width:22px;text-align:center;flex-shrink:0}
|
| 436 |
+
.tab-name{flex:1}
|
| 437 |
+
.tab-indicator{font-size:.8rem}
|
| 438 |
+
/* Main panel */
|
| 439 |
+
.main{flex:1;overflow-y:auto;padding:28px 32px}
|
| 440 |
+
.panel{display:none;animation:fadein .2s ease}
|
| 441 |
+
.panel.active{display:block}
|
| 442 |
+
@keyframes fadein{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}
|
| 443 |
+
.panel-header{display:flex;align-items:flex-start;gap:16px;margin-bottom:20px}
|
| 444 |
+
.panel-emoji{font-size:2.5rem;flex-shrink:0;margin-top:2px}
|
| 445 |
+
.panel-title{font-size:1.5rem;font-weight:600;margin-bottom:4px}
|
| 446 |
+
.portal-link{color:var(--pink);font-size:.82rem;text-decoration:none}
|
| 447 |
+
.portal-link:hover{text-decoration:underline}
|
| 448 |
+
/* Status banner */
|
| 449 |
+
.status-banner{padding:10px 14px;border-radius:10px;font-size:.85rem;margin-bottom:20px}
|
| 450 |
+
.banner-ok{background:rgba(16,185,129,.1);border:1px solid rgba(16,185,129,.2);color:#6ee7b7}
|
| 451 |
+
.banner-warn{background:rgba(245,158,11,.1);border:1px solid rgba(245,158,11,.2);color:#fcd34d}
|
| 452 |
+
.banner-info{background:rgba(59,130,246,.1);border:1px solid rgba(59,130,246,.2);color:#93c5fd}
|
| 453 |
+
/* Section labels */
|
| 454 |
+
.section-label{font-size:.7rem;text-transform:uppercase;letter-spacing:.1em;color:var(--dim);margin:20px 0 10px}
|
| 455 |
+
/* Steps */
|
| 456 |
+
.steps-list{display:flex;flex-direction:column;gap:2px}
|
| 457 |
+
.step{display:flex;gap:12px;padding:10px 12px;border-radius:10px;background:rgba(255,255,255,.03);border:1px solid var(--border)}
|
| 458 |
+
.step-num{width:24px;height:24px;border-radius:50%;background:var(--accent);color:#fff;font-size:.7rem;font-weight:700;display:flex;align-items:center;justify-content:center;flex-shrink:0;margin-top:1px}
|
| 459 |
+
.step-title{font-size:.88rem;font-weight:600;margin-bottom:3px}
|
| 460 |
+
.step-body{font-size:.82rem;color:var(--dim);line-height:1.55}
|
| 461 |
+
.step-body code{background:rgba(255,255,255,.1);padding:1px 5px;border-radius:4px;font-size:.8em;color:var(--text)}
|
| 462 |
+
/* Callback URL copy block */
|
| 463 |
+
.copy-block{display:flex;align-items:center;gap:10px;background:rgba(0,0,0,.3);border:1px solid var(--border);border-radius:10px;padding:12px 14px;margin-bottom:6px}
|
| 464 |
+
.copy-block-text{flex:1;font-size:.82rem;color:#c4b5fd;word-break:break-all;font-family:monospace}
|
| 465 |
+
/* Env vars */
|
| 466 |
+
.env-list{display:flex;flex-direction:column;gap:6px;margin-bottom:16px}
|
| 467 |
+
.env-row{display:flex;align-items:center;gap:10px;padding:10px 14px;background:rgba(255,255,255,.03);border:1px solid var(--border);border-radius:10px}
|
| 468 |
+
.env-info{flex:1;display:flex;flex-direction:column;gap:3px}
|
| 469 |
+
.env-name{font-size:.82rem;color:#c4b5fd;background:rgba(139,92,246,.1);padding:2px 7px;border-radius:5px;width:fit-content}
|
| 470 |
+
.env-desc{font-size:.76rem;color:var(--dim)}
|
| 471 |
+
.env-actions{display:flex;align-items:center;gap:8px;flex-shrink:0}
|
| 472 |
+
/* Buttons */
|
| 473 |
+
.copy-btn{background:rgba(255,255,255,.07);border:1px solid var(--border);color:var(--text);font:inherit;font-size:.75rem;padding:5px 10px;border-radius:7px;cursor:pointer;transition:background .15s;flex-shrink:0}
|
| 474 |
+
.copy-btn:hover{background:rgba(255,255,255,.12)}
|
| 475 |
+
.copy-btn.copied{background:rgba(16,185,129,.15);border-color:rgba(16,185,129,.3);color:var(--ok)}
|
| 476 |
+
.copy-btn-primary{background:rgba(236,72,153,.15);border-color:rgba(236,72,153,.3);color:var(--pink);font-size:.82rem;padding:6px 14px}
|
| 477 |
+
.copy-btn-primary:hover{background:rgba(236,72,153,.25)}
|
| 478 |
+
.settings-btn{display:inline-block;background:var(--accent);color:#fff;text-decoration:none;padding:11px 20px;border-radius:10px;font-size:.88rem;font-weight:600;transition:opacity .2s}
|
| 479 |
+
.settings-btn:hover{opacity:.85}
|
| 480 |
+
.settings-cta{margin-top:4px}
|
| 481 |
+
/* Badges */
|
| 482 |
+
.badge{display:inline-flex;align-items:center;gap:4px;padding:2px 8px;border-radius:20px;font-weight:600}
|
| 483 |
+
.badge-on{background:rgba(16,185,129,.12);color:var(--ok)}
|
| 484 |
+
.badge-off{background:rgba(239,68,68,.12);color:var(--err)}
|
| 485 |
+
/* Hint */
|
| 486 |
+
.hint{font-size:.78rem;color:var(--dim);margin-top:6px;line-height:1.5;margin-bottom:16px}
|
| 487 |
+
/* Mobile */
|
| 488 |
+
@media(max-width:700px){
|
| 489 |
+
body{overflow:auto;height:auto}
|
| 490 |
+
.layout{flex-direction:column;overflow:visible}
|
| 491 |
+
.sidebar{width:100%;border-right:none;border-bottom:1px solid var(--border);display:flex;flex-wrap:wrap;padding:8px;gap:4px}
|
| 492 |
+
.sidebar-label{display:none}
|
| 493 |
+
.plat-tab{width:auto;flex:0 0 auto;padding:6px 10px}
|
| 494 |
+
.tab-name{display:none}
|
| 495 |
+
.main{padding:16px}
|
| 496 |
+
}
|
| 497 |
+
</style>
|
| 498 |
+
</head>
|
| 499 |
+
<body>
|
| 500 |
+
<div class="topbar">
|
| 501 |
+
<a href="/">โ Dashboard</a>
|
| 502 |
+
<h1>Platform Setup Guide</h1>
|
| 503 |
+
<span class="topbar-right">${configuredCount}/${platforms.length} configured</span>
|
| 504 |
+
</div>
|
| 505 |
+
<div class="layout">
|
| 506 |
+
<nav class="sidebar">
|
| 507 |
+
<div class="sidebar-label">OAuth Platforms</div>
|
| 508 |
+
${sidebarItems}
|
| 509 |
+
</nav>
|
| 510 |
+
<main class="main">
|
| 511 |
+
${panels}
|
| 512 |
+
</main>
|
| 513 |
+
</div>
|
| 514 |
+
<script>
|
| 515 |
+
const PLATFORM_IDS = ${JSON.stringify(platforms.map(p => p.id))};
|
| 516 |
+
function show(i) {
|
| 517 |
+
document.querySelectorAll('.plat-tab').forEach((t,j) => t.classList.toggle('active', j===i));
|
| 518 |
+
document.querySelectorAll('.panel').forEach((p,j) => p.classList.toggle('active', j===i));
|
| 519 |
+
if (PLATFORM_IDS[i]) history.replaceState(null, '', '#' + PLATFORM_IDS[i]);
|
| 520 |
+
}
|
| 521 |
+
function copy(text, btn) {
|
| 522 |
+
navigator.clipboard.writeText(text).then(() => {
|
| 523 |
+
const orig = btn.textContent;
|
| 524 |
+
btn.textContent = 'Copied!';
|
| 525 |
+
btn.classList.add('copied');
|
| 526 |
+
setTimeout(() => { btn.textContent = orig; btn.classList.remove('copied'); }, 1800);
|
| 527 |
+
}).catch(() => {
|
| 528 |
+
// fallback for non-HTTPS
|
| 529 |
+
const ta = document.createElement('textarea');
|
| 530 |
+
ta.value = text; ta.style.position='fixed'; ta.style.opacity='0';
|
| 531 |
+
document.body.appendChild(ta); ta.select();
|
| 532 |
+
try { document.execCommand('copy'); } catch {}
|
| 533 |
+
document.body.removeChild(ta);
|
| 534 |
+
const orig = btn.textContent;
|
| 535 |
+
btn.textContent = 'Copied!';
|
| 536 |
+
btn.classList.add('copied');
|
| 537 |
+
setTimeout(() => { btn.textContent = orig; btn.classList.remove('copied'); }, 1800);
|
| 538 |
+
});
|
| 539 |
+
}
|
| 540 |
+
// Hash-based deep-linking: /setup#linkedin jumps to LinkedIn tab
|
| 541 |
+
(function() {
|
| 542 |
+
const hash = location.hash.replace('#','').toLowerCase();
|
| 543 |
+
if (hash) {
|
| 544 |
+
const idx = PLATFORM_IDS.indexOf(hash);
|
| 545 |
+
if (idx !== -1) show(idx);
|
| 546 |
+
}
|
| 547 |
+
})();
|
| 548 |
+
</script>
|
| 549 |
+
</body>
|
| 550 |
+
</html>`;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
// ============================================================================
|
| 554 |
// URL helpers
|
| 555 |
// ============================================================================
|
|
|
|
| 564 |
pathname === "/health" ||
|
| 565 |
pathname === "/status" ||
|
| 566 |
pathname === "/" ||
|
| 567 |
+
pathname === "" ||
|
| 568 |
+
pathname === "/setup" ||
|
| 569 |
+
pathname === "/setup/"
|
| 570 |
);
|
| 571 |
}
|
| 572 |
|
|
|
|
| 660 |
return `<div class="plat-row">
|
| 661 |
<span class="plat-icon" style="filter:grayscale(1);opacity:.5">${p.emoji}</span>
|
| 662 |
<span class="plat-name" style="color:var(--dim)">${p.name}</span>
|
| 663 |
+
<a class="setup-link" href="/setup#${p.id}" style="margin-right:4px">Setup guide โ</a>
|
| 664 |
</div>`;
|
| 665 |
}).join("");
|
| 666 |
|
|
|
|
| 783 |
<li>
|
| 784 |
<div>
|
| 785 |
<div class="s-title">Enable LinkedIn, X, YouTubeโฆ (optional)</div>
|
| 786 |
+
<div class="s-note">These require a free API key from each platform. Use the <a href="/setup" style="color:#f472b6">Setup Guide โ</a> for step-by-step instructions per platform, then add the keys as <a href="https://huggingface.co/spaces/${process.env.SPACE_ID || "your-space"}/settings" target="_blank">Space secrets</a>.</div>
|
| 787 |
</div>
|
| 788 |
</li>
|
| 789 |
<li>
|
|
|
|
| 818 |
<div class="sync-note" style="margin-top:10px">
|
| 819 |
After getting API keys: go to your <a href="https://huggingface.co/spaces/${process.env.SPACE_ID || "your-space"}/settings" target="_blank" style="color:#f472b6">Space Settings โ Variables & Secrets</a>, add the keys, then restart the Space.
|
| 820 |
</div>
|
| 821 |
+
<a href="/setup" style="display:inline-block;margin-top:12px;background:linear-gradient(135deg,#ec4899,#8b5cf6);color:#fff;text-decoration:none;padding:9px 18px;border-radius:10px;font-size:.84rem;font-weight:600">๐ Full Setup Guide โ</a>
|
| 822 |
</div>
|
| 823 |
</div>
|
| 824 |
|
|
|
|
| 1057 |
return;
|
| 1058 |
}
|
| 1059 |
|
| 1060 |
+
// โโ /setup โ OAuth platform setup wizard โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1061 |
+
if (pathname === "/setup" || pathname === "/setup/") {
|
| 1062 |
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
| 1063 |
+
res.end(renderSetupPage());
|
| 1064 |
+
return;
|
| 1065 |
+
}
|
| 1066 |
+
|
| 1067 |
// โโ Dashboard at exact / โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1068 |
if (pathname === "/" || pathname === "") {
|
| 1069 |
void (async () => {
|