MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / downloadAndExtractArtifact

Function downloadAndExtractArtifact

scripts/studio-host-provider.mjs:534–563  ·  view source on GitHub ↗
(config, sessionId)

Source from the content-addressed store, hash-verified

532}
533
534async function downloadAndExtractArtifact(config, sessionId) {
535 const sessionRoot = path.join(config.workRoot, "sessions", sessionId);
536 await fs.promises.rm(sessionRoot, { force: true, recursive: true });
537 await fs.promises.mkdir(sessionRoot, { recursive: true });
538 const zipPath = path.join(sessionRoot, "artifact.zip");
539 const response = await fetch(
540 `${config.studioUrl}/api/actions/provider-hosts/sessions/${encodeURIComponent(sessionId)}/artifact`,
541 {
542 headers: {
543 "x-simdeck-host-id": config.hostId,
544 "x-simdeck-host-token": config.hostToken,
545 },
546 },
547 );
548 if (!response.ok) {
549 throw new Error(`Artifact download failed: HTTP ${response.status}`);
550 }
551 await fs.promises.writeFile(
552 zipPath,
553 Buffer.from(await response.arrayBuffer()),
554 );
555 await execFileAsync("ditto", ["-x", "-k", zipPath, sessionRoot], {
556 timeout: 120000,
557 });
558 const appPath = await findAppBundle(sessionRoot);
559 if (!appPath) {
560 throw new Error("Artifact did not contain an .app bundle.");
561 }
562 return appPath;
563}
564
565async function findAppBundle(root) {
566 const entries = await fs.promises.readdir(root, { withFileTypes: true });

Callers 1

allocateSessionFunction · 0.85

Calls 4

fetchFunction · 0.85
findAppBundleFunction · 0.85
fromMethod · 0.80
arrayBufferMethod · 0.80

Tested by

no test coverage detected