-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (45 loc) · 1.5 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
require('dotenv').config()
const path = require('path');
const fs = require('fs');
const axios = require('axios');
var throttle = require('promise-ratelimit')(5000); //10s
var FormData = require('form-data');
//joining path of directory
const directoryPath = path.join(__dirname, process.env.FOLDER);
//passsing directoryPath and callback function
fs.readdir(directoryPath, async function (err, files) {
//handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
}
let arrRequest = []
for (let i in files) {
if (i > 149 && i < 200) {
console.log(files[i].replace('.gif', ''));
var form = new FormData();
form.append('mode', 'data');
form.append('name', files[i].replace(/(.gif|.png|.jpg)/gi, ''));
form.append('token', process.env.TOKEN);
form.append('_x_reason', 'customize-emoji-add');
form.append('_x_mode', 'online');
form.append('image', fs.createReadStream(path.join(__dirname, process.env.FOLDER, files[i])));
const formHeaders = form.getHeaders();
const rq = await axios.post(`${process.env.URL}/api/emoji.add`, form, {
headers: {
...formHeaders,
},
})
console.log('rq', rq && rq.data)
}
// arrRequest.push(rq)
}
// Promise.all(arrRequest).then(function (values) {
// console.log(values);
// });
// for (let i = 0; i < files.length; i++) {
// throttle().then(async function () {
// console.log('gooo')
// await arrRequest[i]
// });
// }
});