koishi-plugin-ets2-tools-tmp 3.4.5 → 3.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/command/tmpVersionCheck.js +53 -10
- package/package.json +1 -1
|
@@ -18,6 +18,7 @@ class VersionCheckService {
|
|
|
18
18
|
this.currentVersion = null;
|
|
19
19
|
// 上一次检查时的文件清单快照(FilePath -> {md5, type}),用于比对文件变化
|
|
20
20
|
this.fileManifest = null;
|
|
21
|
+
this.disposed = false;
|
|
21
22
|
this.timers = [];
|
|
22
23
|
this.logger = this.initLogger();
|
|
23
24
|
}
|
|
@@ -53,18 +54,51 @@ class VersionCheckService {
|
|
|
53
54
|
|
|
54
55
|
setupVersionCheck() {
|
|
55
56
|
this.logger.info("设置TMP版本检查服务");
|
|
56
|
-
|
|
57
|
-
this.logger.debug("启动时立即检查版本");
|
|
58
|
-
this.checkVersion();
|
|
59
57
|
|
|
60
58
|
const checkInterval = this.cfg.checkInterval * 60 * 1000;
|
|
61
59
|
this.logger.info(`设置定时版本检查,间隔: ${this.cfg.checkInterval} 分钟`);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
|
|
61
|
+
// 顺序很重要:先建立文件清单基线,再开始版本检查。
|
|
62
|
+
// 否则第一次真发生版本更新时 fileManifest 仍是 null,只能退化成“输出完整列表”。
|
|
63
|
+
this.runInitialCheck()
|
|
64
|
+
.catch((error) => {
|
|
65
|
+
this.logger.error("启动版本检查失败:", error.message);
|
|
66
|
+
})
|
|
67
|
+
.finally(() => {
|
|
68
|
+
// 初始化失败也要把定时器挂上,否则整个功能就停摆了
|
|
69
|
+
if (this.disposed) return;
|
|
70
|
+
const intervalTimer = setInterval(async () => {
|
|
71
|
+
this.logger.debug("执行定时版本检查");
|
|
72
|
+
await this.checkVersion();
|
|
73
|
+
}, checkInterval);
|
|
74
|
+
this.timers.push(intervalTimer);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 启动时的初始化:先拉文件清单做基线,再做第一次版本检查。
|
|
80
|
+
*/
|
|
81
|
+
async runInitialCheck() {
|
|
82
|
+
await this.initBaselineManifest();
|
|
83
|
+
|
|
84
|
+
this.logger.debug("启动时立即检查版本");
|
|
85
|
+
await this.checkVersion();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 建立文件清单基线(FilePath -> {md5, type})。
|
|
90
|
+
*
|
|
91
|
+
* files.json 只有“当前版本”的清单、没有历史归档,所以必须在启动时就把当前清单存下来,
|
|
92
|
+
* 下次版本更新时才能逐文件比对 MD5。基线建立失败不影响功能,只是首次更新会退化成完整列表。
|
|
93
|
+
*/
|
|
94
|
+
async initBaselineManifest() {
|
|
95
|
+
const manifest = await this.fetchFileManifest();
|
|
96
|
+
if (manifest && manifest.size > 0) {
|
|
97
|
+
this.fileManifest = manifest;
|
|
98
|
+
this.logger.info(`已建立文件清单基线,共 ${manifest.size} 个文件(版本更新时可精确比对 MD5)`);
|
|
99
|
+
} else {
|
|
100
|
+
this.logger.warn("启动时未能建立文件清单基线,首次版本更新将输出完整文件列表");
|
|
101
|
+
}
|
|
68
102
|
}
|
|
69
103
|
|
|
70
104
|
async checkVersion() {
|
|
@@ -88,12 +122,20 @@ class VersionCheckService {
|
|
|
88
122
|
|
|
89
123
|
this.logger.info(`获取到TMP版本信息: ${versionInfo.name} (${versionInfo.time})`);
|
|
90
124
|
|
|
125
|
+
// 基线可能因启动时网络抖动没建立成功,这里顺带补一次(失败也不影响本次检查)
|
|
126
|
+
if (!this.fileManifest) {
|
|
127
|
+
await this.initBaselineManifest();
|
|
128
|
+
}
|
|
129
|
+
|
|
91
130
|
if (this.currentVersion && this.currentVersion.name !== versionInfo.name) {
|
|
92
131
|
this.logger.info(`检测到版本更新: ${this.currentVersion.name} -> ${versionInfo.name}`);
|
|
93
132
|
|
|
94
133
|
// 比对文件 MD5,找出本次更新实际替换了哪些文件
|
|
134
|
+
// 返回 null 表示清单查询失败(区别于“没有变化”的空数组)
|
|
95
135
|
const changedFiles = await this.detectChangedFiles();
|
|
96
|
-
if (changedFiles
|
|
136
|
+
if (changedFiles === null) {
|
|
137
|
+
this.logger.warn("文件清单获取失败,本次更新通知不包含文件变化");
|
|
138
|
+
} else if (changedFiles.length > 0) {
|
|
97
139
|
this.logger.info(`本次更新涉及 ${changedFiles.length} 个文件变化`);
|
|
98
140
|
}
|
|
99
141
|
|
|
@@ -425,6 +467,7 @@ class VersionCheckService {
|
|
|
425
467
|
|
|
426
468
|
cleanup() {
|
|
427
469
|
this.logger.debug("插件卸载,开始清理版本检查服务资源");
|
|
470
|
+
this.disposed = true;
|
|
428
471
|
this.timers.forEach((timer) => {
|
|
429
472
|
clearTimeout(timer);
|
|
430
473
|
clearInterval(timer);
|