bin-pls
Version:
An npm package to upload code to a pastbin
39 lines (34 loc) • 962 B
JavaScript
const https = require("https");
module.exports = class{
constructor(content){
this.content = content || "";
this.raw = null;
this.json = null;
this.link = null;
}
setContent(content){
this.content = content;
return this;
}
async post(){
const requestOpts = {
method: "POST",
hostname: "hasteb.in",
path: "/documents",
};
let data = "";
await new Promise(resolve => {
const req = https.request(requestOpts, (res) => {
res.once("data", chunk => {
data += chunk
this.raw = data;
this.json = JSON.parse(data);
this.link = `https://hasteb.in/${this.json.key}`
resolve()
});
});
req.write(this.content.toString());
req.end();
})
}
}