2024-09-11 23:37:59 +09:00
|
|
|
import { writeFile } from 'node:fs/promises'
|
2023-01-05 19:03:32 +09:00
|
|
|
import fs from 'fs-extra'
|
2023-03-21 00:11:04 +09:00
|
|
|
import { ofetch } from 'ofetch'
|
2024-09-30 17:11:56 +09:00
|
|
|
import { join, resolve } from 'pathe'
|
2023-01-30 19:58:18 +09:00
|
|
|
import { elkTeamMembers } from '../composables/about'
|
2023-01-05 19:03:32 +09:00
|
|
|
|
|
|
|
const avatarsDir = resolve('./public/avatars/')
|
|
|
|
|
|
|
|
const sizes = [60, 100]
|
|
|
|
|
|
|
|
async function download(url: string, fileName: string) {
|
|
|
|
console.log('downloading', fileName)
|
|
|
|
try {
|
2023-03-21 00:11:04 +09:00
|
|
|
const image = await ofetch(url, { responseType: 'arrayBuffer' })
|
2024-09-11 23:37:59 +09:00
|
|
|
await writeFile(fileName, new Uint8Array(image))
|
2023-01-05 19:03:32 +09:00
|
|
|
}
|
2023-01-12 14:39:22 +09:00
|
|
|
catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2023-01-05 19:03:32 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchAvatars() {
|
|
|
|
await fs.ensureDir(avatarsDir)
|
|
|
|
|
2023-01-30 19:58:18 +09:00
|
|
|
await Promise.all(elkTeamMembers.reduce((acc, { github }) => {
|
2023-01-05 19:03:32 +09: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()
|