communitybuilds-node
Version:
Node.js API for Genshin Impact communitiy builds spreadsheet
71 lines • 2.34 kB
JavaScript
import { get } from 'https';
var myHttp;
(function (myHttp) {
function json(hostname, { path, headers, }) {
return new Promise((resolve, reject) => {
const options = {
hostname: hostname,
path: path,
headers,
method: 'GET',
port: 443,
};
let chunks = [];
get(options, (res) => {
// push the http packets chunks into the buffer
res.on('data', (chunk) => {
chunks.push(chunk);
});
// the connection has ended so build the body from the buffer
// parse it as a JSON and get the tag_name
res.on('end', () => {
const buffer = Buffer.concat(chunks);
try {
const data = JSON.parse(buffer.toString());
if (!data.error) {
resolve(data.values);
}
reject(data.error);
}
catch (err) {
reject(err);
}
});
res.on('error', (error) => {
reject(error);
});
}).on('error', (error) => {
reject(error);
});
});
}
myHttp.json = json;
function html(hostname, { path, headers, }) {
return new Promise((resolve, reject) => {
const options = {
hostname: hostname,
path: path,
headers,
method: 'GET',
port: 443,
};
let chunks = [];
get(options, (res) => {
res.on('data', (chunk) => {
chunks.push(chunk);
});
res.on('end', () => {
resolve(Buffer.concat(chunks).toString());
});
res.on('error', (error) => {
reject(error);
});
}).on('error', (error) => {
reject(error);
});
});
}
myHttp.html = html;
})(myHttp || (myHttp = {}));
export default myHttp;
//# sourceMappingURL=http.js.map