fix(auth+bugs): optional auth bypass, login routes, conform column name, panel metadata fields, login page: conform.js

This commit is contained in:
Zac Gaetano 2026-05-15 23:40:13 -04:00
parent f745122ef0
commit 47c113e6c3

View file

@ -1,5 +1,5 @@
import { join } from 'path'; import { join } from 'path';
import { unlink, writeFile, readFile } from 'fs/promises'; import { unlink, writeFile, mkdir } from 'fs/promises';
import { tmpdir } from 'os'; import { tmpdir } from 'os';
import { query } from '../db/client.js'; import { query } from '../db/client.js';
import { downloadFromS3, uploadToS3 } from '../s3/client.js'; import { downloadFromS3, uploadToS3 } from '../s3/client.js';
@ -11,36 +11,35 @@ const S3_BUCKET = process.env.S3_BUCKET || 'wild-dragon';
export const conformWorker = async (job) => { export const conformWorker = async (job) => {
const { jobId, edl, projectId, outputFormat } = job.data; const { jobId, edl, projectId, outputFormat } = job.data;
const tmpDir = tmpdir(); const tmpDir = tmpdir();
const edlPath = join(tmpDir, `edl-${job.id}.edl`); const edlPath = join(tmpDir, `edl-${job.id}.edl`);
const segmentsDir = join(tmpDir, `segments-${job.id}`); const segmentsDir = join(tmpDir, `segments-${job.id}`);
const segmentListPath = join(tmpDir, `segments-${job.id}.txt`); const segmentListPath = join(tmpDir, `segments-${job.id}.txt`);
const outputPath = join(tmpDir, `output-${job.id}.${outputFormat || 'mov'}`); const outputPath = join(tmpDir, `output-${job.id}.${outputFormat || 'mov'}`);
try { try {
// Write EDL to temp file // Write EDL to temp file
await writeFile(edlPath, edl, 'utf-8'); await writeFile(edlPath, edl, 'utf-8');
// Parse EDL // Parse EDL
job.updateProgress(5); await job.updateProgress(5);
console.log(`[conform] Parsing EDL for job ${jobId}`); console.log(`[conform] Parsing EDL for job ${jobId}`);
const edits = parseEDL(edl); const edits = parseEDL(edl);
// Create segments directory // Create temp directory for segment files
await writeFile(segmentsDir, ''); await mkdir(segmentsDir, { recursive: true });
// Process each edit
let processedEdits = 0; let processedEdits = 0;
const concatList = []; const concatList = [];
for (const edit of edits) { for (const edit of edits) {
job.updateProgress(Math.min(5 + (processedEdits / edits.length) * 50, 55)); await job.updateProgress(Math.min(5 + (processedEdits / edits.length) * 50, 55));
console.log(`[conform] Processing edit ${edit.editNumber}: ${edit.reelName}`); console.log(`[conform] Processing edit ${edit.editNumber}: ${edit.reelName}`);
// Look up asset by reel name // Look up asset by filename (the reel name in the EDL matches the clip filename)
const assetRes = await query( const assetRes = await query(
'SELECT id, original_s3_key FROM assets WHERE original_filename = $1 LIMIT 1', 'SELECT id, original_s3_key FROM assets WHERE filename = $1 LIMIT 1',
[edit.reelName] [edit.reelName]
); );
@ -49,78 +48,67 @@ export const conformWorker = async (job) => {
} }
const { id: assetId, original_s3_key: sourceKey } = assetRes.rows[0]; const { id: assetId, original_s3_key: sourceKey } = assetRes.rows[0];
const segmentInputPath = join(tmpDir, `segment-${edit.editNumber}-input`); const segmentInputPath = join(segmentsDir, `segment-${edit.editNumber}-src`);
const segmentOutputPath = join(tmpDir, `segment-${edit.editNumber}.mov`); const segmentOutputPath = join(segmentsDir, `segment-${edit.editNumber}.mov`);
// Download source from S3 // Download source clip from S3
console.log(`[conform] Downloading segment ${edit.editNumber} from S3`); console.log(`[conform] Downloading segment ${edit.editNumber} from S3 (${sourceKey})`);
await downloadFromS3(S3_BUCKET, sourceKey, segmentInputPath); await downloadFromS3(S3_BUCKET, sourceKey, segmentInputPath);
// Trim segment // Trim to EDL in/out points
console.log(`[conform] Trimming segment ${edit.editNumber}: ${edit.sourceIn} -> ${edit.sourceOut}`); console.log(`[conform] Trimming ${edit.editNumber}: ${edit.sourceIn}${edit.sourceOut}`);
await trimSegment( await trimSegment(segmentInputPath, segmentOutputPath, edit.sourceIn, edit.sourceOut);
segmentInputPath,
segmentOutputPath,
edit.sourceIn,
edit.sourceOut
);
concatList.push(segmentOutputPath); concatList.push(segmentOutputPath);
// Cleanup input // Remove the (large) source download immediately to conserve disk
await unlink(segmentInputPath).catch(() => {}); await unlink(segmentInputPath).catch(() => {});
processedEdits++; processedEdits++;
} }
// Create concat file // Write ffmpeg concat file
job.updateProgress(60); await job.updateProgress(60);
console.log(`[conform] Creating concat list for ${concatList.length} segments`); console.log(`[conform] Writing concat list for ${concatList.length} segments`);
const concatContent = concatList const concatContent = concatList.map(p => `file '${p}'`).join('\n');
.map(path => `file '${path}'`)
.join('\n');
await writeFile(segmentListPath, concatContent, 'utf-8'); await writeFile(segmentListPath, concatContent, 'utf-8');
// Concatenate all segments // Concatenate
job.updateProgress(70); await job.updateProgress(70);
console.log(`[conform] Concatenating segments for job ${jobId}`); console.log(`[conform] Concatenating segments for job ${jobId}`);
await concatSegments(segmentListPath, outputPath); await concatSegments(segmentListPath, outputPath);
// Upload final output to S3 // Upload to S3
job.updateProgress(85); await job.updateProgress(85);
const outputKey = `jobs/${jobId}/output.${outputFormat || 'mov'}`; const outputKey = `jobs/${jobId}/output.${outputFormat || 'mov'}`;
console.log(`[conform] Uploading final output to ${outputKey}`); console.log(`[conform] Uploading output to ${outputKey}`);
await uploadToS3(S3_BUCKET, outputKey, outputPath); await uploadToS3(S3_BUCKET, outputKey, outputPath);
// Update job record // Mark job complete
job.updateProgress(95); await job.updateProgress(95);
console.log(`[conform] Updating job record ${jobId}`);
await query( await query(
'UPDATE jobs SET status = $1, result = $2 WHERE id = $3', `UPDATE jobs SET status = 'complete', result = $1, updated_at = NOW() WHERE id = $2`,
['complete', JSON.stringify({ output_key: outputKey }), jobId] [JSON.stringify({ output_key: outputKey }), jobId]
); );
job.updateProgress(100); await job.updateProgress(100);
console.log(`[conform] Job ${jobId} conform complete`); console.log(`[conform] Job ${jobId} complete`);
return { jobId, outputKey }; return { jobId, outputKey };
} catch (error) { } catch (error) {
console.error(`[conform] Error processing job ${jobId}:`, error); console.error(`[conform] Error in job ${jobId}:`, error);
await query( await query(
'UPDATE jobs SET status = $1 WHERE id = $2', `UPDATE jobs SET status = 'failed', error = $1, updated_at = NOW() WHERE id = $2`,
['error', jobId] [error.message, jobId]
); );
throw error; throw error;
} finally { } finally {
// Cleanup // Best-effort cleanup of temp files
try { await Promise.all([
await Promise.all([ unlink(edlPath).catch(() => {}),
unlink(edlPath).catch(() => {}), unlink(segmentListPath).catch(() => {}),
unlink(segmentListPath).catch(() => {}), unlink(outputPath).catch(() => {}),
unlink(outputPath).catch(() => {}), ]);
]);
} catch (err) {
console.error(`[conform] Cleanup error for job ${job.id}:`, err);
}
} }
}; };