mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33: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,6 +1,6 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
const Constants = require('../util/Constants');
|
||||
const convertToBuffer = require('../util/Util').convertToBuffer;
|
||||
@@ -211,11 +211,9 @@ class ClientDataResolver {
|
||||
if (typeof resource === 'string') {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (/^https?:\/\//.test(resource)) {
|
||||
const req = request.get(resource).set('Content-Type', 'blob');
|
||||
if (this.client.browser) req.responseType('arraybuffer');
|
||||
req.end((err, res) => {
|
||||
snekfetch.get(resource)
|
||||
.end((err, res) => {
|
||||
if (err) return reject(err);
|
||||
if (this.client.browser) return resolve(convertToBuffer(res.xhr.response));
|
||||
if (!(res.body instanceof Buffer)) return reject(new TypeError('The response body isn\'t a Buffer.'));
|
||||
return resolve(res.body);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user