2023-04-11 18:04:22 +03:00
|
|
|
import { Buffer } from 'node:buffer'
|
2023-01-05 13:03:32 +03:00
|
|
|
import { join, resolve } from 'pathe'
|
|
|
|
import fs from 'fs-extra'
|
2023-03-20 18:11:04 +03:00
|
|
|
import { ofetch } from 'ofetch'
|
2023-01-30 13:58:18 +03:00
|
|
|
import { elkTeamMembers } from '../composables/about'
|
2023-01-05 13:03:32 +03:00
|
|
|
|
|
|
|
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 {
|
2023-03-20 18:11:04 +03:00
|
|
|
const image = await ofetch(url, { responseType: 'arrayBuffer' })
|
2023-01-05 13:03:32 +03:00
|
|
|
await fs.writeFile(fileName, Buffer.from(image))
|
|
|
|
}
|
2023-01-12 08:39:22 +03:00
|
|
|
catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2023-01-05 13:03:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchAvatars() {
|
|
|
|
await fs.ensureDir(avatarsDir)
|
|
|
|
|
2023-01-30 13:58:18 +03:00
|
|
|
await Promise.all(elkTeamMembers.reduce((acc, { github }) => {
|
2023-01-05 13:03:32 +03:00
|
|
|
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()
|