Skip to content

Commit

Permalink
Fix download
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed May 31, 2023
1 parent abcae14 commit 0cec854
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 11 additions & 9 deletions packages/mermaid/src/docs/.vitepress/scripts/fetch-avatars.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { mkdir, writeFile, readFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { fileURLToPath } from 'url';
Expand All @@ -12,22 +13,23 @@ async function download(url: string, fileName: URL) {
if (existsSync(fileName)) {
return;
}
// eslint-disable-next-line no-console
console.log('downloading', fileName);
console.log('downloading', url);
try {
const image = await fetch(url);
await writeFile(fileName, Buffer.from(await image.arrayBuffer()));
} catch {}
} catch (error) {
console.error(error);
}
}

async function fetchAvatars() {
await mkdir(fileURLToPath(new URL('..', getAvatarPath('none'))), { recursive: true });
await mkdir(fileURLToPath(new URL(getAvatarPath('none'))).replace('none.png', ''), {
recursive: true,
});
contributors = JSON.parse(await readFile(pathContributors, { encoding: 'utf-8' }));
await Promise.allSettled(
contributors.map((name) =>
download(`https://github.com/${name}.png?size=100`, getAvatarPath(name))
)
);
for (const name of contributors) {
await download(`https://github.com/${name}.png?size=100`, getAvatarPath(name));
}
}

fetchAvatars();
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ async function fetchContributors() {
}
);
data = await response.json();
console.log(response.status, response.statusText);
console.log(data);
collaborators.push(...data.map((i) => i.login));
console.log(`Fetched page ${page}`);
page++;
} while (data.length === 100);
return collaborators.filter((name) => !name.includes('[bot]'));
Expand Down

0 comments on commit 0cec854

Please sign in to comment.