-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprocess.ts
More file actions
155 lines (148 loc) · 4.91 KB
/
process.ts
File metadata and controls
155 lines (148 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import * as fs from "node:fs";
interface Member {
name: string,
avatar?: string,
links: {
icon: "github" | "bilibili",
link: string
}[],
title: string
}
async function downloadGithubAvatar(username: string, name: string) {
try {
const url = `https://gh-proxy.top/https://api.github.com/users/${username}`
const res = await fetch(url)
if (!res.ok) return undefined
const json = await res.json()
const savePath = `src/public/avatars/${name}.png`
if (!json.avatar_url) return undefined
const avatarResponse = await fetch(json.avatar_url)
const buffer = await avatarResponse.arrayBuffer()
fs.writeFileSync(savePath, Buffer.from(buffer))
return `/avatars/${name}.png`
} catch (e) {
return undefined
}
}
async function downloadBiliBiliAvatar(uid: string, name: string) {
try {
const url = `https://space.bilibili.com/${uid}`
const res = await fetch(url)
if (!res.ok) return undefined
const text = await res.text()
const match = text.match(/<link rel="apple-touch-icon" href="(.*?)">/)
if (!match || !match[1]) return undefined
const avatarUrl = "https:" + match[1]
const avatarResponse = await fetch(avatarUrl)
if (!avatarResponse.ok) return undefined
const buffer = await avatarResponse.arrayBuffer()
const savePath = `src/public/avatars/${name}.png`
fs.writeFileSync(savePath, Buffer.from(buffer))
return `/avatars/${name}.png`
} catch (e) {
return undefined
}
}
const memberData = fs.readFileSync('member.txt', 'utf8')
const memberDatas = memberData.split('\n')
const contributors: Member[] = []
const supporters: Member[] = []
const promises: Promise<void>[] = []
let count = 0;
for (let member of memberDatas) {
const memberSplited = member.split(',')
const name = memberSplited[0]
const ghid = memberSplited[1]
const bilibili = memberSplited[3]
const developer = memberSplited[5]
const scholar = memberSplited[6]
const bugHunter = memberSplited[7]
const linguist = memberSplited[8]
const supporter = memberSplited[9]
const craftsman = memberSplited[10]
const addon = memberSplited[11]
const hasOther = developer === 'true'
|| scholar === 'true'
|| bugHunter === 'true'
|| linguist === 'true'
|| craftsman === 'true'
|| addon === 'true'
const member1: Member = {
name,
links: [],
title: ""
}
const thisPromises: Promise<void>[] = []
if (ghid) {
const avatarPromise = downloadGithubAvatar(ghid, name).then(avatar => {
if (avatar) {
member1.avatar = avatar
member1.links.push({
icon: "github",
link: `https://github.com/${ghid}`
})
}
})
promises.push(avatarPromise)
thisPromises.push(avatarPromise)
}
if (bilibili) {
const avatarPromise = downloadBiliBiliAvatar(bilibili, name).then(avatar => {
if (avatar) {
member1.avatar = avatar
member1.links.push({
icon: "bilibili",
link: `https://space.bilibili.com/${bilibili}`
})
}
})
promises.push(avatarPromise)
thisPromises.push(avatarPromise)
}
if (developer === 'true') {
if (member1.title) member1.title += " "
member1.title += "代码民工💻"
}
if (scholar === 'true') {
if (member1.title) member1.title += " "
member1.title += "智识学者📚"
}
if (bugHunter === 'true') {
if (member1.title) member1.title += " "
member1.title += "捉虫达人🐞"
}
if (linguist === 'true') {
if (member1.title) member1.title += " "
member1.title += "语言学家🌏"
}
if (craftsman === 'true') {
if (member1.title) member1.title += " "
member1.title += "像素工匠👾"
}
if (addon === 'true') {
if (member1.title) member1.title += " "
member1.title += "砧艺添材➕"
}
const thisPromise = Promise.all(thisPromises).then(() => {
if(!member1.avatar) {
member1.avatar = `/avatars/${name}.png`
}
if (supporter === 'true') {
const member2 = {
...member1
}
member2.title = "实力富哥💵"
supporters.push(member2)
}
if (hasOther) {
contributors.push(member1)
}
console.log(`${++count}/${memberDatas.length} ${member1.name} successed!`)
});
promises.push(thisPromise)
}
Promise.all(promises).then(() => {
console.log("done")
fs.writeFileSync('contributors.json', JSON.stringify(contributors, null, 2))
fs.writeFileSync('supporters.json', JSON.stringify(supporters, null, 2))
})