elk/scripts/avatars.ts

32 lines
872 B
TypeScript
Raw Normal View History

import { writeFile } from 'node:fs/promises'
import { join, resolve } from 'pathe'
import fs from 'fs-extra'
2023-03-20 18:11:04 +03:00
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) {
console.log('downloading', fileName)
try {
2023-03-20 18:11:04 +03:00
const image = await ofetch(url, { responseType: 'arrayBuffer' })
await writeFile(fileName, new Uint8Array(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()