1
0
mirror of https://github.com/elk-zone/elk synced 2024-11-30 15:58:06 +09:00
elk/scripts/avatars.ts
2023-01-30 11:58:58 +01:00

34 lines
873 B
TypeScript

import { join, resolve } from 'pathe'
import fs from 'fs-extra'
import { $fetch } from 'ohmyfetch'
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 $fetch(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()