-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
243 lines (210 loc) · 8.9 KB
/
app.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
const axios = require('axios');
const qs = require('qs');
var HttpsProxyAgent = require('https-proxy-agent').HttpsProxyAgent;
/*
_____ _______ __ _____ ____ ____ __ ___ ____ ____
/ ___/____ ___ ___ ____/ / ___// |/ / |/ / | / / // / / | / __ \/ _/
\__ \/ __ \/ _ \/ _ \/ __ /\__ \/ /|_/ / /|_/ /| | / / // /_______/ /| | / /_/ // /
___/ / /_/ / __/ __/ /_/ /___/ / / / / / / / | |/ /__ __/_____/ ___ |/ ____// /
/____/ .___/\___/\___/\__,_//____/_/ /_/_/ /_/ |___/ /_/ /_/ |_/_/ /___/
/_/
*/
class smmAPI {
constructor(options) {
this.key = options.key;
this.api = options.api;
this.proxy = options.proxy || [];
if(!this.key) throw new Error("Please provide an API key.");
if(!this.api) throw new Error("Please provide an API URL.");
this.axiosInstance = axios.create(this.getRandomProxyConfig());
}
getRandomProxyConfig() {
if (this.proxy.length === 0) return {};
const randomIndex = Math.floor(Math.random() * this.proxy.length);
const proxy = this.proxy[randomIndex];
const agent = new HttpsProxyAgent(`http://${proxy.auth.username}:${proxy.auth.password}@${proxy.host}:${proxy.port}`);
return {
httpsAgent: agent
};
}
async getMyIP() {
try {
let res = await this.axiosInstance.get('https://ipinfo.io/json');
return res.data;
} catch (e) {
return e?.response?.data || { status: "error", error: 'An error occurred while fetching your IP address.' };
}
};
async getBalance() {
try {
let res = await this.axiosInstance.post(this.api, qs.stringify({
key: this.key,
action: "balance"
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
if (res.headers['content-type'] !== 'application/json' && !Array.isArray(res.data) && res.headers['content-type'] !== 'application/json; charset=UTF-8' || !res.data) {
return { status: "systemError", error: 'An error occurred while fetching your balance. Maybe your proxy is not working.' };
} else {
return res.data;
}
} catch (e) {
return { status: "systemError", error: e?.response?.data || 'An error occurred while fetching your balance. Maybe your proxy is not working.' };
}
};
async getServices() {
try {
let res = await this.axiosInstance.post(this.api, qs.stringify({
key: this.key,
action: "services"
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
if (res.headers['content-type'] !== 'application/json' && !Array.isArray(res.data) && res.headers['content-type'] !== 'application/json; charset=UTF-8' || !res.data) {
return { status: "systemError", error: 'An error occurred while fetching services. Maybe your proxy is not working.' };
} else {
return res.data;
}
} catch (e) {
return e?.response?.data || { status: "error", error: 'An error occurred while fetching services.' };
}
};
async getStatus({ order }) {
try {
let res = await this.axiosInstance.post(this.api, qs.stringify({
key: this.key,
action: "status",
order: order
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
if (!res.data && !Array.isArray(res.data)) {
return { status: "systemError", error: 'An error occurred while fetching services. Maybe your proxy is not working.' };
} else {
return res.data;
}
} catch (e) {
return e?.response?.data || { status: "error", error: 'An error occurred while fetching order status.' };
}
};
async getMultipleStatus({ orders }) {
try {
let res = await this.axiosInstance.post(this.api, qs.stringify({
key: this.key,
action: "status",
orders: orders.join(',')
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
if (!res.data && !Array.isArray(res.data)) {
return { status: "systemError", error: 'An error occurred while fetching services. Maybe your proxy is not working.' };
} else {
return res.data;
}
} catch (e) {
return e?.response?.data || { status: "error", error: 'An error occurred while fetching order status.' };
}
};
async addOrder({ service, data }) {
try {
let res = await this.axiosInstance.post(this.api, qs.stringify({
key: this.key,
action: "add",
service: service,
...Object.keys(data).reduce((acc, key) => { return { ...acc, [key]: data[key] } }, {})
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
if (res.headers['content-type'] !== 'application/json' && !Array.isArray(res.data) && res.headers['content-type'] !== 'application/json; charset=UTF-8' || !res.data) {
return { status: "systemError", error: 'An error occurred while fetching services. Maybe your proxy is not working.' };
} else {
return res.data;
}
} catch (e) {
return e?.response?.data || { status: "systemError", error: 'An error occurred while adding an order.' };
}
};
async ordersCancel({ orders }) {
try {
let res = await this.axiosInstance.post(this.api, qs.stringify({
key: this.key,
action: "cancel",
orders: orders
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
return res.data;
} catch (e) {
return e?.response?.data || { status: "error", error: 'An error occurred while cancelling an order.' };
}
};
async refill({ order }) {
try {
let res = await this.axiosInstance.post(this.api, qs.stringify({
key: this.key,
action: "refill",
order: order
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
return res.data;
} catch (e) {
return e?.response?.data || { status: "error", error: 'An error occurred while refilling an order.' };
}
};
async refillStatus({ order }) {
try {
let res = await this.axiosInstance.post(this.api, qs.stringify({
key: this.key,
action: "refill_status",
refill: order
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
return res.data;
} catch (e) {
return e?.response?.data || { status: "error", error: 'An error occurred while fetching refill status.' };
}
};
async refillMultipleStatus({ orders }) {
try {
let res = await this.axiosInstance.post(this.api, qs.stringify({
key: this.key,
action: "refill_status",
refills: orders
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
return res.data;
} catch (e) {
return e?.response?.data || { status: "error", error: 'An error occurred while fetching refill status.' };
}
};
}
module.exports = smmAPI;
/*
_____ _______ __ _____ ____ ____ __ ___ ____ ____
/ ___/____ ___ ___ ____/ / ___// |/ / |/ / | / / // / / | / __ \/ _/
\__ \/ __ \/ _ \/ _ \/ __ /\__ \/ /|_/ / /|_/ /| | / / // /_______/ /| | / /_/ // /
___/ / /_/ / __/ __/ /_/ /___/ / / / / / / / | |/ /__ __/_____/ ___ |/ ____// /
/____/ .___/\___/\___/\__,_//____/_/ /_/_/ /_/ |___/ /_/ /_/ |_/_/ /___/
/_/
*/