( event: AssembleEvent, deps?: HandlerDeps, )
| 390 | // ── Assemble ──────────────────────────────────────────────────────────────── |
| 391 | |
| 392 | async function handleAssemble( |
| 393 | event: AssembleEvent, |
| 394 | deps?: HandlerDeps, |
| 395 | ): Promise<AssembleLambdaResult> { |
| 396 | const started = Date.now(); |
| 397 | const s3 = deps?.s3 ?? getS3Client(); |
| 398 | const primitive = deps?.primitives?.assemble ?? assemble; |
| 399 | |
| 400 | const work = mkdtempSync(join(deps?.tmpRoot ?? tmpdir(), "hf-lambda-assemble-")); |
| 401 | const planTar = join(work, "plan.tar.gz"); |
| 402 | const planDir = join(work, "plan"); |
| 403 | |
| 404 | try { |
| 405 | await downloadS3ObjectToFile(s3, event.PlanS3Uri, planTar); |
| 406 | await untarDirectory(planTar, planDir); |
| 407 | |
| 408 | const chunkPaths = await downloadChunkObjects(s3, event.ChunkS3Uris, work, event.Format); |
| 409 | |
| 410 | let audioPath: string | null = null; |
| 411 | if (event.AudioS3Uri) { |
| 412 | audioPath = join(planDir, "audio.aac"); |
| 413 | await downloadS3ObjectToFile(s3, event.AudioS3Uri, audioPath); |
| 414 | } |
| 415 | |
| 416 | const finalOutput = |
| 417 | event.Format === "png-sequence" |
| 418 | ? join(work, "output-frames") |
| 419 | : join(work, `output${formatExtension(event.Format)}`); |
| 420 | |
| 421 | const result: AssembleResult = await primitive(planDir, chunkPaths, audioPath, finalOutput, { |
| 422 | cfr: event.Cfr === true, |
| 423 | }); |
| 424 | |
| 425 | if (event.Format === "png-sequence") { |
| 426 | const tarball = `${finalOutput}.tar.gz`; |
| 427 | await tarDirectory(finalOutput, tarball); |
| 428 | await uploadFileToS3(s3, tarball, event.OutputS3Uri, "application/gzip"); |
| 429 | } else { |
| 430 | await uploadFileToS3(s3, finalOutput, event.OutputS3Uri); |
| 431 | } |
| 432 | |
| 433 | return { |
| 434 | Action: "assemble", |
| 435 | OutputS3Uri: event.OutputS3Uri, |
| 436 | FramesEncoded: result.framesEncoded, |
| 437 | FileSize: result.fileSize, |
| 438 | DurationMs: Date.now() - started, |
| 439 | }; |
| 440 | } finally { |
| 441 | cleanupDir(work); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | async function downloadChunkObjects( |
| 446 | s3: S3Client, |
no test coverage detected