]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/friends.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / server / lib / friends.ts
index a658201913d9a080c1e34b097d25f7a08b5c8f26..50355d5d17af216936ecc0f893167c4f74ff6deb 100644 (file)
@@ -1,6 +1,7 @@
 import * as request from 'request'
 import * as Sequelize from 'sequelize'
 import * as Promise from 'bluebird'
+import { join } from 'path'
 
 import { database as db } from '../initializers/database'
 import {
@@ -9,7 +10,8 @@ import {
   REQUESTS_IN_PARALLEL,
   REQUEST_ENDPOINTS,
   REQUEST_ENDPOINT_ACTIONS,
-  REMOTE_SCHEME
+  REMOTE_SCHEME,
+  STATIC_PATHS
 } from '../initializers'
 import {
   logger,
@@ -43,8 +45,8 @@ import {
   Pod as FormatedPod
 } from '../../shared'
 
-type QaduParam = { videoId: string, type: RequestVideoQaduType }
-type EventParam = { videoId: string, type: RequestVideoEventType }
+type QaduParam = { videoId: number, type: RequestVideoQaduType }
+type EventParam = { videoId: number, type: RequestVideoEventType }
 
 const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS]
 
@@ -111,7 +113,7 @@ function quickAndDirtyUpdateVideoToFriends (qaduParam: QaduParam, transaction?:
 function quickAndDirtyUpdatesVideoToFriends (qadusParams: QaduParam[], transaction: Sequelize.Transaction) {
   const tasks = []
 
-  qadusParams.forEach(function (qaduParams) {
+  qadusParams.forEach(qaduParams => {
     tasks.push(quickAndDirtyUpdateVideoToFriends(qaduParams, transaction))
   })
 
@@ -130,7 +132,7 @@ function addEventToRemoteVideo (eventParam: EventParam, transaction?: Sequelize.
 function addEventsToRemoteVideo (eventsParams: EventParam[], transaction: Sequelize.Transaction) {
   const tasks = []
 
-  eventsParams.forEach(function (eventParams) {
+  eventsParams.forEach(eventParams => {
     tasks.push(addEventToRemoteVideo(eventParams, transaction))
   })
 
@@ -233,6 +235,13 @@ function sendOwnedVideosToPod (podId: number) {
     })
 }
 
+function fetchRemotePreview (pod: PodInstance, video: VideoInstance) {
+  const host = video.Author.Pod.host
+  const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName())
+
+  return request.get(REMOTE_SCHEME.HTTP + '://' + host + path)
+}
+
 function getRequestScheduler () {
   return requestScheduler
 }
@@ -263,7 +272,8 @@ export {
   sendOwnedVideosToPod,
   getRequestScheduler,
   getRequestVideoQaduScheduler,
-  getRequestVideoEventScheduler
+  getRequestVideoEventScheduler,
+  fetchRemotePreview
 }
 
 // ---------------------------------------------------------------------------
@@ -307,7 +317,7 @@ function getForeignPodsList (host: string) {
   return new Promise< ResultList<FormatedPod> >((res, rej) => {
     const path = '/api/' + API_VERSION + '/pods'
 
-    request.get(REMOTE_SCHEME.HTTP + '://' + host + path, function (err, response, body) {
+    request.get(REMOTE_SCHEME.HTTP + '://' + host + path, (err, response, body) => {
       if (err) return rej(err)
 
       try {