Skip to content

Commit

Permalink
Merge pull request #63 from atorber/main
Browse files Browse the repository at this point in the history
修复@swc/core兼容性问题,修复图片文件接收失败问题
  • Loading branch information
leochen-g authored Sep 19, 2023
2 parents 71369a0 + 72b525c commit 2ac055e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"memory-card": "^1.0.3"
},
"peerDependencies": {
"wechaty-puppet": "^1.18.3"
"wechaty-puppet": "^1.18.3",
"@swc/core":"1.3.78"
},
"homepage": "https://github.com/wechaty/wechaty-puppet-wechat4u#readme",
"dependencies": {
Expand Down
32 changes: 24 additions & 8 deletions src/puppet-wechat4u.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,18 @@ export class PuppetWechat4u extends PUPPET.Puppet {
imageType,
PUPPET.types.Image[imageType],
)
return PUPPET.throwUnsupportedError()
/**
* 图片消息
*/
// console.log('图片消息,保存到本地')
const filename = `${messageId}.jpg`
const msg = await this.wechat4u.getMsgImg(messageId)
const file = FileBox.fromStream(
msg.data,
filename,
)

return file
}

override async messageFile (id: string): Promise<FileBoxInterface> {
Expand All @@ -617,7 +628,7 @@ export class PuppetWechat4u extends PUPPET.Puppet {
const payload = await this.messagePayload(id)
const rawPayload = await this.messageRawPayload(id)

const filename = payload.filename || 'unknown.txt'
let filename = payload.filename || 'unknown.txt'

/**
* 判断消息类型
Expand All @@ -644,16 +655,20 @@ export class PuppetWechat4u extends PUPPET.Puppet {
return emoticonBox
}
// eslint-disable-next-lint no-fallthrough
case PUPPET.types.Message.Image:
case PUPPET.types.Message.Image:{
/**
* 图片消息
*/
// console.log('图片消息,保存到本地')
return FileBox.fromStream(
(await this.wechat4u.getMsgImg(rawPayload.MsgId)).data,
filename = `${rawPayload.MsgId}.jpg`
const msg = await this.wechat4u.getMsgImg(rawPayload.MsgId)

const file = FileBox.fromBuffer(
msg.data,
filename,
)

return file
}
case PUPPET.types.Message.Audio: {
/**
* 语音消息
Expand Down Expand Up @@ -692,9 +707,10 @@ export class PuppetWechat4u extends PUPPET.Puppet {
* 文件消息
*/
// console.log('文件消息,保存到本地')
return FileBox.fromStream(
filename = rawPayload.FileName
return FileBox.fromBuffer(
(await this.wechat4u.getDoc(rawPayload.FromUserName, rawPayload.MediaId, rawPayload.FileName)).data,
rawPayload.FileName,
filename,
)
}
break
Expand Down

0 comments on commit 2ac055e

Please sign in to comment.