mirror of
https://github.com/danbulant/discord.js
synced 2026-07-05 19:20:42 +00:00
Merge remote-tracking branch 'ntay/sendfile-original-name' into indev
This commit is contained in:
commit
2c6cbb6675
4 changed files with 38 additions and 6 deletions
|
|
@ -223,10 +223,15 @@ var Client = (function (_EventEmitter) {
|
||||||
|
|
||||||
// def sendFile
|
// def sendFile
|
||||||
|
|
||||||
Client.prototype.sendFile = function sendFile(where, attachment) {
|
Client.prototype.sendFile = function sendFile(where, attachment, name) {
|
||||||
var name = arguments.length <= 2 || arguments[2] === undefined ? "image.png" : arguments[2];
|
|
||||||
var callback = arguments.length <= 3 || arguments[3] === undefined ? function () /*err, m*/{} : arguments[3];
|
var callback = arguments.length <= 3 || arguments[3] === undefined ? function () /*err, m*/{} : arguments[3];
|
||||||
|
|
||||||
|
if (typeof name === "function") {
|
||||||
|
// name is the callback
|
||||||
|
callback = name;
|
||||||
|
name = undefined; // Will get resolved into original filename in internal
|
||||||
|
}
|
||||||
|
|
||||||
return this.internal.sendFile(where, attachment, name).then(dataCallback(callback), errorCallback(callback));
|
return this.internal.sendFile(where, attachment, name).then(dataCallback(callback), errorCallback(callback));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -573,10 +573,19 @@ var InternalClient = (function () {
|
||||||
|
|
||||||
// def sendFile
|
// def sendFile
|
||||||
|
|
||||||
InternalClient.prototype.sendFile = function sendFile(where, _file) {
|
InternalClient.prototype.sendFile = function sendFile(where, _file, name) {
|
||||||
var _this15 = this;
|
var _this15 = this;
|
||||||
|
|
||||||
var name = arguments.length <= 2 || arguments[2] === undefined ? "image.png" : arguments[2];
|
if (!name) {
|
||||||
|
if (_file instanceof String || typeof _file === "string") {
|
||||||
|
name = require("path").basename(attachment);
|
||||||
|
} else if (_file.path) {
|
||||||
|
// fs.createReadStream()'s have .path that give the path. Not sure about other streams though.
|
||||||
|
name = require("path").basename(_file.path);
|
||||||
|
} else {
|
||||||
|
name = "image.png"; // Just have to go with default filenames.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this.resolver.resolveChannel(where).then(function (channel) {
|
return this.resolver.resolveChannel(where).then(function (channel) {
|
||||||
return _this15.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, null, {
|
return _this15.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, null, {
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,13 @@ export default class Client extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// def sendFile
|
// def sendFile
|
||||||
sendFile(where, attachment, name = "image.png", callback = (/*err, m*/) => { }) {
|
sendFile(where, attachment, name, callback = (/*err, m*/) => { }) {
|
||||||
|
if (typeof name === "function") {
|
||||||
|
// name is the callback
|
||||||
|
callback = name;
|
||||||
|
name = undefined; // Will get resolved into original filename in internal
|
||||||
|
}
|
||||||
|
|
||||||
return this.internal.sendFile(where, attachment, name)
|
return this.internal.sendFile(where, attachment, name)
|
||||||
.then(dataCallback(callback), errorCallback(callback));
|
.then(dataCallback(callback), errorCallback(callback));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -461,7 +461,19 @@ export default class InternalClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
// def sendFile
|
// def sendFile
|
||||||
sendFile(where, _file, name = "image.png") {
|
sendFile(where, _file, name) {
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
if (_file instanceof String || typeof _file === "string") {
|
||||||
|
name = require("path").basename(attachment);
|
||||||
|
} else if (_file.path) {
|
||||||
|
// fs.createReadStream()'s have .path that give the path. Not sure about other streams though.
|
||||||
|
name = require("path").basename(_file.path);
|
||||||
|
} else {
|
||||||
|
name = "image.png"; // Just have to go with default filenames.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this.resolver.resolveChannel(where)
|
return this.resolver.resolveChannel(where)
|
||||||
.then(channel =>
|
.then(channel =>
|
||||||
this.apiRequest("post", Endpoints.CHANNEL_MESSAGES(channel.id), true, null, {
|
this.apiRequest("post", Endpoints.CHANNEL_MESSAGES(channel.id), true, null, {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue