(config)
| 192 | |
| 193 | |
| 194 | def ensure_config_defaults(config): |
| 195 | # 兼容旧 config.json,老配置不用手动删,启动后自动补齐新字段。 |
| 196 | if not isinstance(config, dict): |
| 197 | config = {} |
| 198 | config.setdefault("data_dir", []) |
| 199 | config.setdefault("users", []) |
| 200 | global_config = config.setdefault("global", {}) |
| 201 | for key, value in DEFAULT_GLOBAL_CONFIG.items(): |
| 202 | global_config.setdefault(key, value) |
| 203 | for key in LEGACY_GLOBAL_CONFIG_KEYS: |
| 204 | global_config.pop(key, None) |
| 205 | |
| 206 | for index, user in enumerate(config.get("users", [])): |
| 207 | for key, value in DEFAULT_USER_EXTRA.items(): |
| 208 | if isinstance(value, dict): |
| 209 | user.setdefault(key, {}) |
| 210 | for k2, v2 in value.items(): |
| 211 | user[key].setdefault(k2, v2) |
| 212 | elif isinstance(value, list): |
| 213 | user.setdefault(key, list(value)) |
| 214 | else: |
| 215 | user.setdefault(key, value) |
| 216 | # 账号和目录直接绑定,保留旧 data_dir 列表只是为了兼容旧版本。 |
| 217 | if "data_dir" not in user and index < len(config.get("data_dir", [])): |
| 218 | user["data_dir"] = config["data_dir"][index] |
| 219 | valid_users = [] |
| 220 | valid_data_dirs = [] |
| 221 | for user in config.get("users", []): |
| 222 | data_dir = user.get("data_dir") |
| 223 | if data_dir and is_wechat_like_account_dir(data_dir): |
| 224 | valid_users.append(user) |
| 225 | valid_data_dirs.append(data_dir) |
| 226 | config["users"] = valid_users |
| 227 | config["data_dir"] = valid_data_dirs |
| 228 | return config |
| 229 | |
| 230 | |
| 231 | def load_config_file(): |
no test coverage detected