46 lines
1.0 KiB
TypeScript
46 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 () {
|
|
const whitelist = [
|
|
'peertube.cpy.re',
|
|
'peertube2.cpy.re',
|
|
'peertube3.cpy.re',
|
|
'framatube.org',
|
|
'aperi.tube',
|
|
'peertube.datagueule.tv',
|
|
'thinkerview.video'
|
|
]
|
|
|
|
const indexHosts = (await listIndexInstancesHost()).filter(h => whitelist.includes(h))
|
|
|
|
const dbHosts = await listIndexInstances()
|
|
const removedHosts = getRemovedHosts(dbHosts, indexHosts)
|
|
|
|
return { indexHosts, removedHosts }
|
|
}
|
|
|
|
export {
|
|
listIndexInstances,
|
|
buildInstanceHosts
|
|
}
|