koishi-plugin-maichuni-scorehelper 0.0.9-test → 0.0.11-test

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.
@@ -116,11 +116,15 @@ class MaimaiStatus extends koishi_1.Service {
116
116
  this.clientLogger.warn('Failed to fetch heartbeat data.');
117
117
  return;
118
118
  }
119
- // 3. 补充未知服务 ID (针对网站挂了但 API 正常返回新 ID 的情况)
120
- // 修复:传递 heartbeatData.heartbeatList
121
- this.syncUnknownGroups(heartbeatData.heartbeatList);
119
+ const list = heartbeatData.heartbeatList;
120
+ if (!list) {
121
+ this.clientLogger.warn('Heartbeat data format invalid: list missing', Object.keys(heartbeatData));
122
+ return;
123
+ }
124
+ // 3. 补充未知服务 ID
125
+ this.syncUnknownGroups(list);
122
126
  // 4. 分析状态并处理通知
123
- await this.analyzeAndNotify(heartbeatData.heartbeatList);
127
+ await this.analyzeAndNotify(list);
124
128
  }
125
129
  catch (e) {
126
130
  this.clientLogger.error('Error in check task:', e);
@@ -284,7 +288,16 @@ class MaimaiStatus extends koishi_1.Service {
284
288
  */
285
289
  async fetchHeartbeats() {
286
290
  try {
287
- const data = await this.ctx.http.get(this.API_URL);
291
+ let data = await this.ctx.http.get(this.API_URL);
292
+ // 如果不是对象,尝试解析 JSON (因为 Object.keys 打印出了索引,说明是字符串)
293
+ if (typeof data === 'string') {
294
+ try {
295
+ data = JSON.parse(data);
296
+ }
297
+ catch {
298
+ return null;
299
+ }
300
+ }
288
301
  // 返回原始对象,包含 heartbeatList 和 uptimeList
289
302
  return data || {};
290
303
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-maichuni-scorehelper",
3
- "version": "0.0.9-test",
3
+ "version": "0.0.11-test",
4
4
  "description": "一个基础的 Koishi 插件,未来用于舞萌中二节奏分数辅助。",
5
5
  "keywords": [
6
6
  "koishi",
@@ -161,13 +161,18 @@ export class MaimaiStatus extends Service {
161
161
  this.clientLogger.warn('Failed to fetch heartbeat data.')
162
162
  return
163
163
  }
164
+
165
+ const list = heartbeatData.heartbeatList
166
+ if (!list) {
167
+ this.clientLogger.warn('Heartbeat data format invalid: list missing', Object.keys(heartbeatData))
168
+ return
169
+ }
164
170
 
165
- // 3. 补充未知服务 ID (针对网站挂了但 API 正常返回新 ID 的情况)
166
- // 修复:传递 heartbeatData.heartbeatList
167
- this.syncUnknownGroups(heartbeatData.heartbeatList)
171
+ // 3. 补充未知服务 ID
172
+ this.syncUnknownGroups(list)
168
173
 
169
174
  // 4. 分析状态并处理通知
170
- await this.analyzeAndNotify(heartbeatData.heartbeatList)
175
+ await this.analyzeAndNotify(list)
171
176
 
172
177
  } catch (e) {
173
178
  this.clientLogger.error('Error in check task:', e)
@@ -341,7 +346,17 @@ export class MaimaiStatus extends Service {
341
346
  */
342
347
  private async fetchHeartbeats(): Promise<any> {
343
348
  try {
344
- const data = await this.ctx.http.get(this.API_URL)
349
+ let data = await this.ctx.http.get(this.API_URL)
350
+
351
+ // 如果不是对象,尝试解析 JSON (因为 Object.keys 打印出了索引,说明是字符串)
352
+ if (typeof data === 'string') {
353
+ try {
354
+ data = JSON.parse(data)
355
+ } catch {
356
+ return null
357
+ }
358
+ }
359
+
345
360
  // 返回原始对象,包含 heartbeatList 和 uptimeList
346
361
  return data || {}
347
362
  } catch (e) {