()
| 3 | import config from "./config"; |
| 4 | |
| 5 | export default async function checkPluginsUpdate() { |
| 6 | const plugins = await fsOperation(PLUGIN_DIR).lsDir(); |
| 7 | const promises = []; |
| 8 | const updates = []; |
| 9 | |
| 10 | plugins.forEach((pluginDir) => { |
| 11 | promises.push( |
| 12 | (async () => { |
| 13 | const plugin = await fsOperation( |
| 14 | Url.join(pluginDir.url, "plugin.json"), |
| 15 | ).readFile("json"); |
| 16 | |
| 17 | const res = await fetch( |
| 18 | `${config.API_BASE}/plugin/check-update/${plugin.id}/${plugin.version}`, |
| 19 | ); |
| 20 | |
| 21 | if (res.ok) { |
| 22 | const json = await res.json(); |
| 23 | if (json.update) { |
| 24 | updates.push(plugin.id); |
| 25 | } |
| 26 | } |
| 27 | })(), |
| 28 | ); |
| 29 | }); |
| 30 | |
| 31 | await Promise.allSettled(promises); |
| 32 | return updates; |
| 33 | } |
no test coverage detected