MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / migrateConfig

Method migrateConfig

autodelcmd/autodelcmd.ts:224–258  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

222
223 // 从版本 0 迁移到版本 1:添加默认规则
224 if (currentVersion < 1) {
225 console.log("[autodelcmd] 从版本 0 迁移到版本 1");
226
227 if (!this.config.customRules) {
228 this.config.customRules = [];
229 }
230
231 const existingRules = this.config.customRules;
232 const defaultRules = this.getDefaultRules();
233
234 // 获取当前最大ID
235 let nextId = getMaxRuleId(existingRules) + 1;
236
237 // 将默认规则中不存在的规则添加到配置中
238 let addedCount = 0;
239 for (const defaultRule of defaultRules) {
240 const ruleKey = this.getRuleKey(defaultRule);
241 const exists = existingRules.some(r => this.getRuleKey(r) === ruleKey);
242
243 if (!exists) {
244 defaultRule.id = nextId.toString();
245 existingRules.push(defaultRule);
246 nextId++;
247 addedCount++;
248 }
249 }
250
251 console.log(`[autodelcmd] 迁移完成,新增 ${addedCount} 条默认规则`);
252 this.config.configVersion = 1;
253 }
254 }
255
256 private async saveConfig() {
257 try {
258 await fs.mkdir(path.dirname(CONFIG_FILE_PATH), { recursive: true });
259 await fs.writeFile(
260 CONFIG_FILE_PATH,
261 JSON.stringify(this.config, null, 2)

Callers 1

loadConfigMethod · 0.95

Calls 3

getDefaultRulesMethod · 0.95
getRuleKeyMethod · 0.95
getMaxRuleIdFunction · 0.85

Tested by

no test coverage detected