-
Notifications
You must be signed in to change notification settings - Fork 1
/
pastebin.js
57 lines (56 loc) · 1.46 KB
/
pastebin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const axios = require("axios");
const qs = require("qs");
/**
* This is the main class of the Pastebin API
*/
class Pastebin {
/**
*
* @param {string} dev_key = your pastebin dev key, get it on https://pastebin.com/doc_api#1
*/
constructor(dev_key) {
if (!dev_key) {
throw new Error("Pastebin dev key is required");
}
this.options = {
dev_key: dev_key,
paste_private: "1",
paste_expire_date: "10M",
paste_name: "PastebinAPI Snippet",
paste_format: "text",
user_key: "",
};
this.paste_url = "https://pastebin.com/api/api_post.php";
Pastebin.url = "undefined";
}
async newPaste(paste_code) {
if (!paste_code) {
throw new Error("Paste code is required");
}
const data = qs.stringify({
api_option: "paste",
api_paste_code: paste_code,
api_paste_private: this.options.paste_private,
api_user_key: this.options.user_key,
api_paste_name: this.options.paste_name,
api_paste_expire_date: this.options.paste_expire_date,
api_paste_format: this.options.paste_format,
api_dev_key: this.options.dev_key,
});
const config = {
method: "post",
url: this.paste_url,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
data: data,
};
try {
return (await axios(config)).data
}
catch(error) {
throw new Error(error.response.data);
}
}
}
module.exports = Pastebin;