]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/friends.ts
Better typescript typing for a better world
[github/Chocobozzz/PeerTube.git] / server / lib / friends.ts
index 498144318a78819a0a59ade60b282e4013a527a3..4d56e9eb22a9fd72611e1ec8955a95d40ad2a532 100644 (file)
@@ -34,7 +34,11 @@ import {
 import {
   RequestEndpoint,
   RequestVideoEventType,
-  RequestVideoQaduType
+  RequestVideoQaduType,
+  RemoteVideoCreateData,
+  RemoteVideoUpdateData,
+  RemoteVideoRemoveData,
+  RemoteVideoReportAbuseData
 } from '../../shared'
 
 type QaduParam = { videoId: string, type: RequestVideoQaduType }
@@ -52,7 +56,7 @@ function activateSchedulers () {
   requestVideoEventScheduler.activate()
 }
 
-function addVideoToFriends (videoData: Object, transaction: Sequelize.Transaction) {
+function addVideoToFriends (videoData: RemoteVideoCreateData, transaction: Sequelize.Transaction) {
   const options = {
     type: ENDPOINT_ACTIONS.ADD,
     endpoint: REQUEST_ENDPOINTS.VIDEOS,
@@ -62,7 +66,7 @@ function addVideoToFriends (videoData: Object, transaction: Sequelize.Transactio
   return createRequest(options)
 }
 
-function updateVideoToFriends (videoData: Object, transaction: Sequelize.Transaction) {
+function updateVideoToFriends (videoData: RemoteVideoUpdateData, transaction: Sequelize.Transaction) {
   const options = {
     type: ENDPOINT_ACTIONS.UPDATE,
     endpoint: REQUEST_ENDPOINTS.VIDEOS,
@@ -72,7 +76,7 @@ function updateVideoToFriends (videoData: Object, transaction: Sequelize.Transac
   return createRequest(options)
 }
 
-function removeVideoToFriends (videoParams: Object) {
+function removeVideoToFriends (videoParams: RemoteVideoRemoveData) {
   const options = {
     type: ENDPOINT_ACTIONS.REMOVE,
     endpoint: REQUEST_ENDPOINTS.VIDEOS,
@@ -82,7 +86,7 @@ function removeVideoToFriends (videoParams: Object) {
   return createRequest(options)
 }
 
-function reportAbuseVideoToFriend (reportData: Object, video: VideoInstance, transaction: Sequelize.Transaction) {
+function reportAbuseVideoToFriend (reportData: RemoteVideoReportAbuseData, video: VideoInstance, transaction: Sequelize.Transaction) {
   const options = {
     type: ENDPOINT_ACTIONS.REPORT_ABUSE,
     endpoint: REQUEST_ENDPOINTS.VIDEOS,
@@ -141,9 +145,7 @@ function makeFriends (hosts: string[]) {
   logger.info('Make friends!')
   return getMyPublicCert()
     .then(cert => {
-      return Promise.mapSeries(hosts, host => {
-        return computeForeignPodsList(host, podsScore)
-      }).then(() => cert)
+      return Promise.each(hosts, host => computeForeignPodsList(host, podsScore)).then(() => cert)
     })
     .then(cert => {
       logger.debug('Pods scores computed.', { podsScore: podsScore })
@@ -169,7 +171,6 @@ function quitFriends () {
       const requestParams = {
         method: 'POST' as 'POST',
         path: '/api/' + API_VERSION + '/remote/pods/remove',
-        sign: true,
         toPod: null
       }
 
@@ -178,11 +179,12 @@ function quitFriends () {
       // The other pod will exclude us automatically after a while
       return Promise.map(pods, pod => {
         requestParams.toPod = pod
+
         return makeSecureRequest(requestParams)
       }, { concurrency: REQUESTS_IN_PARALLEL })
       .then(() => pods)
       .catch(err => {
-        logger.error('Some errors while quitting friends.', { err: err })
+        logger.error('Some errors while quitting friends.', err)
         // Don't stop the process
       })
     })
@@ -217,7 +219,7 @@ function sendOwnedVideosToPod (podId: number) {
             return createRequest(options)
           })
           .catch(err => {
-            logger.error('Cannot convert video to remote.', { error: err })
+            logger.error('Cannot convert video to remote.', err)
             // Don't break the process
             return undefined
           })
@@ -346,7 +348,7 @@ function makeRequestsToWinningPods (cert: string, podsList: PodInstance[]) {
               sendOwnedVideosToPod(podCreated.id)
             })
             .catch(err => {
-              logger.error('Cannot add friend %s pod.', pod.host, { error: err })
+              logger.error('Cannot add friend %s pod.', pod.host, err)
             })
         } else {
           logger.error('Status not 200 for %s pod.', pod.host)