Update server.js
Browse files
server.js
CHANGED
|
@@ -92,9 +92,9 @@ async function getBundle() {
|
|
| 92 |
function getRenderConfig() {
|
| 93 |
return {
|
| 94 |
// Video settings
|
| 95 |
-
codec: 'h264'
|
| 96 |
-
pixelFormat: 'yuv420p'
|
| 97 |
-
imageFormat: 'jpeg'
|
| 98 |
jpegQuality: 80,
|
| 99 |
|
| 100 |
// Performance settings (optimized for L4: 8 vCPU, 30GB RAM)
|
|
@@ -135,19 +135,16 @@ function getRenderConfig() {
|
|
| 135 |
|
| 136 |
// Professional error handling
|
| 137 |
class RenderError extends Error {
|
| 138 |
-
constructor(message,
|
| 139 |
super(message);
|
| 140 |
this.name = 'RenderError';
|
|
|
|
|
|
|
| 141 |
}
|
| 142 |
}
|
| 143 |
|
| 144 |
// Main render function (professional pattern)
|
| 145 |
-
async function renderVideo(params
|
| 146 |
-
compositionId: string;
|
| 147 |
-
serveUrl: string;
|
| 148 |
-
inputProps: any;
|
| 149 |
-
onProgress?: (progress: number) => void;
|
| 150 |
-
}) {
|
| 151 |
const { compositionId, serveUrl, inputProps, onProgress } = params;
|
| 152 |
|
| 153 |
console.log('[Render] Selecting composition...');
|
|
@@ -182,7 +179,7 @@ async function renderVideo(params: {
|
|
| 182 |
if (percent !== lastProgress && percent % 5 === 0) {
|
| 183 |
console.log(`[Progress] ${percent}%`);
|
| 184 |
lastProgress = percent;
|
| 185 |
-
onProgress
|
| 186 |
}
|
| 187 |
},
|
| 188 |
...renderConfig,
|
|
@@ -204,9 +201,9 @@ async function renderVideo(params: {
|
|
| 204 |
return {
|
| 205 |
buffer: videoBuffer,
|
| 206 |
duration: renderTime,
|
| 207 |
-
fps,
|
| 208 |
-
fileSizeMB,
|
| 209 |
-
composition,
|
| 210 |
};
|
| 211 |
|
| 212 |
} catch (error) {
|
|
@@ -330,7 +327,7 @@ app.post('/render', async (req, res) => {
|
|
| 330 |
console.log(`[Job ${projectId}] Completed successfully`);
|
| 331 |
|
| 332 |
} catch (error) {
|
| 333 |
-
console.error(`[Job ${projectId}] Failed:`, error);
|
| 334 |
|
| 335 |
// Update with error
|
| 336 |
try {
|
|
@@ -344,7 +341,7 @@ app.post('/render', async (req, res) => {
|
|
| 344 |
})
|
| 345 |
.eq('id', projectId);
|
| 346 |
} catch (dbError) {
|
| 347 |
-
console.error(`[Job ${projectId}] Failed to update error status:`, dbError);
|
| 348 |
}
|
| 349 |
}
|
| 350 |
})();
|
|
@@ -512,7 +509,7 @@ app.get('/health', async (req, res) => {
|
|
| 512 |
|
| 513 |
res.json({
|
| 514 |
status: anyError ? 'degraded' : (allHealthy ? 'healthy' : 'warning'),
|
| 515 |
-
checks,
|
| 516 |
timestamp: new Date().toISOString()
|
| 517 |
});
|
| 518 |
});
|
|
|
|
| 92 |
function getRenderConfig() {
|
| 93 |
return {
|
| 94 |
// Video settings
|
| 95 |
+
codec: 'h264',
|
| 96 |
+
pixelFormat: 'yuv420p',
|
| 97 |
+
imageFormat: 'jpeg',
|
| 98 |
jpegQuality: 80,
|
| 99 |
|
| 100 |
// Performance settings (optimized for L4: 8 vCPU, 30GB RAM)
|
|
|
|
| 135 |
|
| 136 |
// Professional error handling
|
| 137 |
class RenderError extends Error {
|
| 138 |
+
constructor(message, code, details) {
|
| 139 |
super(message);
|
| 140 |
this.name = 'RenderError';
|
| 141 |
+
this.code = code;
|
| 142 |
+
this.details = details;
|
| 143 |
}
|
| 144 |
}
|
| 145 |
|
| 146 |
// Main render function (professional pattern)
|
| 147 |
+
async function renderVideo(params) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
const { compositionId, serveUrl, inputProps, onProgress } = params;
|
| 149 |
|
| 150 |
console.log('[Render] Selecting composition...');
|
|
|
|
| 179 |
if (percent !== lastProgress && percent % 5 === 0) {
|
| 180 |
console.log(`[Progress] ${percent}%`);
|
| 181 |
lastProgress = percent;
|
| 182 |
+
if (onProgress) onProgress(progress);
|
| 183 |
}
|
| 184 |
},
|
| 185 |
...renderConfig,
|
|
|
|
| 201 |
return {
|
| 202 |
buffer: videoBuffer,
|
| 203 |
duration: renderTime,
|
| 204 |
+
fps: fps,
|
| 205 |
+
fileSizeMB: fileSizeMB,
|
| 206 |
+
composition: composition,
|
| 207 |
};
|
| 208 |
|
| 209 |
} catch (error) {
|
|
|
|
| 327 |
console.log(`[Job ${projectId}] Completed successfully`);
|
| 328 |
|
| 329 |
} catch (error) {
|
| 330 |
+
console.error(`[Job ${projectId}] Failed:`, error.message);
|
| 331 |
|
| 332 |
// Update with error
|
| 333 |
try {
|
|
|
|
| 341 |
})
|
| 342 |
.eq('id', projectId);
|
| 343 |
} catch (dbError) {
|
| 344 |
+
console.error(`[Job ${projectId}] Failed to update error status:`, dbError.message);
|
| 345 |
}
|
| 346 |
}
|
| 347 |
})();
|
|
|
|
| 509 |
|
| 510 |
res.json({
|
| 511 |
status: anyError ? 'degraded' : (allHealthy ? 'healthy' : 'warning'),
|
| 512 |
+
checks: checks,
|
| 513 |
timestamp: new Date().toISOString()
|
| 514 |
});
|
| 515 |
});
|