55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
const jwt = require('jsonwebtoken');
|
|
const http = require('http');
|
|
|
|
const KEY = 'user:1022172:47';
|
|
const SECRET = 'da4e4367277668aa6e048b0a04d1a417ba8bad630f4ac37ccdcea064a9de151e';
|
|
const PROXY = 'http://localhost:12334';
|
|
|
|
const payload = {
|
|
iss: KEY,
|
|
jti: Math.random().toString(36).slice(2),
|
|
iat: Math.floor(Date.now() / 1000),
|
|
exp: Math.floor(Date.now() / 1000) + 300
|
|
};
|
|
const token = jwt.sign(payload, SECRET);
|
|
|
|
const apiUrl = 'https://addons.mozilla.org/api/v5/addons/verstak-bridge@verstak.app/versions/';
|
|
const url = new URL(apiUrl);
|
|
const proxyHost = PROXY.replace('http://', '').split(':');
|
|
|
|
const options = {
|
|
hostname: proxyHost[0],
|
|
port: parseInt(proxyHost[1] || '8080'),
|
|
path: apiUrl,
|
|
method: 'GET',
|
|
headers: {
|
|
'Host': url.hostname,
|
|
'Authorization': 'JWT ' + token,
|
|
'User-Agent': 'web-ext/7.0.0'
|
|
}
|
|
};
|
|
|
|
const req = http.request(options, (res) => {
|
|
let data = '';
|
|
res.on('data', chunk => data += chunk);
|
|
res.on('end', () => {
|
|
try {
|
|
const json = JSON.parse(data);
|
|
if (json.results) {
|
|
json.results.forEach(v => {
|
|
console.log('Version:', v.version, 'ID:', v.id, 'Status:', v.files?.[0]?.status || 'unknown');
|
|
if (v.files && v.files.length > 0 && v.files[0].download_url) {
|
|
console.log(' Download:', v.files[0].download_url);
|
|
}
|
|
});
|
|
} else {
|
|
console.log(JSON.stringify(json, null, 2).substring(0, 500));
|
|
}
|
|
} catch(e) {
|
|
console.log('Raw:', data.substring(0, 500));
|
|
}
|
|
});
|
|
});
|
|
req.on('error', (e) => console.error('Error:', e.message));
|
|
req.end();
|