diff --git a/README.md b/README.md index bb40073..15b04c9 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,17 @@ Then open http://localhost:3234. ## Production +Install dependencies: + * NodeJS (v12) + * Elastic Search + In the root of the cloned repo: ```terminal $ git submodule update --init --recursive $ yarn install --pure-lockfile $ npm run build +$ cp config/default.yaml config/production.yaml +$ vim config/production.yaml $ node dist/server.js ``` diff --git a/config/default.yaml b/config/default.yaml index af09c55..cbccd88 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -18,4 +18,10 @@ log: level: 'debug' # debug/info/warning/error instances-index: - url: 'https://instances.joinpeertube.org' + # Contains PeerTube instance hosts the indexer will index + # Must answer the following format: https://framagit.org/framasoft/peertube/instances-peertube#peertube-auto-follow-global-search + url: 'https://instances.joinpeertube.org/api/v1/instances/hosts' + +whitelist: + enabled: false + hosts: null diff --git a/config/test.yaml b/config/test.yaml index 18e0211..1cd6a94 100644 --- a/config/test.yaml +++ b/config/test.yaml @@ -2,3 +2,14 @@ elastic_search: indexes: videos: 'peertube-index-videos-test1' channels: 'peertube-index-channels-test1' + +whitelist: + enabled: true + hosts: + - 'peertube.cpy.re' + - 'peertube2.cpy.re' + - 'peertube3.cpy.re' + - 'framatube.org' + - 'aperi.tube' + - 'peertube.datagueule.tv' + - 'thinkerview.video' diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 6ad4ef5..df6411b 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -20,6 +20,10 @@ const CONFIG = { }, INSTANCES_INDEX: { URL: config.get('instances-index.url') + }, + WHITELIST: { + ENABLED: config.get('whitelist.enabled'), + HOSTS: config.get('whitelist.hosts') } } diff --git a/server/lib/elastic-search-instances.ts b/server/lib/elastic-search-instances.ts index 55169a5..fd5421f 100644 --- a/server/lib/elastic-search-instances.ts +++ b/server/lib/elastic-search-instances.ts @@ -21,17 +21,13 @@ async function listIndexInstances () { } async function buildInstanceHosts () { - const whitelist = [ - 'peertube.cpy.re', - 'peertube2.cpy.re', - 'peertube3.cpy.re', - 'framatube.org', - 'aperi.tube', - 'peertube.datagueule.tv', - 'thinkerview.video' - ] + let indexHosts = await listIndexInstancesHost() - const indexHosts = (await listIndexInstancesHost()).filter(h => whitelist.includes(h)) + if (CONFIG.WHITELIST.ENABLED) { + const whitelistHosts = Array.isArray(CONFIG.WHITELIST.HOSTS) ? CONFIG.WHITELIST.HOSTS : [] + + indexHosts = indexHosts.filter(h => whitelistHosts.includes(h)) + } const dbHosts = await listIndexInstances() const removedHosts = getRemovedHosts(dbHosts, indexHosts) diff --git a/server/lib/instances-index.ts b/server/lib/instances-index.ts index 0a2abf5..de2f48f 100644 --- a/server/lib/instances-index.ts +++ b/server/lib/instances-index.ts @@ -2,9 +2,12 @@ import { CONFIG } from '../initializers/constants' import { doRequest } from '../helpers/requests' async function listIndexInstancesHost (): Promise { - const uri = CONFIG.INSTANCES_INDEX.URL + '/api/v1/instances/hosts' + const uri = CONFIG.INSTANCES_INDEX.URL - const qs = { count: 5000 } + const qs = { + healthy: true, + count: 5000 + } const { body } = await doRequest({ uri, qs, json: true })