Switch from restler to unirest
restler is buggy and doesn't support utf8 multipart requests
This commit is contained in:
@ -33,8 +33,13 @@ const ESCAPABLE = '.^$*+?()[{\\|}]'.split('');
|
||||
* @return {object} Parsed arguments
|
||||
*/
|
||||
export default function argumentParser(format, string) {
|
||||
string = string.replace(/[^\s]+/, '');
|
||||
format = format.replace(/[^\s]+/, '');
|
||||
string = string.replace(/[^\s]+/, '').trim();
|
||||
format = format.replace(/[^\s]+/, '').trim();
|
||||
|
||||
if (!string || !format) {
|
||||
return {};
|
||||
}
|
||||
|
||||
let indexes = [];
|
||||
|
||||
format = format.replace(/\s/g, '\\s*');
|
||||
|
@ -1,18 +1,24 @@
|
||||
import restler from 'restler';
|
||||
import unirest from 'unirest';
|
||||
|
||||
export default function fetch(path, data = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const method = Object.keys(data).length ? 'POST' : 'GET';
|
||||
const multipart = method === 'POST' ? true : false;
|
||||
const files = {};
|
||||
|
||||
restler.request('https://api.telegram.org/bot' + path, {
|
||||
data, method, multipart
|
||||
}).on('complete', response => {
|
||||
try {
|
||||
let json = JSON.parse(response);
|
||||
resolve(json);
|
||||
} catch(e) {
|
||||
reject(e);
|
||||
for (let key of Object.keys(data)) {
|
||||
if (data[key].file) {
|
||||
files[key] = data[key].file;
|
||||
delete data[key];
|
||||
}
|
||||
}
|
||||
|
||||
unirest.post('https://api.telegram.org/bot' + path)
|
||||
.field(data)
|
||||
.attach(files)
|
||||
.end(response => {
|
||||
if (response.statusType === 4 || response.statusType === 5) {
|
||||
reject(response);
|
||||
} else {
|
||||
resolve(response.body);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user