@@ -57,7 +57,9 @@ async function wait (ms:number) {
57
57
const userInfo = os . userInfo ( )
58
58
const rootPath = `${ userInfo . homedir } \\Documents\\WeChat Files\\`
59
59
60
- export type PuppetXpOptions = PUPPET . PuppetOptions
60
+ export type PuppetXpOptions = PUPPET . PuppetOptions & {
61
+ weChatFilesPath ?: string
62
+ }
61
63
62
64
class PuppetXp extends PUPPET . Puppet {
63
65
@@ -75,6 +77,8 @@ class PuppetXp extends PUPPET.Puppet {
75
77
76
78
private isReady = false
77
79
80
+ private weChatFilesPath = rootPath
81
+
78
82
#sidecar?: WeChatSidecar
79
83
protected get sidecar ( ) : WeChatSidecar {
80
84
return this . #sidecar!
@@ -86,7 +90,9 @@ class PuppetXp extends PUPPET.Puppet {
86
90
log . info ( 'options...' , JSON . stringify ( options ) )
87
91
super ( options )
88
92
log . verbose ( 'PuppetXp' , 'constructor(%s)' , JSON . stringify ( options ) )
89
-
93
+ if ( options . weChatFilesPath ) {
94
+ this . weChatFilesPath = options . weChatFilesPath
95
+ }
90
96
// FIXME: use LRU cache for message store so that we can reduce memory usage
91
97
this . messageStore = { }
92
98
this . roomStore = { }
@@ -760,7 +766,7 @@ class PuppetXp extends PUPPET.Puppet {
760
766
if ( message ?. text ) {
761
767
const picData = JSON . parse ( message . text )
762
768
const filePath = picData [ imageType ]
763
- const dataPath = rootPath + filePath // 要解密的文件路径
769
+ const dataPath = this . weChatFilesPath + filePath // 要解密的文件路径
764
770
// log.info('图片原始文件路径:', dataPath, true)
765
771
766
772
// 检测图片原始文件是否存在,如果存在则继续,如果不存在则每隔0.5秒后检测一次,直到10s后还不存在则继续
@@ -838,7 +844,7 @@ class PuppetXp extends PUPPET.Puppet {
838
844
}
839
845
fileName = '\\' + messageJson . msg . appmsg [ 0 ] . title [ 0 ]
840
846
const filePath = `${ this . selfInfo . id } \\FileStorage\\File\\${ year } -${ month } `
841
- dataPath = rootPath + filePath + fileName // 要解密的文件路径
847
+ dataPath = this . weChatFilesPath + filePath + fileName // 要解密的文件路径
842
848
// log.info(dataPath)
843
849
return FileBox . fromFile (
844
850
dataPath ,
0 commit comments