]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/utils/server/follows.ts
Add ability to manually approves instance followers in REST API
[github/Chocobozzz/PeerTube.git] / shared / utils / server / follows.ts
index 7741757a67247f20a8c662102f3b736094f0c8c7..1505804de45537fe8225f11aa06dec3589487942 100644 (file)
@@ -1,6 +1,7 @@
 import * as request from 'supertest'
 import { ServerInfo } from './servers'
 import { waitJobs } from './jobs'
+import { makeGetRequest, makePostBodyRequest } from '..'
 
 function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) {
   const path = '/api/v1/server/followers'
@@ -16,6 +17,28 @@ function getFollowersListPaginationAndSort (url: string, start: number, count: n
     .expect('Content-Type', /json/)
 }
 
+function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
+  const path = '/api/v1/server/followers/' + follower + '/accept'
+
+  return makePostBodyRequest({
+    url,
+    token,
+    path,
+    statusCodeExpected
+  })
+}
+
+function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
+  const path = '/api/v1/server/followers/' + follower + '/reject'
+
+  return makePostBodyRequest({
+    url,
+    token,
+    path,
+    statusCodeExpected
+  })
+}
+
 function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) {
   const path = '/api/v1/server/following'
 
@@ -30,30 +53,36 @@ function getFollowingListPaginationAndSort (url: string, start: number, count: n
     .expect('Content-Type', /json/)
 }
 
-async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
+function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
   const path = '/api/v1/server/following'
 
   const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
-  const res = await request(follower)
+  return request(follower)
     .post(path)
     .set('Accept', 'application/json')
     .set('Authorization', 'Bearer ' + accessToken)
     .send({ 'hosts': followingHosts })
     .expect(expectedStatus)
-
-  return res
 }
 
 async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) {
   const path = '/api/v1/server/following/' + target.host
 
-  const res = await request(url)
+  return request(url)
     .delete(path)
     .set('Accept', 'application/json')
     .set('Authorization', 'Bearer ' + accessToken)
     .expect(expectedStatus)
+}
+
+function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = 204) {
+  const path = '/api/v1/server/followers/peertube@' + follower.host
 
-  return res
+  return request(url)
+    .delete(path)
+    .set('Accept', 'application/json')
+    .set('Authorization', 'Bearer ' + accessToken)
+    .expect(expectedStatus)
 }
 
 async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
@@ -74,6 +103,9 @@ export {
   getFollowersListPaginationAndSort,
   getFollowingListPaginationAndSort,
   unfollow,
+  removeFollower,
   follow,
-  doubleFollow
+  doubleFollow,
+  acceptFollower,
+  rejectFollower
 }