This commit is contained in:
Tingluo Huang
2023-09-18 01:13:38 +00:00
commit 7751908620
45 changed files with 3072 additions and 0 deletions

39
script/internal/https.js Normal file
View File

@@ -0,0 +1,39 @@
const https = require("https");
const fs = require("fs");
const assert = require("assert");
/**
* Performs a get request
* @param {string} url
* @returns {Promise}
*/
async function get(url) {
assert.ok(url, "Arg 'url' must not be empty");
var options = {
method: "GET",
headers: {
"User-Agent": "node/" + process.version,
},
};
var promise = new Promise((resolve, reject) => {
var req = https.request(url, options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
resolve(body);
});
res.on("error", function (error) {
reject(error);
});
});
req.end();
});
return promise;
}
exports.get = get;