diff --git a/src/message-media.js b/src/message-media.js index 22a4def59a1e53ccc7a691574e9edc511ae3a240..903087301ef8b6d0b1b0da8319a06af6a3af7153 100644 --- a/src/message-media.js +++ b/src/message-media.js @@ -1,59 +1,59 @@ -/** - * - * wechaty: Wechat for Bot. and for human who talk to bot/robot - * - * Licenst: ISC - * https://github.com/zixia/wechaty - * - */ -const co = require('co') - -const log = require('./brolog-env') -const UtilLib = require('./util-lib') -const Message = require('./message') - -class MediaMessage extends Message { - constructor(rawObj) { - super(rawObj) - this.bridge = Message.puppet.bridge - } - ready() { - log.silly('MediaMessage', 'ready()') - - const parentReady = super.ready.bind(this) - return co.call(this, function* () { - yield parentReady() - const url = yield this.getMsgImg(this.id) - this.obj.url = url - - return this // IMPORTANT! - }) - .catch(e => { - log.warn('MediaMessage', 'ready() exception: %s', e.message) - throw e - }) - } - getMsgImg(id) { - return this.bridge.getMsgImg(id) - .catch(e => { - log.warn('MediaMessage', 'getMsgImg(%d) exception: %s', id, e.message) - throw e - }) - } - - readyStream() { - return this.ready() - .then(() => { - return Message.puppet.browser.checkSession() - }) - .then(cookies => { - return UtilLib.downloadStream(this.obj.url, cookies) - }) - .catch(e => { - log.warn('MediaMessage', 'stream() exception: %s', e.message) - throw e - }) - } -} - -module.exports = MediaMessage +/** + * + * wechaty: Wechat for Bot. and for human who talk to bot/robot + * + * Licenst: ISC + * https://github.com/zixia/wechaty + * + */ +const co = require('co') + +const log = require('./brolog-env') +const UtilLib = require('./util-lib') +const Message = require('./message') + +class MediaMessage extends Message { + constructor(rawObj) { + super(rawObj) + this.bridge = Message.puppet.bridge + } + ready() { + log.silly('MediaMessage', 'ready()') + + const parentReady = super.ready.bind(this) + return co.call(this, function* () { + yield parentReady() + const url = yield this.getMsgImg(this.id) + this.obj.url = url + + return this // IMPORTANT! + }) + .catch(e => { + log.warn('MediaMessage', 'ready() exception: %s', e.message) + throw e + }) + } + getMsgImg(id) { + return this.bridge.getMsgImg(id) + .catch(e => { + log.warn('MediaMessage', 'getMsgImg(%d) exception: %s', id, e.message) + throw e + }) + } + + readyStream() { + return this.ready() + .then(() => { + return Message.puppet.browser.checkSession() + }) + .then(cookies => { + return UtilLib.downloadStream(this.obj.url, cookies) + }) + .catch(e => { + log.warn('MediaMessage', 'stream() exception: %s', e.message) + throw e + }) + } +} + +module.exports = MediaMessage.default = MediaMessage.MediaMessage = MediaMessage