]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/server/follows.ts
modularize abstract video list header and implement video hotness recommendation...
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / follows.ts
index 3f7729c20aab00773adb38ae1720c8269ddc2148..6aae4a31dfe4462b92d06d8a4d9ef9c265a8d4ae 100644 (file)
@@ -3,14 +3,15 @@ import { ServerInfo } from './servers'
 import { waitJobs } from './jobs'
 import { makePostBodyRequest } from '../requests/requests'
 import { ActivityPubActorType, FollowState } from '@shared/models'
+import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
 
 function getFollowersListPaginationAndSort (options: {
-  url: string,
-  start: number,
-  count: number,
-  sort: string,
-  search?: string,
-  actorType?: ActivityPubActorType,
+  url: string
+  start: number
+  count: number
+  sort: string
+  search?: string
+  actorType?: ActivityPubActorType
   state?: FollowState
 }) {
   const { url, start, count, sort, search, state, actorType } = options
@@ -29,11 +30,11 @@ function getFollowersListPaginationAndSort (options: {
     .get(path)
     .query(query)
     .set('Accept', 'application/json')
-    .expect(200)
+    .expect(HttpStatusCode.OK_200)
     .expect('Content-Type', /json/)
 }
 
-function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
+function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
   const path = '/api/v1/server/followers/' + follower + '/accept'
 
   return makePostBodyRequest({
@@ -44,7 +45,7 @@ function acceptFollower (url: string, token: string, follower: string, statusCod
   })
 }
 
-function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
+function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
   const path = '/api/v1/server/followers/' + follower + '/reject'
 
   return makePostBodyRequest({
@@ -56,12 +57,12 @@ function rejectFollower (url: string, token: string, follower: string, statusCod
 }
 
 function getFollowingListPaginationAndSort (options: {
-  url: string,
-  start: number,
-  count: number,
-  sort: string,
-  search?: string,
-  actorType?: ActivityPubActorType,
+  url: string
+  start: number
+  count: number
+  sort: string
+  search?: string
+  actorType?: ActivityPubActorType
   state?: FollowState
 }) {
   const { url, start, count, sort, search, state, actorType } = options
@@ -80,11 +81,11 @@ function getFollowingListPaginationAndSort (options: {
     .get(path)
     .query(query)
     .set('Accept', 'application/json')
-    .expect(200)
+    .expect(HttpStatusCode.OK_200)
     .expect('Content-Type', /json/)
 }
 
-function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
+function follow (follower: string, following: string[], accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
   const path = '/api/v1/server/following'
 
   const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
@@ -92,11 +93,11 @@ function follow (follower: string, following: string[], accessToken: string, exp
     .post(path)
     .set('Accept', 'application/json')
     .set('Authorization', 'Bearer ' + accessToken)
-    .send({ 'hosts': followingHosts })
+    .send({ hosts: followingHosts })
     .expect(expectedStatus)
 }
 
-async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) {
+async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
   const path = '/api/v1/server/following/' + target.host
 
   return request(url)
@@ -106,7 +107,7 @@ async function unfollow (url: string, accessToken: string, target: ServerInfo, e
     .expect(expectedStatus)
 }
 
-function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = 204) {
+function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
   const path = '/api/v1/server/followers/peertube@' + follower.host
 
   return request(url)