tinify webpacks (#1975)

* tinify webpack

* meme

* fix long version

* more changes

* even smoler

* fix up logic

* fix build

* undo changes to user agent manager because its not webpack'd anymore

* the heck

* fix stupid

* clean up browser rules

* typo
This commit is contained in:
Gus Caplan
2017-09-26 00:18:12 -05:00
committed by Crawl
parent 4d4d2f2db7
commit 27ccad1f1c
21 changed files with 85 additions and 80 deletions

View File

@@ -1,9 +1,9 @@
const path = require('path');
const Util = require('../util/Util');
const DataResolver = require('../util/DataResolver');
const Embed = require('./MessageEmbed');
const MessageAttachment = require('./MessageAttachment');
const MessageEmbed = require('./MessageEmbed');
const { browser } = require('../util/Constants');
/**
* Represents a webhook.
@@ -151,14 +151,14 @@ class Webhook {
if (options.files) {
for (let i = 0; i < options.files.length; i++) {
let file = options.files[i];
if (typeof file === 'string' || Buffer.isBuffer(file)) file = { attachment: file };
if (typeof file === 'string' || (!browser && Buffer.isBuffer(file))) file = { attachment: file };
if (!file.name) {
if (typeof file.attachment === 'string') {
file.name = path.basename(file.attachment);
file.name = Util.basename(file.attachment);
} else if (file.attachment && file.attachment.path) {
file.name = path.basename(file.attachment.path);
file.name = Util.basename(file.attachment.path);
} else if (file instanceof MessageAttachment) {
file = { attachment: file.file, name: path.basename(file.file) || 'file.jpg' };
file = { attachment: file.file, name: Util.basename(file.file) || 'file.jpg' };
} else {
file.name = 'file.jpg';
}
@@ -169,7 +169,7 @@ class Webhook {
}
return Promise.all(options.files.map(file =>
DataResolver.resolveFile(file.attachment, this.client.browser).then(resource => {
DataResolver.resolveFile(file.attachment).then(resource => {
file.file = resource;
return file;
})
@@ -249,9 +249,7 @@ class Webhook {
*/
edit({ name = this.name, avatar }, reason) {
if (avatar && (typeof avatar === 'string' && !avatar.startsWith('data:'))) {
return DataResolver.resolveImage(avatar, this.client.browser).then(image =>
this.edit({ name, avatar: image }, reason)
);
return DataResolver.resolveImage(avatar).then(image => this.edit({ name, avatar: image }, reason));
}
return this.client.api.webhooks(this.id, this.token).patch({
data: { name, avatar },