sepia-search-motore-di-rice.../server/lib/requests/instances-index.ts

32 lines
763 B
TypeScript
Raw Normal View History

2021-06-24 15:18:54 +02:00
import { CONFIG } from '../../initializers/constants'
import { doRequest } from '../../helpers/requests'
2020-02-14 14:09:31 +01:00
2023-12-18 14:48:40 +01:00
export async function listIndexInstancesHost (): Promise<string[]> {
2020-05-28 15:00:37 +02:00
const uri = CONFIG.INSTANCES_INDEX.URL
2020-02-14 14:09:31 +01:00
2020-05-28 15:00:37 +02:00
const qs = {
healthy: true,
count: 5000
}
2020-02-14 14:09:31 +01:00
2020-03-04 15:32:39 +01:00
const { body } = await doRequest<any>({ uri, qs, json: true })
2020-02-14 14:09:31 +01:00
return body.data.map(o => o.host as string)
}
2023-12-18 14:48:40 +01:00
export async function getMajorInstanceVersion (host: string): Promise<number> {
2023-12-20 16:30:54 +01:00
try {
const { body } = await doRequest<any>({ uri: `https://${host}/api/v1/config`, json: true })
2023-12-18 14:48:40 +01:00
2023-12-20 16:30:54 +01:00
const version = body.serverVersion
2023-12-18 14:48:40 +01:00
2023-12-20 16:30:54 +01:00
const majorVersion = parseInt(version.split('.')[0])
2023-12-18 14:48:40 +01:00
2023-12-20 16:30:54 +01:00
return isNaN(majorVersion)
? 0
: majorVersion
} catch {
return 0
}
2020-02-14 14:09:31 +01:00
}