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

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-02-19 15:39:35 +01:00
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: {
2020-09-03 09:55:06 +02:00
size: 5000,
2020-02-19 15:39:35 +01:00
field: 'host'
}
}
}
}
})
return res.body.aggregations.hosts.buckets.map(b => b.key)
}
async function buildInstanceHosts () {
2020-05-28 15:00:37 +02:00
let indexHosts = await listIndexInstancesHost()
2020-06-11 11:04:00 +02:00
if (CONFIG.INSTANCES_INDEX.WHITELIST.ENABLED) {
const whitelistHosts = Array.isArray(CONFIG.INSTANCES_INDEX.WHITELIST.HOSTS) ? CONFIG.INSTANCES_INDEX.WHITELIST.HOSTS : []
2020-05-28 15:00:37 +02:00
indexHosts = indexHosts.filter(h => whitelistHosts.includes(h))
}
2020-02-19 15:39:35 +01:00
const dbHosts = await listIndexInstances()
const removedHosts = getRemovedHosts(dbHosts, indexHosts)
return { indexHosts, removedHosts }
}
export {
listIndexInstances,
buildInstanceHosts
}