fix: handle fetch streams safely
This commit is contained in:
@@ -34,6 +34,10 @@ export type SkillInstallResult = {
|
|||||||
code: number | null;
|
code: number | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isNodeReadableStream(value: unknown): value is NodeJS.ReadableStream {
|
||||||
|
return Boolean(value && typeof (value as NodeJS.ReadableStream).pipe === "function");
|
||||||
|
}
|
||||||
|
|
||||||
function summarizeInstallOutput(text: string): string | undefined {
|
function summarizeInstallOutput(text: string): string | undefined {
|
||||||
const raw = text.trim();
|
const raw = text.trim();
|
||||||
if (!raw) return undefined;
|
if (!raw) return undefined;
|
||||||
@@ -154,13 +158,10 @@ async function downloadFile(
|
|||||||
}
|
}
|
||||||
await ensureDir(path.dirname(destPath));
|
await ensureDir(path.dirname(destPath));
|
||||||
const file = fs.createWriteStream(destPath);
|
const file = fs.createWriteStream(destPath);
|
||||||
const body = response.body;
|
const body = response.body as unknown;
|
||||||
// Node's Readable.fromWeb expects the node:stream/web type; cast through unknown for DOM streams.
|
const readable = isNodeReadableStream(body)
|
||||||
const nodeStream = body as unknown as NodeJS.ReadableStream;
|
? body
|
||||||
const readable =
|
: Readable.fromWeb(body as NodeReadableStream);
|
||||||
typeof nodeStream.pipe === "function"
|
|
||||||
? nodeStream
|
|
||||||
: Readable.fromWeb(body as unknown as NodeReadableStream);
|
|
||||||
await pipeline(readable, file);
|
await pipeline(readable, file);
|
||||||
const stat = await fs.promises.stat(destPath);
|
const stat = await fs.promises.stat(destPath);
|
||||||
return { bytes: stat.size };
|
return { bytes: stat.size };
|
||||||
|
|||||||
Reference in New Issue
Block a user