From 9434e12730b9e8c1f0a2314c5a3f67d391feb7f4 Mon Sep 17 00:00:00 2001 From: Edgard Lorraine Messias Date: Sat, 13 May 2023 18:10:02 -0300 Subject: [PATCH] Added update proto workflow (#61) --- .github/workflows/update-proto.yml | 52 ++++++++++++++++++++++++++++++ .gitignore | 3 +- proto-extract/index.js | 20 ++++++++++-- 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/update-proto.yml diff --git a/.github/workflows/update-proto.yml b/.github/workflows/update-proto.yml new file mode 100644 index 0000000..b969533 --- /dev/null +++ b/.github/workflows/update-proto.yml @@ -0,0 +1,52 @@ +name: Update WAProto + +on: + schedule: + - cron: "10 1 * * *" + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + update-proto: + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v3 + + - name: Install Node + uses: actions/setup-node@v3 + with: + node-version: 16.x + + - name: Install packages + run: | + yarn + yarn --pure-lockfile --cwd proto-extract + + - name: Update WAProto.proto + id: wa_proto_info + run: | + yarn --cwd proto-extract start > wa-logs.txt + WA_VERSION=$(cat wa-logs.txt | perl -n -e'/Current version\: (.+)/ && print $1') + WA_JS_URL=$(cat wa-logs.txt | perl -n -e'/Found source JS URL\: (.+)/ && print $1') + echo "wa_version=$WA_VERSION" >> $GITHUB_OUTPUT + echo "wa_js_url=$WA_JS_URL" >> $GITHUB_OUTPUT + + - name: GenerateStatics + run: yarn gen:protobuf + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + commit-message: "chore: updated proto to v${{steps.wa_proto_info.outputs.wa_version}}" + title: "Whatsapp v${{steps.wa_proto_info.outputs.wa_version}} proto change" + branch: "update-proto/stable" + delete-branch: true + labels: "update-proto" + body: "Automated changes\nFound source JS URL: ${{steps.wa_proto_info.outputs.wa_js_url}}\nCurrent version: v${{steps.wa_proto_info.outputs.wa_version}}" + add-paths: | + WAProto/* diff --git a/.gitignore b/.gitignore index a6ab698..e735d1e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ node_modules output.csv Proxy test.ts -TestData \ No newline at end of file +TestData +wa-logs.txt \ No newline at end of file diff --git a/proto-extract/index.js b/proto-extract/index.js index e8b13c7..81a73c0 100644 --- a/proto-extract/index.js +++ b/proto-extract/index.js @@ -34,9 +34,23 @@ async function findAppModules() { } } const baseURL = 'https://web.whatsapp.com' - const index = await request.get(baseURL, ua) - const bootstrapQRID = index.match(/src="\/app.([0-9a-z]{10,}).js"/)[1] - const bootstrapQRURL = baseURL + '/app.' + bootstrapQRID + '.js' + const serviceworker = await request.get(`${baseURL}/serviceworker.js`, ua) + + const versions = [...serviceworker.matchAll(/assets-manifest-([\d\.]+).json/g)].map(r => r[1]) + const version = versions[0] + + let bootstrapQRURL = '' + if(version) { + const asset = await request.get(`${baseURL}/assets-manifest-${version}.json`, ua) + const hashFiles = JSON.parse(asset) + const files = Object.keys(hashFiles) + const app = files.find(f => /^app\./.test(f)) + bootstrapQRURL = `${baseURL}/${app}` + } else { + const index = await request.get(baseURL, ua) + const bootstrapQRID = index.match(/src="\/app.([0-9a-z]{10,}).js"/)[1] + bootstrapQRURL = baseURL + '/app.' + bootstrapQRID + '.js' + } console.error('Found source JS URL:', bootstrapQRURL)