const jwt = require('jsonwebtoken'); const http = require('http'); const { execSync } = require('child_process'); const fs = require('fs'); const KEY = 'user:1022172:47'; const SECRET = 'da4e4367277668aa6e048b0a04d1a417ba8bad630f4ac37ccdcea064a9de151e'; const ADDON_ID = 'verstak-bridge@verstak.app'; function makeJWT() { return jwt.sign({ iss: KEY, jti: Math.random().toString(36).slice(2), iat: Math.floor(Date.now() / 1000), exp: Math.floor(Date.now() / 1000) + 300 }, SECRET); } function proxyReq(method, url, headers) { return new Promise((resolve, reject) => { const u = new URL(url); const req = http.request({ hostname: 'localhost', port: 12334, path: url, method, headers: Object.assign({ 'Host': u.hostname }, headers) }, res => { const chunks = []; res.on('data', c => chunks.push(c)); res.on('end', () => resolve({ status: res.statusCode, body: Buffer.concat(chunks) })); }); req.on('error', reject); req.end(); }); } async function main() { const token = makeJWT(); const auth = 'JWT ' + token; // Get version 1.0.3 details console.log('==> Getting 1.0.3 file details...'); const vRes = await proxyReq('GET', `https://addons.mozilla.org/api/v5/addons/addon/${ADDON_ID}/versions/6297788/`, { 'Authorization': auth }); const vData = JSON.parse(vRes.body.toString()); const file = vData.file; console.log(` Status: ${file.status} Size: ${file.size} URL: ${file.url}`); if (file.status !== 'public' || !file.url) { console.log(' Not ready yet'); process.exit(1); } // Download 1.0.3 console.log('==> Downloading 1.0.3...'); fs.mkdirSync('release/firefox', { recursive: true }); const out103 = 'release/firefox/verstak-firefox-1.0.3.xpi'; execSync(`curl -s -x http://localhost:12334 -L "${file.url}" -H "Authorization: ${auth}" -o "${out103}"`, { timeout: 60000 }); const fd = fs.openSync(out103, 'r'); const magic = Buffer.alloc(4); fs.readSync(fd, magic, 0, 4, 0); fs.closeSync(fd); console.log(` 1.0.3: ${out103} (${(fs.statSync(out103).size / 1024).toFixed(1)} KB) ZIP: ${magic[0]===0x50 && magic[1]===0x4B ? 'VALID ✓' : 'INVALID ✗'}`); // List contents console.log(' Contents:'); execSync(`unzip -l "${out103}" 2>&1 | grep -v "^Archive" | grep -v "^ Length" | grep -v "^---------" | grep -v "^-$"`); // Generate updates.json for 1.0.3 const updatesJson = JSON.stringify({ addons: { 'verstak-bridge@verstak.app': { updates: [{ version: '1.0.3', update_link: 'https://mirv.top/verstak/firefox/verstak-firefox-1.0.3.xpi' }] } } }, null, 2); fs.writeFileSync('release/firefox/updates.json', updatesJson); console.log('\n==> updates.json written'); console.log(updatesJson); console.log('\n==> DONE ✓'); } main().catch(e => { console.error(e.message); process.exit(1); });