| 160 | [CONFIG_KEYS.PASSWORD_AUTH]: "no", |
| 161 | [CONFIG_KEYS.PUBKEY_AUTH]: "yes" |
| 162 | }; |
| 163 | |
| 164 | // 配置管理器 |
| 165 | class ConfigManager { |
| 166 | private static db: any = null; |
| 167 | private static initialized = false; |
| 168 | private static initLock = false; // 添加锁防止并发初始化 |
| 169 | private static configPath: string; |
| 170 | |
| 171 | static cleanup(): void { |
| 172 | // 引用重置:清空实例级 db / cache / manager 引用,便于 reload 后重新初始化。 |
| 173 | this.db = null; |
| 174 | this.initialized = false; |
| 175 | this.initLock = false; |
| 176 | this.configPath = ""; |
| 177 | } |
| 178 | |
| 179 | private static async init(): Promise<void> { |
| 180 | if (this.initialized) return; |
| 181 | |
| 182 | // 简单的锁机制防止并发初始化 |
| 183 | while (this.initLock) { |
| 184 | await new Promise(resolve => setTimeout(resolve, 10)); |
| 185 | } |
| 186 | |
| 187 | if (this.initialized) return; |
| 188 | this.initLock = true; |
| 189 | |
| 190 | try { |
| 191 | this.configPath = resolvePluginAssetFile({ |