* download the dynamic update data and save it locally. * refresh the local `config.json` file if it's older than 24h * @returns Config object with tools update data
()
| 169 | * @returns Config object with tools update data |
| 170 | */ |
| 171 | async function getUpdateConfig(): Promise<Config> { |
| 172 | const configFile = path.resolve(apklabDataDir, "config.json"); |
| 173 | let configJsonData = { tools: [] }; |
| 174 | |
| 175 | if (fs.existsSync(configFile)) { |
| 176 | configJsonData = JSON.parse(fs.readFileSync(configFile, "utf-8")); |
| 177 | if (Date.now() - fs.statSync(configFile).mtimeMs < ONE_DAY_MS) { |
| 178 | return configJsonData; |
| 179 | } |
| 180 | } |
| 181 | try { |
| 182 | const buffer = await downloadFile(updaterConfigURL); |
| 183 | const config = JSON.parse(Buffer.from(buffer).toString("utf-8")); |
| 184 | if (config && config.tools) { |
| 185 | fs.writeFileSync(configFile, buffer); |
| 186 | return config; |
| 187 | } |
| 188 | } catch (err) { |
| 189 | outputChannel.appendLine(`Failed to download update config: ${err}`); |
| 190 | } |
| 191 | |
| 192 | return configJsonData; |
| 193 | } |
no test coverage detected