mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
http rewrite (actually works this time!!1!) (#1257)
* rewrite http * browser fun * all the mimes dammit * i need a newline * whoops * forgot about this * use promises and HTTPRequest.method * fluent * move httpclient to external module * branding * middleware * revert middleware
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
const Constants = require('../../util/Constants');
|
||||
|
||||
class APIRequest {
|
||||
@@ -34,17 +34,16 @@ class APIRequest {
|
||||
|
||||
gen() {
|
||||
const API = `${this.client.options.http.host}/api/v${this.client.options.http.version}`;
|
||||
const apiRequest = request[this.method](`${API}${this.path}`);
|
||||
if (this.auth) apiRequest.set('authorization', this.getAuth());
|
||||
const request = snekfetch[this.method](`${API}${this.path}`);
|
||||
if (this.auth) request.set('Authorization', this.getAuth());
|
||||
if (!this.rest.client.browser) request.set('User-Agent', this.rest.userAgentManager.userAgent);
|
||||
if (this.files) {
|
||||
for (const file of this.files) if (file && file.file) apiRequest.attach(file.name, file.file, file.name);
|
||||
this.data = this.data || {};
|
||||
apiRequest.field('payload_json', JSON.stringify(this.data));
|
||||
for (const file of this.files) if (file && file.file) request.attach(file.name, file.file, file.name);
|
||||
if (typeof this.data !== 'undefined') request.attach('payload_json', JSON.stringify(this.data));
|
||||
} else if (this.data) {
|
||||
apiRequest.send(this.data);
|
||||
request.send(this.data);
|
||||
}
|
||||
if (!this.client.browser) apiRequest.set('User-Agent', this.rest.userAgentManager.userAgent);
|
||||
return apiRequest;
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user