提交 dd5c366f 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

code format

上级 9cb7749d
/** /**
* *
* wechaty: Wechat for Bot. and for human who talk to bot/robot * wechaty: Wechat for Bot. and for human who talk to bot/robot
* *
* Licenst: ISC * Licenst: ISC
* https://github.com/zixia/wechaty * https://github.com/zixia/wechaty
* *
*/ */
const co = require('co') const co = require('co')
const log = require('./brolog-env') const log = require('./brolog-env')
const UtilLib = require('./util-lib') const UtilLib = require('./util-lib')
const Message = require('./message') const Message = require('./message')
class MediaMessage extends Message { class MediaMessage extends Message {
constructor(rawObj) { constructor(rawObj) {
super(rawObj) super(rawObj)
this.bridge = Message.puppet.bridge this.bridge = Message.puppet.bridge
} }
ready() { ready() {
log.silly('MediaMessage', 'ready()') log.silly('MediaMessage', 'ready()')
const parentReady = super.ready.bind(this) const parentReady = super.ready.bind(this)
return co.call(this, function* () { return co.call(this, function* () {
yield parentReady() yield parentReady()
const url = yield this.getMsgImg(this.id) const url = yield this.getMsgImg(this.id)
this.obj.url = url this.obj.url = url
return this // IMPORTANT! return this // IMPORTANT!
}) })
.catch(e => { .catch(e => {
log.warn('MediaMessage', 'ready() exception: %s', e.message) log.warn('MediaMessage', 'ready() exception: %s', e.message)
throw e throw e
}) })
} }
getMsgImg(id) { getMsgImg(id) {
return this.bridge.getMsgImg(id) return this.bridge.getMsgImg(id)
.catch(e => { .catch(e => {
log.warn('MediaMessage', 'getMsgImg(%d) exception: %s', id, e.message) log.warn('MediaMessage', 'getMsgImg(%d) exception: %s', id, e.message)
throw e throw e
}) })
} }
readyStream() { readyStream() {
return this.ready() return this.ready()
.then(() => { .then(() => {
return Message.puppet.browser.checkSession() return Message.puppet.browser.checkSession()
}) })
.then(cookies => { .then(cookies => {
return UtilLib.downloadStream(this.obj.url, cookies) return UtilLib.downloadStream(this.obj.url, cookies)
}) })
.catch(e => { .catch(e => {
log.warn('MediaMessage', 'stream() exception: %s', e.message) log.warn('MediaMessage', 'stream() exception: %s', e.message)
throw e throw e
}) })
} }
} }
module.exports = MediaMessage module.exports = MediaMessage.default = MediaMessage.MediaMessage = MediaMessage
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册