Spaces:
Build error
Build error
Download server.js from irelandcuca/HumanMaster6HD: direct link, hf CLI and curl.
- Browser
- Download file 5.9 kB
-
https://huggingface.co/spaces/irelandcuca/HumanMaster6HD/resolve/main/server.js
- Command line
-
hf download hf://spaces/irelandcuca/HumanMaster6HD/server.js
-
curl -L -o server.js https://huggingface.co/spaces/irelandcuca/HumanMaster6HD/resolve/main/server.js
5.9 kB
| const express = require('express'); | |
| const { Pool } = require('pg'); | |
| const session = require('express-session'); | |
| const pgSession = require('connect-pg-simple')(session); | |
| require('dotenv').config(); | |
| const app = express(); | |
| const PORT = process.env.PORT || 7860; | |
| // 1. Initialize High-Performance Database Connection Pool | |
| const pool = new Pool({ | |
| connectionString: process.env.DATABASE_URL, | |
| ssl: { | |
| rejectUnauthorized: false, | |
| require: true | |
| } | |
| }); | |
| // 2. Attach Express Session management directly to your 'sessions' Table | |
| app.use(session({ | |
| store: new pgSession({ | |
| pool: pool, | |
| tableName: 'sessions' | |
| }), | |
| secret: process.env.SESSION_SECRET || 'ucdm_global_secure_secret_token', | |
| resave: false, | |
| saveUninitialized: false, | |
| cookie: { | |
| maxAge: 30 * 24 * 60 * 60 * 1000, | |
| secure: false, | |
| httpOnly: true | |
| } | |
| })); | |
| // 3. Visual Admin Dashboard Interface | |
| app.get('/', async (req, res) => { | |
| try { | |
| // Fetch real-time data counts from your tables | |
| const userCount = await pool.query('SELECT COUNT(*) FROM users'); | |
| const logCount = await pool.query('SELECT COUNT(*) FROM usage_logs'); | |
| res.send(` | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Audio AI Hub Admin Dashboard</title> | |
| <style> | |
| body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #0f172a; color: #f8fafc; padding: 40px; margin: 0; } | |
| .container { max-width: 800px; margin: 0 auto; } | |
| .header { border-bottom: 1px solid #334155; padding-bottom: 20px; margin-bottom: 30px; } | |
| h1 { color: #38bdf8; margin: 0; font-size: 28px; } | |
| .status-badge { background: #10b981; color: white; padding: 4px 10px; border-radius: 12px; font-size: 12px; display: inline-block; margin-top: 8px; } | |
| .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; } | |
| .card { background: #1e293b; border: 1px solid #334155; padding: 24px; border-radius: 12px; text-align: center; } | |
| .card-number { font-size: 48px; font-weight: bold; color: #f59e0b; margin: 10px 0; } | |
| .card-label { color: #94a3b8; font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px; } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <div class="header"> | |
| <h1>Audio AI Hub Administrative Engine</h1> | |
| <div class="status-badge">● Engine Operational</div> | |
| </div> | |
| <p>Your Docker core container is fully active on Hugging Face. The database proxy lines are listening for live app integrations.</p> | |
| <div class="grid"> | |
| <div class="card"> | |
| <div class="card-label">Registered App Users</div> | |
| <div class="card-number">${userCount.rows[0].count}</div> | |
| </div> | |
| <div class="card"> | |
| <div class="card-label">Total Files Processed</div> | |
| <div class="card-number">${logCount.rows[0].count}</div> | |
| </div> | |
| </div> | |
| </div> | |
| </body> | |
| </html> | |
| `); | |
| } catch (err) { | |
| res.status(500).send(` | |
| <body style="background: #0f172a; color: #f8fafc; padding: 40px; font-family: sans-serif;"> | |
| <h2 style="color: #ef4444;">Database Connection Error</h2> | |
| <p>Your server is running, but it cannot connect to your PostgreSQL database.</p> | |
| <code style="background: #1e293b; padding: 10px; display: block; border-radius: 6px; color: #f8fafc;">${err.message}</code> | |
| <p>Please double-check your <strong>DATABASE_URL</strong> secret in the Space settings tab.</p> | |
| </body> | |
| `); | |
| } | |
| }); | |
| // 4. API Core Schema Integration Routes | |
| // Create/Sync User | |
| app.post('/api/users', async (req, res) => { | |
| const { id, email, first_name, last_name, profile_image_url, tier } = req.body; | |
| try { | |
| const result = await pool.query( | |
| `INSERT INTO users (id, email, first_name, last_name, profile_image_url, tier) | |
| VALUES (COALESCE($1, gen_random_uuid()::text), $2, $3, $4, $5, COALESCE($6, 'free'::tier)) | |
| ON CONFLICT (email) DO UPDATE | |
| SET first_name = EXCLUDED.first_name, last_name = EXCLUDED.last_name, profile_image_url = EXCLUDED.profile_image_url, updated_at = now() | |
| RETURNING *`, | |
| [id, email, first_name, last_name, profile_image_url, tier] | |
| ); | |
| res.status(201).json({ success: true, user: result.rows[0] }); | |
| } catch (err) { res.status(500).json({ error: err.message }); } | |
| }); | |
| // Write Processed Usage Log | |
| app.post('/api/logs', async (req, res) => { | |
| const { user_id, preset, original_filename, output_filename } = req.body; | |
| try { | |
| const result = await pool.query( | |
| `INSERT INTO usage_logs (user_id, preset, original_filename, output_filename) | |
| VALUES ($1, $2, $3, $4) RETURNING *`, | |
| [user_id, preset, original_filename, output_filename] | |
| ); | |
| res.status(201).json({ success: true, log: result.rows[0] }); | |
| } catch (err) { res.status(500).json({ error: err.message }); } | |
| }); | |
| // Explicitly bind network listening parameters | |
| app.listen(PORT, '0.0.0.0', () => { | |
| console.log(`Server actively routing pipelines on port ${PORT}`); | |
| }); | |