More string checking, and stream filename checking (fs streams)

This commit is contained in:
Nicholas Tay
2016-01-25 11:07:06 +11:00
parent 3a8f1ddbf9
commit 3b3f5d831a
2 changed files with 21 additions and 2 deletions

View File

@@ -571,7 +571,16 @@ var InternalClient = (function () {
InternalClient.prototype.sendFile = function sendFile(where, _file, name) {
var _this14 = this;
name = name ? name : require('path').basename(attachment);
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 _this14.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, null, {

View File

@@ -461,7 +461,17 @@ export default class InternalClient {
// def sendFile
sendFile(where, _file, name) {
name = name ? name : require('path').basename(attachment);
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(channel =>