verstak/scripts/check-104.js

52 lines
2.4 KiB
JavaScript

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;
// List versions
const vRes = await proxyReq('GET', `https://addons.mozilla.org/api/v5/addons/addon/${ADDON_ID}/versions/?filter=all_with_unlisted`, { 'Authorization': auth });
const vData = JSON.parse(vRes.body.toString());
for (const v of vData.results || []) {
const file = v.files?.[0] || v.file;
console.log(`v${v.version} id=${v.id} status=${file?.status} url=${file?.url || 'none'}`);
if (v.version === '1.0.4' && file?.status === 'public' && file?.url) {
console.log(`\n==> Downloading 1.0.4...`);
fs.mkdirSync('release/firefox', { recursive: true });
const out = 'release/firefox/verstak-firefox-1.0.4.xpi';
execSync(`curl -s -x http://localhost:12334 -L "${file.url}" -H "Authorization: ${auth}" -o "${out}"`, { timeout: 60000 });
console.log(` Saved: ${out} (${(fs.statSync(out).size/1024).toFixed(1)} KB)`);
// Update updates.json
const updatesJson = JSON.stringify({ addons: { 'verstak-bridge@verstak.app': { updates: [{ version: '1.0.4', update_link: 'https://mirv.top/verstak/firefox/verstak-firefox-1.0.4.xpi' }] } } }, null, 2);
fs.writeFileSync('release/firefox/updates.json', updatesJson);
console.log('==> updates.json updated');
return;
}
}
console.log('1.0.4 not found or not public');
}
main().catch(e => { console.error(e.message); process.exit(1); });