From 7dacb23daf6a9f8b215891d12f44bdad3f639549 Mon Sep 17 00:00:00 2001 From: Oj Date: Tue, 12 Apr 2022 21:54:31 +0100 Subject: [PATCH] [CI > Win] Rewrite downloading in Node --- .github/workflows/nightly.yml | 5 ++--- scripts/downloadWin.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 scripts/downloadWin.js diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 7cf0db3..4d5e9a1 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -98,9 +98,8 @@ jobs: - name: Setup Client run: | # Download latest client from updater v2 and extract (manifest -> brotli -> tar) - wget "$(curl 'https://discord.com/api/updates/distributions/app/manifests/latest?channel=canary&platform=win&arch=x86' | python -c 'import json,sys;print(json.load(sys.stdin)["full"]["url"])')" - node -e "fs.writeFileSync('full.tar', zlib.brotliDecompressSync(fs.readFileSync('full.distro')))" - tar xf full.tar + node scripts/downloadWin.js + tar xf client.tar # Install OpenAsar build and setup environment sed -i "s/^\/\/ .*$/if \(name == 'discord_rpc'\) { console.log\('ABRA'\); process.exit\(\); }/" app.asar diff --git a/scripts/downloadWin.js b/scripts/downloadWin.js new file mode 100644 index 0000000..437c9bc --- /dev/null +++ b/scripts/downloadWin.js @@ -0,0 +1,35 @@ +const { get } = require('https'); +const zlib = require('zlib'); +const fs = require('fs'); + +console.log('getting manifest...'); + +get('https://discord.com/api/updates/distributions/app/manifests/latest?channel=canary&platform=win&arch=x86', async (res) => { + let body = ''; + res.on('data', (chunk) => { + body += chunk.toString(); + }); + + await new Promise((resolve) => res.on('end', resolve)); // Wait to read full body + + const manifest = JSON.parse(body); + const downloadUrl = manifest.full.url; + + console.log('downloading full.distro...'); + + get(downloadUrl, async (res) => { + let body = []; + res.on('data', (chunk) => { + body.push(chunk); + }); + + await new Promise((resolve) => res.on('end', resolve)); // Wait to read full body + + console.log('decompressing...'); + + body = Buffer.concat(data); + body = zlib.brotliDecompressSync(body); + + fs.writeFileSync('client.tar', body); + }); +}); \ No newline at end of file