Update server.js
Browse files
server.js
CHANGED
|
@@ -7,6 +7,7 @@ import { tmpdir } from 'os';
|
|
| 7 |
import { join, dirname } from 'path';
|
| 8 |
import { randomUUID } from 'crypto';
|
| 9 |
import { fileURLToPath } from 'url';
|
|
|
|
| 10 |
|
| 11 |
const __filename = fileURLToPath(import.meta.url);
|
| 12 |
const __dirname = dirname(__filename);
|
|
@@ -139,7 +140,8 @@ function getFFmpegOverride() {
|
|
| 139 |
|
| 140 |
// Calculate optimal concurrency based on CPU count
|
| 141 |
function getOptimalConcurrency() {
|
| 142 |
-
|
|
|
|
| 143 |
const cpuCount = os.cpus().length;
|
| 144 |
|
| 145 |
if (isGpuAvailable()) {
|
|
@@ -168,7 +170,6 @@ app.post('/render', async (req, res) => {
|
|
| 168 |
return res.status(500).json({ error: 'Renderer configuration error' });
|
| 169 |
}
|
| 170 |
|
| 171 |
-
const { createClient } = await import('@supabase/supabase-js');
|
| 172 |
const supabase = createClient(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY);
|
| 173 |
|
| 174 |
// 1. Respond immediately
|
|
@@ -202,7 +203,7 @@ app.post('/render', async (req, res) => {
|
|
| 202 |
await mkdir(tempDir, { recursive: true });
|
| 203 |
const outputPath = join(tempDir, 'output.mp4');
|
| 204 |
|
| 205 |
-
const concurrency = getOptimalConcurrency();
|
| 206 |
console.log(`[Concurrency] Using ${concurrency} threads`);
|
| 207 |
|
| 208 |
let lastLog = 0;
|
|
@@ -301,8 +302,8 @@ app.post('/render', async (req, res) => {
|
|
| 301 |
});
|
| 302 |
|
| 303 |
// Performance endpoint
|
| 304 |
-
app.get('/status', (req, res) => {
|
| 305 |
-
const os =
|
| 306 |
|
| 307 |
res.json({
|
| 308 |
status: 'running',
|
|
@@ -315,10 +316,13 @@ app.get('/status', (req, res) => {
|
|
| 315 |
});
|
| 316 |
});
|
| 317 |
|
| 318 |
-
app.listen(PORT, () => {
|
| 319 |
console.log(`🎬 FacelessFlowAI Renderer running on port ${PORT}`);
|
| 320 |
console.log(`⚡ GPU Available: ${isGpuAvailable() ? 'Yes' : 'No'}`);
|
| 321 |
-
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
// Environment check
|
| 324 |
console.log('--- Environment ---');
|
|
|
|
| 7 |
import { join, dirname } from 'path';
|
| 8 |
import { randomUUID } from 'crypto';
|
| 9 |
import { fileURLToPath } from 'url';
|
| 10 |
+
import { createClient } from '@supabase/supabase-js';
|
| 11 |
|
| 12 |
const __filename = fileURLToPath(import.meta.url);
|
| 13 |
const __dirname = dirname(__filename);
|
|
|
|
| 140 |
|
| 141 |
// Calculate optimal concurrency based on CPU count
|
| 142 |
function getOptimalConcurrency() {
|
| 143 |
+
// Dynamically import os module
|
| 144 |
+
const os = await import('os');
|
| 145 |
const cpuCount = os.cpus().length;
|
| 146 |
|
| 147 |
if (isGpuAvailable()) {
|
|
|
|
| 170 |
return res.status(500).json({ error: 'Renderer configuration error' });
|
| 171 |
}
|
| 172 |
|
|
|
|
| 173 |
const supabase = createClient(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY);
|
| 174 |
|
| 175 |
// 1. Respond immediately
|
|
|
|
| 203 |
await mkdir(tempDir, { recursive: true });
|
| 204 |
const outputPath = join(tempDir, 'output.mp4');
|
| 205 |
|
| 206 |
+
const concurrency = await getOptimalConcurrency();
|
| 207 |
console.log(`[Concurrency] Using ${concurrency} threads`);
|
| 208 |
|
| 209 |
let lastLog = 0;
|
|
|
|
| 302 |
});
|
| 303 |
|
| 304 |
// Performance endpoint
|
| 305 |
+
app.get('/status', async (req, res) => {
|
| 306 |
+
const os = await import('os');
|
| 307 |
|
| 308 |
res.json({
|
| 309 |
status: 'running',
|
|
|
|
| 316 |
});
|
| 317 |
});
|
| 318 |
|
| 319 |
+
app.listen(PORT, async () => {
|
| 320 |
console.log(`🎬 FacelessFlowAI Renderer running on port ${PORT}`);
|
| 321 |
console.log(`⚡ GPU Available: ${isGpuAvailable() ? 'Yes' : 'No'}`);
|
| 322 |
+
|
| 323 |
+
// Dynamically import os module
|
| 324 |
+
const os = await import('os');
|
| 325 |
+
console.log(`💾 Memory: ${Math.round(os.totalmem() / (1024 * 1024 * 1024))}GB`);
|
| 326 |
|
| 327 |
// Environment check
|
| 328 |
console.log('--- Environment ---');
|