1
0
mirror of https://framagit.org/framasoft/peertube/search-index/ synced 2024-12-12 09:06:08 +01:00
sepia-search-motore-di-rice.../server/lib/elastic-search-instances.ts
2020-09-03 09:55:06 +02:00

43 lines
1.1 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: {
size: 5000,
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
}