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

Function fetchItemFile

packages/cli/src/registry/remote.ts:128–146  ·  view source on GitHub ↗
(
  item: RegistryItem,
  file: FileTarget,
  destPath: string,
  baseUrl: string = DEFAULT_REGISTRY_URL,
)

Source from the content-addressed store, hash-verified

126 * Caller is responsible for target-path validation (see installer.ts).
127 */
128export async function fetchItemFile(
129 item: RegistryItem,
130 file: FileTarget,
131 destPath: string,
132 baseUrl: string = DEFAULT_REGISTRY_URL,
133): Promise<void> {
134 // Reject path-traversal in file.path (mirrors assertSafeTarget for file.target).
135 if (/(^|[/\\])\.\.([/\\]|$)/.test(file.path)) {
136 throw new Error(`Unsafe file.path "${file.path}": path segments may not contain "..".`);
137 }
138 const url = `${baseUrl}/${ITEM_TYPE_DIRS[item.type]}/${item.name}/${file.path}`;
139 const res = await fetch(url, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
140 if (!res.ok) {
141 throw new Error(`File fetch failed: ${url} — HTTP ${res.status}`);
142 }
143 const buf = new Uint8Array(await res.arrayBuffer());
144 mkdirSync(dirname(destPath), { recursive: true });
145 writeFileSync(destPath, buf);
146}

Callers 1

installItemFunction · 0.85

Calls 1

fetchFunction · 0.85

Tested by

no test coverage detected