MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / maybeUploadProject

Function maybeUploadProject

packages/cli/src/commands/cloud/render.ts:523–583  ·  view source on GitHub ↗
(
  client: HyperframesCloudClient,
  source: ProjectInputSource,
  asJson: boolean,
  idempotencyKey: string | undefined,
)

Source from the content-addressed store, hash-verified

521
522// fallow-ignore-next-line complexity
523async function maybeUploadProject(
524 client: HyperframesCloudClient,
525 source: ProjectInputSource,
526 asJson: boolean,
527 idempotencyKey: string | undefined,
528): Promise<UploadResult> {
529 if (source.kind === "asset_id") {
530 return { projectInput: { type: "asset_id", asset_id: source.assetId! } };
531 }
532 if (source.kind === "url") {
533 return { projectInput: { type: "url", url: source.url! } };
534 }
535
536 const project = resolveProject(source.dir);
537 if (!asJson) {
538 console.log("");
539 console.log(`${c.accent("◆")} Zipping ${c.accent(project.name)}`);
540 }
541 let archive;
542 try {
543 archive = createPublishArchive(project.dir);
544 } catch (err) {
545 const msg = normalizeErrorMessage(err);
546 errorBox("Zip failed", msg, "Check the project for missing files or unreadable permissions.");
547 process.exit(1);
548 }
549 if (!asJson) {
550 console.log(c.dim(` ${archive.fileCount} files · ${formatBytes(archive.buffer.byteLength)}`));
551 }
552
553 if (!asJson) {
554 console.log("");
555 console.log(`${c.accent("◆")} Uploading to /v3/assets`);
556 }
557 const uploadStart = Date.now();
558 let uploaded;
559 try {
560 uploaded = await client.uploadAsset({
561 file: archive.buffer,
562 filename: `${project.name}.zip`,
563 // Tag the multipart part with application/zip so downstream
564 // proxies / WAFs / any server-side path that keys off the
565 // part Content-Type see the intended type. The asset
566 // controller currently sniffs magic bytes from the file
567 // bytes, so this is belt-and-suspenders today; without it,
568 // FormData defaults to application/octet-stream.
569 mimeType: "application/zip",
570 idempotencyKey,
571 });
572 } catch (err) {
573 reportApiError("Upload failed", err);
574 }
575 if (!asJson) {
576 console.log(
577 c.dim(
578 ` asset_id: ${c.accent(uploaded.asset_id)} · ${formatDuration(Date.now() - uploadStart)}`,
579 ),
580 );

Callers 1

runFunction · 0.85

Calls 9

createPublishArchiveFunction · 0.85
errorBoxFunction · 0.85
reportApiErrorFunction · 0.85
nowMethod · 0.80
uploadAssetMethod · 0.80
resolveProjectFunction · 0.50
normalizeErrorMessageFunction · 0.50
formatBytesFunction · 0.50
formatDurationFunction · 0.50

Tested by

no test coverage detected