]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/friends.js
Client: add ability to report a video
[github/Chocobozzz/PeerTube.git] / server / lib / friends.js
index f0575ff2fc0b34d2c433e157e5892099f961f48c..2ea837c9997b5463b5eda6807d0f1ca86b2194bb 100644 (file)
@@ -3,21 +3,22 @@
 const each = require('async/each')
 const eachLimit = require('async/eachLimit')
 const eachSeries = require('async/eachSeries')
-const fs = require('fs')
 const request = require('request')
 const waterfall = require('async/waterfall')
 
 const constants = require('../initializers/constants')
 const db = require('../initializers/database')
 const logger = require('../helpers/logger')
+const peertubeCrypto = require('../helpers/peertube-crypto')
 const requests = require('../helpers/requests')
 
+const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
+
 const friends = {
   addVideoToFriends,
   updateVideoToFriends,
   reportAbuseVideoToFriend,
   hasFriends,
-  getMyCertificate,
   makeFriends,
   quitFriends,
   removeVideoToFriends,
@@ -26,7 +27,7 @@ const friends = {
 
 function addVideoToFriends (videoData, transaction, callback) {
   const options = {
-    type: 'add',
+    type: ENDPOINT_ACTIONS.ADD,
     endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
     data: videoData,
     transaction
@@ -36,7 +37,7 @@ function addVideoToFriends (videoData, transaction, callback) {
 
 function updateVideoToFriends (videoData, transaction, callback) {
   const options = {
-    type: 'update',
+    type: ENDPOINT_ACTIONS.UPDATE,
     endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
     data: videoData,
     transaction
@@ -46,7 +47,7 @@ function updateVideoToFriends (videoData, transaction, callback) {
 
 function removeVideoToFriends (videoParams) {
   const options = {
-    type: 'remove',
+    type: ENDPOINT_ACTIONS.REMOVE,
     endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
     data: videoParams
   }
@@ -55,7 +56,7 @@ function removeVideoToFriends (videoParams) {
 
 function reportAbuseVideoToFriend (reportData, video) {
   const options = {
-    type: 'report-abuse',
+    type: ENDPOINT_ACTIONS.REPORT_ABUSE,
     endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
     data: reportData,
     toIds: [ video.Author.podId ]
@@ -72,15 +73,11 @@ function hasFriends (callback) {
   })
 }
 
-function getMyCertificate (callback) {
-  fs.readFile(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.pub', 'utf8', callback)
-}
-
 function makeFriends (hosts, callback) {
   const podsScore = {}
 
   logger.info('Make friends!')
-  getMyCertificate(function (err, cert) {
+  peertubeCrypto.getMyPublicCert(function (err, cert) {
     if (err) {
       logger.error('Cannot read public cert.')
       return callback(err)
@@ -201,7 +198,7 @@ function computeForeignPodsList (host, podsScore, callback) {
       else podsScore[foreignPodHost] = 1
     })
 
-    callback()
+    return callback()
   })
 }
 
@@ -210,6 +207,7 @@ function computeWinningPods (hosts, podsScore) {
   // Only add a pod if it exists in more than a half base pods
   const podsList = []
   const baseScore = hosts.length / 2
+
   Object.keys(podsScore).forEach(function (podHost) {
     // If the pod is not me and with a good score we add it
     if (isMe(podHost) === false && podsScore[podHost] > baseScore) {