@samitouri / QOSami-HFS / commits / c6bc4410

dx: couldn't test new central.json locally

Massimo Melina committed Apr 1, 2026 at 18:57 UTC c6bc44101147acc4be20bc11c785b99792f4d873
1 file changed +35 -34
src/github.ts
+35 -34
@@ -3,7 +3,7 @@
3 import events from './events'
4 import {
5 httpString, httpStream, unzip, AsapStream, debounceAsync, asyncGeneratorToArray, retry, popKey, onlyTruthy, waitFor,
6 - HOUR, DAY
6 + HOUR, DAY, tryJson
7 } from './misc'
8 import {
9 DISABLING_SUFFIX, enablePlugin, findPluginByRepo, getInactivePlugins, getPluginInfo, isPluginRunning, mapPlugins,
@@ -266,37 +266,38 @@ const cachedCentralInfo = storedMap.singleSync('cachedCentralInfo', '') // persi
266 export let blacklistedInstalledPlugins: string[] = []
267 // centralized hosted information, to be used as little as possible
268 const FN = 'central.json'
269 -let builtIn = JSON.parse(fs.readFileSync(join(__dirname, '..', FN), 'utf8'))
269 +const builtInJson = fs.readFileSync(join(__dirname, '..', FN), 'utf8')
270 const branch = RUNNING_BETA ? VERSION.split('.')[1] : 'main'
271 -export const getProjectInfo = debounceAsync(
272 - () => argv.central === false ? Promise.resolve(builtIn) : readGithubFile(`${HFS_REPO}/${branch}/${FN}`)
273 - .catch(e => RUNNING_BETA ? readGithubFile(`${HFS_REPO}/main/${FN}`) : Promise.reject(e)) // for beta versions, try again with 'main'
274 - .then(JSON.parse, () => null)
275 - .then(o => {
276 - if (o)
277 - cachedCentralInfo.set(o)
278 - o ||= { ...cachedCentralInfo.get() || builtIn } // fall back to built-in
279 - // merge byVersions info in the main object, but collect alerts separately, to preserve multiple instances
280 - const allAlerts: string[] = [o.alert]
281 - for (const [ver, more] of Object.entries(popKey(o, 'byVersion') || {}))
282 - if (VERSION.match(new RegExp(ver))) {
283 - allAlerts.push((more as any).alert)
284 - Object.assign(o, more)
285 - }
286 - _.remove(allAlerts, x => !x)
287 - alerts.set(was => {
288 - if (!_.isEqual(was, allAlerts))
289 - for (const a of allAlerts)
290 - console.log("ALERT:", a)
291 - return allAlerts
292 - })
293 - const black = onlyTruthy(Object.keys(o.repo_blacklist || {}).map(findPluginByRepo))
294 - blacklistedInstalledPlugins = onlyTruthy(black.map(x => _.isString(x.repo) && x.repo))
295 - if (black.length) {
296 - console.log("blacklisted plugins found:", black.join(', '))
297 - for (const p of black)
298 - enablePlugin(p.id, false)
299 - }
300 - return o
301 - }),
302 - { retain: HOUR, retainFailure: 60_000 })
\ No newline at end of file
271 +export const getProjectInfo = debounceAsync(async () => {
272 + const txt = argv.central === false ? builtInJson
273 + : await readGithubFile(`${HFS_REPO}/${branch}/${FN}`)
274 + .catch(() => RUNNING_BETA ? readGithubFile(`${HFS_REPO}/main/${FN}`) : '') // for beta versions, try again with 'main'
275 + .catch(() => '')
276 + let obj = tryJson(txt)
277 + await cachedCentralInfo.ready()
278 + if (obj)
279 + cachedCentralInfo.set(obj)
280 + obj ||= { ...cachedCentralInfo.get() || JSON.parse(builtInJson) } // fall back to built-in
281 + // merge byVersions info in the main object but collect alerts separately to preserve multiple instances
282 + const allAlerts: string[] = [obj.alert]
283 + for (const [ver, more] of Object.entries(popKey(obj, 'byVersion') || {}))
284 + if (VERSION.match(new RegExp(ver))) {
285 + allAlerts.push((more as any).alert)
286 + Object.assign(obj, more)
287 + }
288 + _.remove(allAlerts, x => !x)
289 + alerts.set(was => {
290 + if (!_.isEqual(was, allAlerts))
291 + for (const a of allAlerts)
292 + console.log("ALERT:", a)
293 + return allAlerts
294 + })
295 + const black = onlyTruthy(Object.keys(obj.repo_blacklist || {}).map(findPluginByRepo))
296 + blacklistedInstalledPlugins = onlyTruthy(black.map(x => _.isString(x.repo) && x.repo))
297 + if (black.length) {
298 + console.log("blacklisted plugins found:", black.join(', '))
299 + for (const p of black)
300 + enablePlugin(p.id, false)
301 + }
302 + return obj
303 +}, { retain: HOUR, retainFailure: 60_000 })
\ No newline at end of file