42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { elasticSearch } from '../helpers/elastic-search'
|
|
import { CONFIG } from '../initializers/constants'
|
|
import { getRemovedHosts, listIndexInstancesHost } from './instances-index'
|
|
|
|
async function listIndexInstances () {
|
|
const res = await elasticSearch.search({
|
|
index: CONFIG.ELASTIC_SEARCH.INDEXES.VIDEOS,
|
|
body: {
|
|
size: 0,
|
|
aggs: {
|
|
hosts: {
|
|
terms: {
|
|
field: 'host'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
return res.body.aggregations.hosts.buckets.map(b => b.key)
|
|
}
|
|
|
|
async function buildInstanceHosts () {
|
|
let indexHosts = await listIndexInstancesHost()
|
|
|
|
if (CONFIG.INSTANCES_INDEX.WHITELIST.ENABLED) {
|
|
const whitelistHosts = Array.isArray(CONFIG.INSTANCES_INDEX.WHITELIST.HOSTS) ? CONFIG.INSTANCES_INDEX.WHITELIST.HOSTS : []
|
|
|
|
indexHosts = indexHosts.filter(h => whitelistHosts.includes(h))
|
|
}
|
|
|
|
const dbHosts = await listIndexInstances()
|
|
const removedHosts = getRemovedHosts(dbHosts, indexHosts)
|
|
|
|
return { indexHosts, removedHosts }
|
|
}
|
|
|
|
export {
|
|
listIndexInstances,
|
|
buildInstanceHosts
|
|
}
|