diff --git a/server/lib/elastic-search/elastic-search-instances.ts b/server/lib/elastic-search/elastic-search-instances.ts index 44555ae..194e67e 100644 --- a/server/lib/elastic-search/elastic-search-instances.ts +++ b/server/lib/elastic-search/elastic-search-instances.ts @@ -1,8 +1,9 @@ import { AggregationsStringTermsAggregate } from '@elastic/elasticsearch/lib/api/types' import { elasticSearch } from '../../helpers/elastic-search' import { CONFIG } from '../../initializers/constants' -import { listIndexInstancesHost } from '../requests/instances-index' +import { getMajorInstanceVersion, listIndexInstancesHost } from '../requests/instances-index' import { extractBucketsFromAggregation } from './elastic-search-queries' +import { logger } from '../../helpers/logger' async function buildInstanceHosts () { let indexHosts = await listIndexInstancesHost() @@ -15,6 +16,16 @@ async function buildInstanceHosts () { indexHosts = indexHosts.filter(h => whitelistHosts.includes(h)) } + for (const indexHost of indexHosts) { + const instanceVersion = await getMajorInstanceVersion(indexHost) + + if (instanceVersion < 4) { + logger.info(`Do not index ${indexHost} because the major version is too low (v${instanceVersion} < v4)`) + + indexHosts = indexHosts.filter(h => h === indexHost) + } + } + const dbHosts = await listDBInstances() const removedHosts = getRemovedHosts(dbHosts, indexHosts) diff --git a/server/lib/requests/instances-index.ts b/server/lib/requests/instances-index.ts index a0083be..210a0e7 100644 --- a/server/lib/requests/instances-index.ts +++ b/server/lib/requests/instances-index.ts @@ -1,7 +1,7 @@ import { CONFIG } from '../../initializers/constants' import { doRequest } from '../../helpers/requests' -async function listIndexInstancesHost (): Promise { +export async function listIndexInstancesHost (): Promise { const uri = CONFIG.INSTANCES_INDEX.URL const qs = { @@ -14,6 +14,14 @@ async function listIndexInstancesHost (): Promise { return body.data.map(o => o.host as string) } -export { - listIndexInstancesHost +export async function getMajorInstanceVersion (host: string): Promise { + const { body } = await doRequest({ uri: `https://${host}/api/v1/config`, json: true }) + + const version = body.serverVersion + + const majorVersion = parseInt(version.split('.')[0]) + + return isNaN(majorVersion) + ? 0 + : majorVersion } diff --git a/server/lib/requests/peertube-instance.ts b/server/lib/requests/peertube-instance.ts index f7f032f..f53f819 100644 --- a/server/lib/requests/peertube-instance.ts +++ b/server/lib/requests/peertube-instance.ts @@ -55,7 +55,6 @@ async function getVideos (host: string, start: number): Promise