diff options
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r-- | server/controllers/api/videos/index.ts | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index b26dcabe1..6ac13e6a4 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -23,7 +23,6 @@ import { | |||
23 | fetchRemoteVideoDescription, | 23 | fetchRemoteVideoDescription, |
24 | getVideoActivityPubUrl | 24 | getVideoActivityPubUrl |
25 | } from '../../../lib/activitypub' | 25 | } from '../../../lib/activitypub' |
26 | import { sendCreateView } from '../../../lib/activitypub/send' | ||
27 | import { JobQueue } from '../../../lib/job-queue' | 26 | import { JobQueue } from '../../../lib/job-queue' |
28 | import { Redis } from '../../../lib/redis' | 27 | import { Redis } from '../../../lib/redis' |
29 | import { | 28 | import { |
@@ -37,6 +36,7 @@ import { | |||
37 | setDefaultPagination, | 36 | setDefaultPagination, |
38 | setDefaultSort, | 37 | setDefaultSort, |
39 | videosAddValidator, | 38 | videosAddValidator, |
39 | videosCustomGetValidator, | ||
40 | videosGetValidator, | 40 | videosGetValidator, |
41 | videosRemoveValidator, | 41 | videosRemoveValidator, |
42 | videosSortValidator, | 42 | videosSortValidator, |
@@ -59,6 +59,7 @@ import { resetSequelizeInstance } from '../../../helpers/database-utils' | |||
59 | import { move } from 'fs-extra' | 59 | import { move } from 'fs-extra' |
60 | import { watchingRouter } from './watching' | 60 | import { watchingRouter } from './watching' |
61 | import { Notifier } from '../../../lib/notifier' | 61 | import { Notifier } from '../../../lib/notifier' |
62 | import { sendView } from '../../../lib/activitypub/send/send-view' | ||
62 | 63 | ||
63 | const auditLogger = auditLoggerFactory('videos') | 64 | const auditLogger = auditLoggerFactory('videos') |
64 | const videosRouter = express.Router() | 65 | const videosRouter = express.Router() |
@@ -123,9 +124,9 @@ videosRouter.get('/:id/description', | |||
123 | ) | 124 | ) |
124 | videosRouter.get('/:id', | 125 | videosRouter.get('/:id', |
125 | optionalAuthenticate, | 126 | optionalAuthenticate, |
126 | asyncMiddleware(videosGetValidator), | 127 | asyncMiddleware(videosCustomGetValidator('only-video-with-rights')), |
127 | asyncMiddleware(checkVideoFollowConstraints), | 128 | asyncMiddleware(checkVideoFollowConstraints), |
128 | getVideo | 129 | asyncMiddleware(getVideo) |
129 | ) | 130 | ) |
130 | videosRouter.post('/:id/views', | 131 | videosRouter.post('/:id/views', |
131 | asyncMiddleware(videosGetValidator), | 132 | asyncMiddleware(videosGetValidator), |
@@ -181,6 +182,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
181 | licence: videoInfo.licence, | 182 | licence: videoInfo.licence, |
182 | language: videoInfo.language, | 183 | language: videoInfo.language, |
183 | commentsEnabled: videoInfo.commentsEnabled || false, | 184 | commentsEnabled: videoInfo.commentsEnabled || false, |
185 | downloadEnabled: videoInfo.downloadEnabled || true, | ||
184 | waitTranscoding: videoInfo.waitTranscoding || false, | 186 | waitTranscoding: videoInfo.waitTranscoding || false, |
185 | state: CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED, | 187 | state: CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED, |
186 | nsfw: videoInfo.nsfw || false, | 188 | nsfw: videoInfo.nsfw || false, |
@@ -326,8 +328,9 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
326 | if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support) | 328 | if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support) |
327 | if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) | 329 | if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) |
328 | if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) | 330 | if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) |
329 | if (videoInfoToUpdate.originallyPublishedAt !== undefined && | 331 | if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled) |
330 | videoInfoToUpdate.originallyPublishedAt !== null) { | 332 | |
333 | if (videoInfoToUpdate.originallyPublishedAt !== undefined && videoInfoToUpdate.originallyPublishedAt !== null) { | ||
331 | videoInstance.set('originallyPublishedAt', videoInfoToUpdate.originallyPublishedAt) | 334 | videoInstance.set('originallyPublishedAt', videoInfoToUpdate.originallyPublishedAt) |
332 | } | 335 | } |
333 | 336 | ||
@@ -370,7 +373,11 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
370 | } | 373 | } |
371 | 374 | ||
372 | const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE | 375 | const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE |
373 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) | 376 | |
377 | // Don't send update if the video was unfederated | ||
378 | if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) { | ||
379 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) | ||
380 | } | ||
374 | 381 | ||
375 | auditLogger.update( | 382 | auditLogger.update( |
376 | getAuditIdFromRes(res), | 383 | getAuditIdFromRes(res), |
@@ -397,15 +404,17 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
397 | return res.type('json').status(204).end() | 404 | return res.type('json').status(204).end() |
398 | } | 405 | } |
399 | 406 | ||
400 | function getVideo (req: express.Request, res: express.Response) { | 407 | async function getVideo (req: express.Request, res: express.Response) { |
401 | const videoInstance = res.locals.video | 408 | // We need more attributes |
409 | const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null | ||
410 | const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId) | ||
402 | 411 | ||
403 | if (videoInstance.isOutdated()) { | 412 | if (video.isOutdated()) { |
404 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', videoUrl: videoInstance.url } }) | 413 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } }) |
405 | .catch(err => logger.error('Cannot create AP refresher job for video %s.', videoInstance.url, { err })) | 414 | .catch(err => logger.error('Cannot create AP refresher job for video %s.', video.url, { err })) |
406 | } | 415 | } |
407 | 416 | ||
408 | return res.json(videoInstance.toFormattedDetailsJSON()) | 417 | return res.json(video.toFormattedDetailsJSON()) |
409 | } | 418 | } |
410 | 419 | ||
411 | async function viewVideo (req: express.Request, res: express.Response) { | 420 | async function viewVideo (req: express.Request, res: express.Response) { |
@@ -424,7 +433,7 @@ async function viewVideo (req: express.Request, res: express.Response) { | |||
424 | ]) | 433 | ]) |
425 | 434 | ||
426 | const serverActor = await getServerActor() | 435 | const serverActor = await getServerActor() |
427 | await sendCreateView(serverActor, videoInstance, undefined) | 436 | await sendView(serverActor, videoInstance, undefined) |
428 | 437 | ||
429 | return res.status(204).end() | 438 | return res.status(204).end() |
430 | } | 439 | } |