From 95cd31f1fe3311c873bee8185e6b07398a775a47 Mon Sep 17 00:00:00 2001
From: Chocobozzz <me@florianbigard.com>
Date: Mon, 11 May 2020 10:48:58 +0200
Subject: [PATCH] Allow to auto follow a specific URL

---
 client/e2e/protractor.conf.js                        | 2 +-
 config/default.yaml                                  | 3 ++-
 config/production.yaml.example                       | 3 ++-
 server/lib/schedulers/auto-follow-index-instances.ts | 4 ++++
 server/tests/api/server/auto-follows.ts              | 2 +-
 5 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/client/e2e/protractor.conf.js b/client/e2e/protractor.conf.js
index 0dd1f6ee5..5531707e6 100644
--- a/client/e2e/protractor.conf.js
+++ b/client/e2e/protractor.conf.js
@@ -61,7 +61,7 @@ exports.config = {
     }
   ],
 
-  maxSessions: 1,
+  // maxSessions: 1,
   // BrowserStack compatible ports: https://www.browserstack.com/question/664
   baseUrl: 'http://localhost:3333/',
   framework: 'jasmine',
diff --git a/config/default.yaml b/config/default.yaml
index c4ea3c42c..a0f2eb3a1 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -367,7 +367,8 @@ followings:
     # /!\ Don't enable this if you don't have a reactive moderation team /!\
     auto_follow_index:
       enabled: false
-      index_url: 'https://instances.joinpeertube.org'
+      # Host your own using https://framagit.org/framasoft/peertube/instances-peertube#peertube-auto-follow
+      index_url: ''
 
 theme:
   default: 'default'
diff --git a/config/production.yaml.example b/config/production.yaml.example
index bd867be53..8b8c98f8c 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -381,7 +381,8 @@ followings:
     # /!\ Don't enable this if you don't have a reactive moderation team /!\
     auto_follow_index:
       enabled: false
-      index_url: 'https://instances.joinpeertube.org'
+      # Host your own using https://framagit.org/framasoft/peertube/instances-peertube#peertube-auto-follow
+      index_url: ''
 
 theme:
   default: 'default'
diff --git a/server/lib/schedulers/auto-follow-index-instances.ts b/server/lib/schedulers/auto-follow-index-instances.ts
index e852c7fc6..a57436a45 100644
--- a/server/lib/schedulers/auto-follow-index-instances.ts
+++ b/server/lib/schedulers/auto-follow-index-instances.ts
@@ -42,6 +42,10 @@ export class AutoFollowIndexInstances extends AbstractScheduler {
       this.lastCheck = new Date()
 
       const { body } = await doRequest<any>({ uri, qs, json: true })
+      if (!body.data || Array.isArray(body.data) === false) {
+        logger.error('Cannot auto follow instances of index %s: bad URL format. Please check the auto follow URL.', indexUrl)
+        return
+      }
 
       const hosts: string[] = body.data.map(o => o.host)
       const chunks = chunk(hosts, 20)
diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts
index 5f48dc0eb..7efccc3e2 100644
--- a/server/tests/api/server/auto-follows.ts
+++ b/server/tests/api/server/auto-follows.ts
@@ -177,7 +177,7 @@ describe('Test auto follows', function () {
         followings: {
           instance: {
             autoFollowIndex: {
-              indexUrl: 'http://localhost:42100',
+              indexUrl: 'http://localhost:42100/api/v1/instances/hosts',
               enabled: true
             }
           }