-
Notifications
You must be signed in to change notification settings - Fork 10
/
proxy.ts
43 lines (36 loc) · 987 Bytes
/
proxy.ts
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
import fs from "fs";
interface Updater {
name: string;
notes: string;
pub_date: string;
platforms: {
[platform: string]: {
url: string;
signature: string;
};
};
}
// console.log(process.env);
const repo = process.env.GITHUB_REPOSITORY!;
async function getUpdater() {
const res = await fetch(
`https://github.com/${repo}/releases/latest/download/latest.json`
);
const content = await res.json();
const updater: Updater = content;
return updater;
}
function generateProxy(updater: Updater, proxy: string) {
const { platforms } = updater;
for (const plat in platforms) {
const raw_url = platforms[plat].url;
platforms[plat].url = `https://${proxy}/` + raw_url;
}
fs.writeFileSync(`${proxy}.proxy.json`, JSON.stringify(updater, null, 2));
}
async function generateProxies() {
const updater = await getUpdater();
generateProxy(updater, "mirror.ghproxy.com");
generateProxy(updater, "ghproxy.com");
}
generateProxies();