-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
91 lines (84 loc) · 2.57 KB
/
index.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var axios = require("axios");
var fs = require("fs");
var fd = require("form-data");
headers = {
'Host': 'api.ifunny.mobi',
'accept': 'application/json',
'applicationstate': '1',
'authorization': 'Basic NjUzNjM0MzQ2MzM4MzI2MjJENjQ2NTY1NjMyRDM0MzAzMjM4MkQ2MTMxNjYzMzJEMzEzMzMxMzAzMzM0MzQzMzMzNjQ2MzM0X01zT0lKMzlRMjg6Y2Y2Njc5OTdiY2U5MTJhOTc1MDZhMmFlYjM0ZTI0MWI5NjZiNTdlZQ==',
'accept-language': 'en-IN',
'ifunny-project-id': 'iFunny',
'content-type': 'application/x-www-form-urlencoded',
'content-length': '72',
'accept-encoding': 'application/json',
'user-agent': 'iFunny/6.16.1(1119178) Android/10 (Xiaomi; Redmi Note 7 Pro; Xiaomi)'
};
module.exports = class Ifunny {
constructor() {
this.root = 'https://api.ifunny.mobi';
}
async login(email,password) {
this.email = email;
this.password = password;
var auth = await axios({
url: this.root+'/v4/oauth2/token',
method: 'POST',
headers: headers,
data: 'grant_type=password&username='+encodeURIComponent(this.email)+'&password='+encodeURIComponent(this.password)
});
this.token = auth.data["access_token"]
return this.token
}
addToken(token) {
this.token = token;
}
async load(url,name) {
const writer = fs.createWriteStream(name);
const response = await axios({
url,
method: 'GET',
responseType: 'stream'
})
response.data.pipe(writer)
return new Promise((resolve, reject) => {
writer.on('finish', resolve)
writer.on('error', reject)
})
}
async postimg(url,desc,tags) {
await this.load(url,"meme.jpg");
var data = new fd();
data.append("type","pic");
data.append("description",desc || "");
data.append("tags",tags?JSON.stringify(tags):"[]");
data.append("image", fs.createReadStream('meme.jpg'));
var res = await axios({
url: "https://api.ifunny.mobi/v4/content",
method: "POST",
headers: {
Authorization: "Bearer " + this.token,
...data.getHeaders()
},
data: data
});
return res.data;
}
async postvid(url,desc,tags) {
await this.load(url,"meme.mp4");
var data = new fd();
data.append("type","video_clip");
data.append("description",desc || "");
data.append("tags",tags?JSON.stringify(tags):"[]");
data.append("video", fs.createReadStream('meme.jpg'));
var res = await axios({
url: "https://api.ifunny.mobi/v4/content",
method: "POST",
headers: {
Authorization: "Bearer " + this.token,
...data.getHeaders()
},
data: data
});
return res.data;
}
}