Skip to content

Commit

Permalink
multi updater proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Nov 25, 2023
1 parent c374763 commit ab5de33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ jobs:
fail_on_unmatched_files: true
token: ${{ secrets.MY_TOKEN }}
files: |
proxy.json
*.proxy.json
20 changes: 15 additions & 5 deletions proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,28 @@ interface Updater {

const repo = process.env.GITHUB_REPOSITORY!;

const generateProxy = async () => {
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://ghproxy.com/" + raw_url;
platforms[plat].url = `https://${proxy}/` + raw_url;
}
fs.writeFileSync("proxy.json", JSON.stringify(updater, null, 2));
};
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");
}

generateProxy();
generateProxies();

0 comments on commit ab5de33

Please sign in to comment.