-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.js
More file actions
68 lines (63 loc) · 1.51 KB
/
Copy pathimage.js
File metadata and controls
68 lines (63 loc) · 1.51 KB
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
58
59
60
61
62
63
64
65
66
67
68
const request = require("request");
// const token = "2f9028f80f1ed8276a7b2bb21e29cb522a653119";
// const id = "90244d8c3d0195f";
// const secret = "cb2b9ab9e56723ed08983e6bf5f2350bb129fce0";
// request(
// {
// method: "POST",
// url: "https://api.imgur.com/oauth2/token",
// headers: {},
// formData: {
// refresh_token: token,
// client_id: id,
// client_secret: secret,
// grant_type: "refresh_token",
// },
// },
// (e, r, b) => {
// const json = JSON.parse(b);
// console.log(json);
// }
// );
function upload(base64) {
return new Promise((resolve, reject) => {
request(
{
method: "POST",
url: "https://api.imgur.com/3/image",
headers: {
Token: "5c08340c93f36b53f7fce9877f7c83c9de7a800c",
Authorization: "Client-ID 90244d8c3d0195f",
},
formData: {
image: base64,
},
},
(e, r, b) => {
const json = JSON.parse(b);
console.log(json);
const link = json.link;
resolve(link);
}
);
});
}
function deleteImg(hash) {
return new Promise((resolve, reject) => {
request(
{
method: "DELETE",
url: `https://api.imgur.com/3/image/${hash}`,
headers: {
Authorization: "Bearer 5c08340c93f36b53f7fce9877f7c83c9de7a800c",
},
formData: {},
},
(e, r, b) => {
const json = JSON.parse(b);
resolve(json);
}
);
});
}
module.exports = { upload, deleteImg };