aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/index.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-10 17:27:49 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit571389d43b8fc8aaf27e77c06f19b320b08dbbc9 (patch)
treee57173bcd0590d939c28952a29258fd02a281e35 /server/controllers/api/videos/index.ts
parent38fa2065831b5f55be0d7f30f19a62c967397208 (diff)
downloadPeerTube-571389d43b8fc8aaf27e77c06f19b320b08dbbc9.tar.gz
PeerTube-571389d43b8fc8aaf27e77c06f19b320b08dbbc9.tar.zst
PeerTube-571389d43b8fc8aaf27e77c06f19b320b08dbbc9.zip
Make it compile at least
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r--server/controllers/api/videos/index.ts88
1 files changed, 29 insertions, 59 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 9ad84609f..063839223 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -1,57 +1,41 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as multer from 'multer' 2import * as multer from 'multer'
3import { extname, join } from 'path' 3import { extname, join } from 'path'
4 4import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared'
5import { database as db } from '../../../initializers/database'
6import { 5import {
7 CONFIG, 6 fetchRemoteVideoDescription,
8 REQUEST_VIDEO_QADU_TYPES, 7 generateRandomString,
9 REQUEST_VIDEO_EVENT_TYPES, 8 getFormattedObjects,
10 VIDEO_CATEGORIES, 9 getVideoFileHeight,
11 VIDEO_LICENCES, 10 logger,
12 VIDEO_LANGUAGES, 11 renamePromise,
13 VIDEO_PRIVACIES, 12 resetSequelizeInstance,
14 VIDEO_MIMETYPE_EXT 13 retryTransactionWrapper
15} from '../../../initializers' 14} from '../../../helpers'
16import { 15import { getActivityPubUrl } from '../../../helpers/activitypub'
17 addEventToRemoteVideo, 16import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers'
18 quickAndDirtyUpdateVideoToFriends, 17import { database as db } from '../../../initializers/database'
19 addVideoToFriends, 18import { sendAddVideo, sendUpdateVideoChannel } from '../../../lib/activitypub/send-request'
20 updateVideoToFriends, 19import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler'
21 JobScheduler,
22 fetchRemoteDescription
23} from '../../../lib'
24import { 20import {
21 asyncMiddleware,
25 authenticate, 22 authenticate,
26 paginationValidator, 23 paginationValidator,
27 videosSortValidator,
28 setVideosSort,
29 setPagination, 24 setPagination,
30 setVideosSearch, 25 setVideosSearch,
31 videosUpdateValidator, 26 setVideosSort,
32 videosSearchValidator,
33 videosAddValidator, 27 videosAddValidator,
34 videosGetValidator, 28 videosGetValidator,
35 videosRemoveValidator, 29 videosRemoveValidator,
36 asyncMiddleware 30 videosSearchValidator,
31 videosSortValidator,
32 videosUpdateValidator
37} from '../../../middlewares' 33} from '../../../middlewares'
38import {
39 logger,
40 retryTransactionWrapper,
41 generateRandomString,
42 getFormattedObjects,
43 renamePromise,
44 getVideoFileHeight,
45 resetSequelizeInstance
46} from '../../../helpers'
47import { VideoInstance } from '../../../models' 34import { VideoInstance } from '../../../models'
48import { VideoCreate, VideoUpdate, VideoPrivacy } from '../../../../shared'
49
50import { abuseVideoRouter } from './abuse' 35import { abuseVideoRouter } from './abuse'
51import { blacklistRouter } from './blacklist' 36import { blacklistRouter } from './blacklist'
52import { rateVideoRouter } from './rate'
53import { videoChannelRouter } from './channel' 37import { videoChannelRouter } from './channel'
54import { getActivityPubUrl } from '../../../helpers/activitypub' 38import { rateVideoRouter } from './rate'
55 39
56const videosRouter = express.Router() 40const videosRouter = express.Router()
57 41
@@ -225,7 +209,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
225 } 209 }
226 210
227 tasks.push( 211 tasks.push(
228 JobScheduler.Instance.createJob(t, 'videoFileOptimizer', dataInput) 212 transcodingJobScheduler.createJob(t, 'videoFileOptimizer', dataInput)
229 ) 213 )
230 } 214 }
231 await Promise.all(tasks) 215 await Promise.all(tasks)
@@ -252,9 +236,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
252 // Don't send video to remote pods, it is private 236 // Don't send video to remote pods, it is private
253 if (video.privacy === VideoPrivacy.PRIVATE) return undefined 237 if (video.privacy === VideoPrivacy.PRIVATE) return undefined
254 238
255 const remoteVideo = await video.toAddRemoteJSON() 239 await sendAddVideo(video, t)
256 // Now we'll add the video's meta data to our friends
257 return addVideoToFriends(remoteVideo, t)
258 }) 240 })
259 241
260 logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoUUID) 242 logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoUUID)
@@ -302,14 +284,12 @@ async function updateVideo (req: express.Request, res: express.Response) {
302 284
303 // Now we'll update the video's meta data to our friends 285 // Now we'll update the video's meta data to our friends
304 if (wasPrivateVideo === false) { 286 if (wasPrivateVideo === false) {
305 const json = videoInstance.toUpdateRemoteJSON() 287 await sendUpdateVideoChannel(videoInstance, t)
306 return updateVideoToFriends(json, t)
307 } 288 }
308 289
309 // Video is not private anymore, send a create action to remote pods 290 // Video is not private anymore, send a create action to remote pods
310 if (wasPrivateVideo === true && videoInstance.privacy !== VideoPrivacy.PRIVATE) { 291 if (wasPrivateVideo === true && videoInstance.privacy !== VideoPrivacy.PRIVATE) {
311 const remoteVideo = await videoInstance.toAddRemoteJSON() 292 await sendAddVideo(videoInstance, t)
312 return addVideoToFriends(remoteVideo, t)
313 } 293 }
314 }) 294 })
315 295
@@ -324,7 +304,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
324 } 304 }
325} 305}
326 306
327function getVideo (req: express.Request, res: express.Response) { 307async function getVideo (req: express.Request, res: express.Response) {
328 const videoInstance = res.locals.video 308 const videoInstance = res.locals.video
329 309
330 if (videoInstance.isOwned()) { 310 if (videoInstance.isOwned()) {
@@ -333,21 +313,11 @@ function getVideo (req: express.Request, res: express.Response) {
333 // For example, only add a view when a user watch a video during 30s etc 313 // For example, only add a view when a user watch a video during 30s etc
334 videoInstance.increment('views') 314 videoInstance.increment('views')
335 .then(() => { 315 .then(() => {
336 const qaduParams = { 316 // TODO: send to followers a notification
337 videoId: videoInstance.id,
338 type: REQUEST_VIDEO_QADU_TYPES.VIEWS
339 }
340 return quickAndDirtyUpdateVideoToFriends(qaduParams)
341 }) 317 })
342 .catch(err => logger.error('Cannot add view to video %s.', videoInstance.uuid, err)) 318 .catch(err => logger.error('Cannot add view to video %s.', videoInstance.uuid, err))
343 } else { 319 } else {
344 // Just send the event to our friends 320 // TODO: send view event to followers
345 const eventParams = {
346 videoId: videoInstance.id,
347 type: REQUEST_VIDEO_EVENT_TYPES.VIEWS
348 }
349 addEventToRemoteVideo(eventParams)
350 .catch(err => logger.error('Cannot add event to remote video %s.', videoInstance.uuid, err))
351 } 321 }
352 322
353 // Do not wait the view system 323 // Do not wait the view system
@@ -361,7 +331,7 @@ async function getVideoDescription (req: express.Request, res: express.Response)
361 if (videoInstance.isOwned()) { 331 if (videoInstance.isOwned()) {
362 description = videoInstance.description 332 description = videoInstance.description
363 } else { 333 } else {
364 description = await fetchRemoteDescription(videoInstance) 334 description = await fetchRemoteVideoDescription(videoInstance)
365 } 335 }
366 336
367 return res.json({ description }) 337 return res.json({ description })