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

32 lines
763 B
TypeScript

import { CONFIG } from '../../initializers/constants'
import { doRequest } from '../../helpers/requests'
export async function listIndexInstancesHost (): Promise<string[]> {
const uri = CONFIG.INSTANCES_INDEX.URL
const qs = {
healthy: true,
count: 5000
}
const { body } = await doRequest<any>({ uri, qs, json: true })
return body.data.map(o => o.host as string)
}
export async function getMajorInstanceVersion (host: string): Promise<number> {
try {
const { body } = await doRequest<any>({ uri: `https://${host}/api/v1/config`, json: true })
const version = body.serverVersion
const majorVersion = parseInt(version.split('.')[0])
return isNaN(majorVersion)
? 0
: majorVersion
} catch {
return 0
}
}