stremio-addons
Version:
Stremio Add-on Server / Client
22 lines (18 loc) • 645 B
JavaScript
module.exports.http = require("http");
var url = require("url");
module.exports.receiveJSON = function(resp, callback) {
if (resp.method == "GET") {
var body = url.parse(resp.url, true).query.b;
try { body = JSON.parse(new Buffer(body, "base64").toString()) } catch(e) { return callback(e) };
return callback(null, body);
}
var body = [];
resp.on("data", function(b) { body.push(b) });
resp.on("end", function() {
try { body = JSON.parse(Buffer.concat(body).toString()) } catch(e) { return callback(e) }
callback(null, body);
});
};
module.exports.genID = function() {
return Math.round(Math.random() * Math.pow(2, 24))
};