tuna-agent 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -364,9 +364,28 @@ async function _doRender(ws, code, taskId, record, payload) {
|
|
|
364
364
|
localPath = destFile;
|
|
365
365
|
}
|
|
366
366
|
else if (scene.videoUrl.startsWith('http://') || scene.videoUrl.startsWith('https://')) {
|
|
367
|
-
// HTTP(S) URL —
|
|
368
|
-
|
|
369
|
-
|
|
367
|
+
// HTTP(S) URL — ask extension to fetch (needs auth cookies for Google Flow)
|
|
368
|
+
try {
|
|
369
|
+
const result = await flowCmd(ws, code, {
|
|
370
|
+
type: 'fetchVideoAsBase64',
|
|
371
|
+
videoUrl: scene.videoUrl,
|
|
372
|
+
}, 120000);
|
|
373
|
+
const base64 = result.base64;
|
|
374
|
+
if (!base64)
|
|
375
|
+
throw new Error('No base64 data returned from extension');
|
|
376
|
+
fs.writeFileSync(destFile, Buffer.from(base64, 'base64'));
|
|
377
|
+
localPath = destFile;
|
|
378
|
+
}
|
|
379
|
+
catch (err) {
|
|
380
|
+
// Fallback: try direct download (works for non-auth URLs)
|
|
381
|
+
try {
|
|
382
|
+
await _downloadFile(scene.videoUrl, destFile);
|
|
383
|
+
localPath = destFile;
|
|
384
|
+
}
|
|
385
|
+
catch (dlErr) {
|
|
386
|
+
throw new Error(`Failed to download video for scene ${scene.idx}: ${dlErr instanceof Error ? dlErr.message : dlErr}`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
370
389
|
}
|
|
371
390
|
else if (scene.videoUrl.startsWith('blob:')) {
|
|
372
391
|
// Blob URL — ask extension to extract via flow command
|
|
@@ -445,27 +464,40 @@ async function _doRender(ws, code, taskId, record, payload) {
|
|
|
445
464
|
console.warn(`[render] ffprobe failed (non-fatal):`, e);
|
|
446
465
|
}
|
|
447
466
|
_emitProgress(ws, code, record, 95, 'Finalizing...');
|
|
448
|
-
// ── Step 5:
|
|
467
|
+
// ── Step 5: Read video file as base64 for extension playback ─────────
|
|
468
|
+
let videoBase64;
|
|
469
|
+
try {
|
|
470
|
+
const buf = fs.readFileSync(outFile);
|
|
471
|
+
videoBase64 = buf.toString('base64');
|
|
472
|
+
console.log(`[render] Video base64 size: ${(videoBase64.length / 1024 / 1024).toFixed(1)}MB`);
|
|
473
|
+
}
|
|
474
|
+
catch (e) {
|
|
475
|
+
console.warn(`[render] Could not read video for base64 (non-fatal):`, e);
|
|
476
|
+
}
|
|
477
|
+
// ── Step 6: Update record and notify ─────────────────────────────────
|
|
449
478
|
record.status = 'rendered';
|
|
450
479
|
record.progress = 100;
|
|
451
480
|
record.outputPath = outFile;
|
|
452
481
|
upsertVideo(record);
|
|
453
482
|
ws.sendExtensionEvent(code, {
|
|
454
483
|
type: 'render_done',
|
|
455
|
-
|
|
484
|
+
videoBase64,
|
|
456
485
|
title: record.title,
|
|
457
486
|
duration,
|
|
458
487
|
resolution,
|
|
459
|
-
video: record,
|
|
460
488
|
});
|
|
461
489
|
ws.sendExtensionDone(code, taskId, {
|
|
462
490
|
ok: true,
|
|
463
491
|
videoId: record.id,
|
|
464
|
-
outputPath: outFile,
|
|
465
492
|
duration,
|
|
466
493
|
resolution,
|
|
467
494
|
});
|
|
468
495
|
console.log(`[render] Done: ${outFile} (${duration}, ${resolution})`);
|
|
496
|
+
// Clean up rendered video file — extension has the base64 data
|
|
497
|
+
try {
|
|
498
|
+
fs.unlinkSync(outFile);
|
|
499
|
+
}
|
|
500
|
+
catch { /* ignore */ }
|
|
469
501
|
}
|
|
470
502
|
catch (err) {
|
|
471
503
|
const error = err instanceof Error ? err.message : String(err);
|