(filename: string)
| 65 | configCache[filename] = Array.isArray(response.data) ? response.data : []; |
| 66 | } catch (error) { |
| 67 | console.error(`下载配置文件失败: ${filename}`, error); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // 确保配置文件存在并是最新的 |
| 72 | async function ensureConfigFile(filename: string): Promise<string[]> { |
| 73 | const localPath = path.join(ASSET_PATH, filename); |
| 74 | const now = Date.now(); |
| 75 | |
| 76 | // 检查是否需要更新 |
| 77 | if (!fs.existsSync(localPath) || now - lastUpdateCheck > UPDATE_INTERVAL) { |
| 78 | await downloadConfigFile(filename); |
| 79 | lastUpdateCheck = now; |
| 80 | } |
| 81 | |
| 82 | // 从缓存获取,如果缓存为空则从文件读取 |
| 83 | if (!configCache[filename] && fs.existsSync(localPath)) { |
| 84 | configCache[filename] = readJsonArray(localPath); |
no test coverage detected