Fix download

This commit is contained in:
Sidharth Vinod 2023-05-31 19:33:30 +05:30
parent abcae14fa7
commit 0cec854f3b
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD
2 changed files with 12 additions and 11 deletions

View File

@ -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';
@ -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();

View File

@ -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]'));