mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-24 10:16:06 +03:00
3acf87d5b6
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Shinigami92 <chrissi92@hotmail.de>
34 lines
907 B
TypeScript
34 lines
907 B
TypeScript
import { Buffer } from 'node:buffer'
|
|
import { join, resolve } from 'pathe'
|
|
import fs from 'fs-extra'
|
|
import { ofetch } from 'ofetch'
|
|
import { elkTeamMembers } from '../composables/about'
|
|
|
|
const avatarsDir = resolve('./public/avatars/')
|
|
|
|
const sizes = [60, 100]
|
|
|
|
async function download(url: string, fileName: string) {
|
|
if (fs.existsSync(fileName))
|
|
return
|
|
|
|
console.log('downloading', fileName)
|
|
try {
|
|
const image = await ofetch(url, { responseType: 'arrayBuffer' })
|
|
await fs.writeFile(fileName, Buffer.from(image))
|
|
}
|
|
catch (err) {
|
|
console.error(err)
|
|
}
|
|
}
|
|
|
|
async function fetchAvatars() {
|
|
await fs.ensureDir(avatarsDir)
|
|
|
|
await Promise.all(elkTeamMembers.reduce((acc, { github }) => {
|
|
acc.push(...sizes.map(s => download(`https://github.com/${github}.png?size=${s}`, join(avatarsDir, `${github}-${s}x${s}.png`))))
|
|
return acc
|
|
}, [] as Promise<void>[]))
|
|
}
|
|
|
|
fetchAvatars()
|