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

Method init

zpr/zpr.ts:88–108  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

86 try {
87 await fs.mkdir(dataPath, { recursive: true });
88 this.configPath = path.join(dataPath, "zpr_config.json");
89 this.backupPath = path.join(dataPath, "zpr_config.backup.json");
90
91 // 尝试从备份恢复损坏的配置
92 await this.validateAndRestore();
93
94 this.db = await JSONFilePreset<Record<string, any>>(
95 this.configPath,
96 { ...DEFAULT_CONFIG }
97 );
98 this.initialized = true;
99 console.log("[zpr] 配置初始化成功");
100 } catch (error) {
101 console.error("[zpr] 初始化配置失败:", error);
102 await this.handleInitError();
103 }
104 }
105
106 private static async validateAndRestore(): Promise<void> {
107 try {
108 const configExists = await fs.access(this.configPath).then(() => true).catch(() => false);
109 if (!configExists) return;
110
111 const configContent = await fs.readFile(this.configPath, 'utf8');

Callers 2

reinitMethod · 0.95
ensureInitializedMethod · 0.95

Calls 3

validateAndRestoreMethod · 0.95
handleInitErrorMethod · 0.95
errorMethod · 0.80

Tested by

no test coverage detected