From 47f35a942c008f7c2083039c82c5c997d3cd15eb Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Sun, 24 Jan 2016 21:23:09 +1100 Subject: [PATCH] Make sendFile() use original file name by default --- lib/Client/Client.js | 5 +++-- lib/Client/InternalClient.js | 4 ++-- src/Client/Client.js | 4 +++- src/Client/InternalClient.js | 4 +++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/Client/Client.js b/lib/Client/Client.js index 46672b55b..877efe134 100644 --- a/lib/Client/Client.js +++ b/lib/Client/Client.js @@ -206,10 +206,11 @@ var Client = (function (_EventEmitter) { // def sendFile - Client.prototype.sendFile = function sendFile(where, attachment) { - var name = arguments.length <= 2 || arguments[2] === undefined ? "image.png" : arguments[2]; + Client.prototype.sendFile = function sendFile(where, attachment, name) { var callback = arguments.length <= 3 || arguments[3] === undefined ? function () /*err, m*/{} : arguments[3]; + name = name ? name : require('path').basename(attachment); + return this.internal.sendFile(where, attachment, name).then(dataCallback(callback), errorCallback(callback)); }; diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index 1d82f8066..d99b4b459 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -568,10 +568,10 @@ var InternalClient = (function () { // def sendFile - InternalClient.prototype.sendFile = function sendFile(where, _file) { + InternalClient.prototype.sendFile = function sendFile(where, _file, name) { var _this14 = this; - var name = arguments.length <= 2 || arguments[2] === undefined ? "image.png" : arguments[2]; + name = name ? name : require('path').basename(attachment); return this.resolver.resolveChannel(where).then(function (channel) { return _this14.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, null, { diff --git a/src/Client/Client.js b/src/Client/Client.js index cbc4945dc..961d50103 100644 --- a/src/Client/Client.js +++ b/src/Client/Client.js @@ -190,7 +190,9 @@ export default class Client extends EventEmitter { } // def sendFile - sendFile(where, attachment, name = "image.png", callback = (/*err, m*/) => { }) { + sendFile(where, attachment, name, callback = (/*err, m*/) => { }) { + name = name ? name : require('path').basename(attachment); + return this.internal.sendFile(where, attachment, name) .then(dataCallback(callback), errorCallback(callback)); } diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index 89f378fe3..4c104930a 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -460,7 +460,9 @@ export default class InternalClient { } // def sendFile - sendFile(where, _file, name = "image.png") { + sendFile(where, _file, name) { + name = name ? name : require('path').basename(attachment); + return this.resolver.resolveChannel(where) .then(channel => this.apiRequest("post", Endpoints.CHANNEL_MESSAGES(channel.id), true, null, {