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

code format

上级 9cb7749d
/**
*
* 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册