Fix multipart for requests, fixes #675

This commit is contained in:
Amish Shah
2016-09-10 12:40:45 +01:00
parent 84fe65ec78
commit 4255dcd3ca
3 changed files with 11 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@@ -28,10 +28,16 @@ class APIRequest {
const apiRequest = request[this.method](this.url);
if (this.auth) apiRequest.set('authorization', this.getAuth());
if (this.file && this.file.file) {
apiRequest.set('Content-Type', 'multipart/form-data');
apiRequest.attach('file', this.file.file, this.file.name);
this.data = this.data || {};
for (const key in this.data) {
if (this.data[key]) {
apiRequest.field(key, this.data[key]);
}
}
} else if (this.data) {
apiRequest.send(this.data);
}
if (this.data) apiRequest.send(this.data);
apiRequest.set('User-Agent', this.rest.userAgentManager.userAgent);
return apiRequest;
}

View File

@@ -49,7 +49,8 @@ class RESTMethods {
sendMessage(channel, content, tts, nonce, disableEveryone, file) {
return new Promise((resolve, reject) => {
const $this = this;
content = this.rest.client.resolver.resolveString(content);
if (typeof content !== 'undefined') content = this.rest.client.resolver.resolveString(content);
if (disableEveryone || (typeof disableEveryone === 'undefined' && this.rest.client.options.disable_everyone)) {
content = content.replace('@everyone', '@\u200beveryone').replace('@here', '@\u200bhere');