mirror of https://github.com/GooseMod/OpenAsar
Remove Polyfills (#101)
* poly: remove completely * bootstrap: remove unused request require * asarUpdate: rewrite request -> https * moduleUpdater: rewrite request -> https * ui: fallback to channel instead of "custom" if no hash * index: set name to branch for obvious testing * config/backend: tweak source * moduleUpdater: fix rewrite * moduleUpdater: fix rewrite (x2) * moduleUpdater: follow redirects with rewrite * ci: start multi-branch rewrite * ci: upgrade node to 18.x * ci: rewrite version changing to use existing * ci: change release version getting to in file * ci: mess with yaml syntax * ci: revert to node 16.x, fix version wrapped in quotes * ci: fix invalid yaml * ci: yaml syntax fixing * ci: append to tag * ci: make pre-release unless nightly build * ci: add title nicening * asarUpdate: fix release suffix * asarUpdate: fix not following redirect * winFirst: don't remake shortcuts, tweaks * ui: add channel prefix if non-nightly * chore: prep for main branchpull/115/head
parent
f2da613f2b
commit
ec5082860e
@ -1,2 +0,0 @@
|
||||
// Stub
|
||||
exports.lookup = (file) => 'text/plain';
|
@ -1,84 +0,0 @@
|
||||
const https = require('https');
|
||||
|
||||
// Generic polyfill for "request" npm package, wrapper for https
|
||||
const nodeReq = ({ method, url, headers, qs, timeout, body }) => new Promise((resolve) => {
|
||||
let req;
|
||||
try {
|
||||
req = https.request(url + (qs != null ? `?${(new URLSearchParams(qs)).toString()}` : ''), { method, headers, timeout }, async (res) => {
|
||||
const loc = res.headers.location;
|
||||
if (loc) return resolve(await nodeReq({ url: loc, method, headers, timeout, body }));
|
||||
|
||||
resolve(res);
|
||||
});
|
||||
} catch (e) {
|
||||
return resolve(e);
|
||||
}
|
||||
|
||||
req.on('error', resolve);
|
||||
|
||||
if (body) req.write(body); // Write POST body if included
|
||||
|
||||
req.end();
|
||||
});
|
||||
|
||||
const request = (...args) => {
|
||||
let options, callback;
|
||||
switch (args.length) {
|
||||
case 3: // request(url, options, callback)
|
||||
options = {
|
||||
url: args[0],
|
||||
...args[1]
|
||||
};
|
||||
|
||||
callback = args[2];
|
||||
break;
|
||||
|
||||
default: // request(url, callback) / request(options, callback)
|
||||
options = args[0];
|
||||
callback = args[1];
|
||||
}
|
||||
|
||||
if (typeof options === 'string') {
|
||||
options = {
|
||||
url: options
|
||||
};
|
||||
}
|
||||
|
||||
const listeners = {};
|
||||
|
||||
nodeReq(options).then(async (res) => {
|
||||
if (!res.statusCode) {
|
||||
listeners['error']?.(res);
|
||||
return callback?.(res, null, null);
|
||||
}
|
||||
|
||||
listeners['response']?.(res);
|
||||
|
||||
let data = [];
|
||||
res.on('data', (chunk) => {
|
||||
data.push(chunk);
|
||||
listeners['data']?.(chunk);
|
||||
});
|
||||
|
||||
await new Promise((resolve) => res.on('end', resolve)); // Wait to read full body
|
||||
|
||||
const buf = Buffer.concat(data);
|
||||
callback?.(undefined, res, options.encoding !== null ? buf.toString() : buf);
|
||||
});
|
||||
|
||||
const ret = {
|
||||
on: (type, handler) => {
|
||||
listeners[type] = handler;
|
||||
return ret; // Return self
|
||||
}
|
||||
};
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
for (const m of [ 'get', 'post', 'put', 'patch', 'delete', 'head', 'options' ]) {
|
||||
request[m] = (url, callback) => request({ url, method: m }, callback);
|
||||
}
|
||||
request.del = request.delete; // Special case
|
||||
|
||||
module.exports = request;
|
@ -1,3 +0,0 @@
|
||||
rm -rf src/node_modules
|
||||
mkdir src/node_modules
|
||||
cp -rf poly/* src/node_modules
|
Loading…
Reference in new issue