MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / downloadFileIfMissingOrChanged

Function downloadFileIfMissingOrChanged

quote/quote.ts:93–101  ·  view source on GitHub ↗
(url: string, filePath: string)

Source from the content-addressed store, hash-verified

91}
92
93
94async function fetchToBuffer(url: string): Promise<Buffer> {
95 const res = await fetch(url);
96 if (!res.ok) throw new Error(`GET ${url} failed: ${res.status} ${res.statusText}`);
97 return Buffer.from(await res.arrayBuffer());
98}
99
100async function downloadFileIfMissingOrChanged(url: string, filePath: string): Promise<void> {
101 fs.mkdirSync(path.dirname(filePath), { recursive: true });
102 const data = await fetchToBuffer(url);
103 if (fs.existsSync(filePath)) {
104 const old = fs.readFileSync(filePath);

Callers 1

ensureQuoteAssetsFunction · 0.85

Calls 1

fetchToBufferFunction · 0.85

Tested by

no test coverage detected