mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Fix download
This commit is contained in:
parent
abcae14fa7
commit
0cec854f3b
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable no-console */
|
||||||
import { mkdir, writeFile, readFile } from 'node:fs/promises';
|
import { mkdir, writeFile, readFile } from 'node:fs/promises';
|
||||||
import { existsSync } from 'node:fs';
|
import { existsSync } from 'node:fs';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
@ -12,22 +13,23 @@ async function download(url: string, fileName: URL) {
|
|||||||
if (existsSync(fileName)) {
|
if (existsSync(fileName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line no-console
|
console.log('downloading', url);
|
||||||
console.log('downloading', fileName);
|
|
||||||
try {
|
try {
|
||||||
const image = await fetch(url);
|
const image = await fetch(url);
|
||||||
await writeFile(fileName, Buffer.from(await image.arrayBuffer()));
|
await writeFile(fileName, Buffer.from(await image.arrayBuffer()));
|
||||||
} catch {}
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchAvatars() {
|
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' }));
|
contributors = JSON.parse(await readFile(pathContributors, { encoding: 'utf-8' }));
|
||||||
await Promise.allSettled(
|
for (const name of contributors) {
|
||||||
contributors.map((name) =>
|
await download(`https://github.com/${name}.png?size=100`, getAvatarPath(name));
|
||||||
download(`https://github.com/${name}.png?size=100`, getAvatarPath(name))
|
}
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchAvatars();
|
fetchAvatars();
|
||||||
|
@ -23,9 +23,8 @@ async function fetchContributors() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
data = await response.json();
|
data = await response.json();
|
||||||
console.log(response.status, response.statusText);
|
|
||||||
console.log(data);
|
|
||||||
collaborators.push(...data.map((i) => i.login));
|
collaborators.push(...data.map((i) => i.login));
|
||||||
|
console.log(`Fetched page ${page}`);
|
||||||
page++;
|
page++;
|
||||||
} while (data.length === 100);
|
} while (data.length === 100);
|
||||||
return collaborators.filter((name) => !name.includes('[bot]'));
|
return collaborators.filter((name) => !name.includes('[bot]'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user