diff options
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r-- | server/controllers/api/videos/index.ts | 88 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as multer from 'multer' | 2 | import * as multer from 'multer' |
3 | import { extname, join } from 'path' | 3 | import { extname, join } from 'path' |
4 | 4 | import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared' | |
5 | import { database as db } from '../../../initializers/database' | ||
6 | import { | 5 | import { |
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' |
16 | import { | 15 | import { getActivityPubUrl } from '../../../helpers/activitypub' |
17 | addEventToRemoteVideo, | 16 | import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' |
18 | quickAndDirtyUpdateVideoToFriends, | 17 | import { database as db } from '../../../initializers/database' |
19 | addVideoToFriends, | 18 | import { sendAddVideo, sendUpdateVideoChannel } from '../../../lib/activitypub/send-request' |
20 | updateVideoToFriends, | 19 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler' |
21 | JobScheduler, | ||
22 | fetchRemoteDescription | ||
23 | } from '../../../lib' | ||
24 | import { | 20 | import { |
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' |
38 | import { | ||
39 | logger, | ||
40 | retryTransactionWrapper, | ||
41 | generateRandomString, | ||
42 | getFormattedObjects, | ||
43 | renamePromise, | ||
44 | getVideoFileHeight, | ||
45 | resetSequelizeInstance | ||
46 | } from '../../../helpers' | ||
47 | import { VideoInstance } from '../../../models' | 34 | import { VideoInstance } from '../../../models' |
48 | import { VideoCreate, VideoUpdate, VideoPrivacy } from '../../../../shared' | ||
49 | |||
50 | import { abuseVideoRouter } from './abuse' | 35 | import { abuseVideoRouter } from './abuse' |
51 | import { blacklistRouter } from './blacklist' | 36 | import { blacklistRouter } from './blacklist' |
52 | import { rateVideoRouter } from './rate' | ||
53 | import { videoChannelRouter } from './channel' | 37 | import { videoChannelRouter } from './channel' |
54 | import { getActivityPubUrl } from '../../../helpers/activitypub' | 38 | import { rateVideoRouter } from './rate' |
55 | 39 | ||
56 | const videosRouter = express.Router() | 40 | const 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 | ||
327 | function getVideo (req: express.Request, res: express.Response) { | 307 | async 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 }) |