diff options
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r-- | server/controllers/api/videos/index.ts | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 5ebd8fbc4..a3b1dde29 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -62,6 +62,7 @@ import { sequelizeTypescript } from '../../../initializers/database' | |||
62 | import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail' | 62 | import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail' |
63 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | 63 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' |
64 | import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding' | 64 | import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding' |
65 | import { Hooks } from '../../../lib/plugins/hooks' | ||
65 | 66 | ||
66 | const auditLogger = auditLoggerFactory('videos') | 67 | const auditLogger = auditLoggerFactory('videos') |
67 | const videosRouter = express.Router() | 68 | const videosRouter = express.Router() |
@@ -268,10 +269,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
268 | } | 269 | } |
269 | 270 | ||
270 | const videoWasAutoBlacklisted = await autoBlacklistVideoIfNeeded(video, res.locals.oauth.token.User, t) | 271 | const videoWasAutoBlacklisted = await autoBlacklistVideoIfNeeded(video, res.locals.oauth.token.User, t) |
271 | 272 | if (!videoWasAutoBlacklisted) await federateVideoIfNeeded(video, true, t) | |
272 | if (!videoWasAutoBlacklisted) { | ||
273 | await federateVideoIfNeeded(video, true, t) | ||
274 | } | ||
275 | 273 | ||
276 | auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON())) | 274 | auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON())) |
277 | logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) | 275 | logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) |
@@ -279,11 +277,8 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
279 | return { videoCreated, videoWasAutoBlacklisted } | 277 | return { videoCreated, videoWasAutoBlacklisted } |
280 | }) | 278 | }) |
281 | 279 | ||
282 | if (videoWasAutoBlacklisted) { | 280 | if (videoWasAutoBlacklisted) Notifier.Instance.notifyOnVideoAutoBlacklist(videoCreated) |
283 | Notifier.Instance.notifyOnVideoAutoBlacklist(videoCreated) | 281 | else Notifier.Instance.notifyOnNewVideo(videoCreated) |
284 | } else { | ||
285 | Notifier.Instance.notifyOnNewVideo(videoCreated) | ||
286 | } | ||
287 | 282 | ||
288 | if (video.state === VideoState.TO_TRANSCODE) { | 283 | if (video.state === VideoState.TO_TRANSCODE) { |
289 | // Put uuid because we don't have id auto incremented for now | 284 | // Put uuid because we don't have id auto incremented for now |
@@ -307,6 +302,8 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
307 | await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }) | 302 | await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }) |
308 | } | 303 | } |
309 | 304 | ||
305 | Hooks.runAction('action:api.video.uploaded', { video: videoCreated }) | ||
306 | |||
310 | return res.json({ | 307 | return res.json({ |
311 | video: { | 308 | video: { |
312 | id: videoCreated.id, | 309 | id: videoCreated.id, |
@@ -421,6 +418,8 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
421 | if (wasUnlistedVideo || wasPrivateVideo) { | 418 | if (wasUnlistedVideo || wasPrivateVideo) { |
422 | Notifier.Instance.notifyOnNewVideo(videoInstanceUpdated) | 419 | Notifier.Instance.notifyOnNewVideo(videoInstanceUpdated) |
423 | } | 420 | } |
421 | |||
422 | Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated }) | ||
424 | } catch (err) { | 423 | } catch (err) { |
425 | // Force fields we want to update | 424 | // Force fields we want to update |
426 | // If the transaction is retried, sequelize will think the object has not changed | 425 | // If the transaction is retried, sequelize will think the object has not changed |
@@ -436,7 +435,11 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
436 | async function getVideo (req: express.Request, res: express.Response) { | 435 | async function getVideo (req: express.Request, res: express.Response) { |
437 | // We need more attributes | 436 | // We need more attributes |
438 | const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null | 437 | const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null |
439 | const video = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId) | 438 | |
439 | const video = await Hooks.wrapPromise( | ||
440 | VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId), | ||
441 | 'filter:api.video.get.result' | ||
442 | ) | ||
440 | 443 | ||
441 | if (video.isOutdated()) { | 444 | if (video.isOutdated()) { |
442 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } }) | 445 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } }) |
@@ -464,6 +467,8 @@ async function viewVideo (req: express.Request, res: express.Response) { | |||
464 | const serverActor = await getServerActor() | 467 | const serverActor = await getServerActor() |
465 | await sendView(serverActor, videoInstance, undefined) | 468 | await sendView(serverActor, videoInstance, undefined) |
466 | 469 | ||
470 | Hooks.runAction('action:api.video.viewed', { video: videoInstance, ip }) | ||
471 | |||
467 | return res.status(204).end() | 472 | return res.status(204).end() |
468 | } | 473 | } |
469 | 474 | ||
@@ -481,7 +486,7 @@ async function getVideoDescription (req: express.Request, res: express.Response) | |||
481 | } | 486 | } |
482 | 487 | ||
483 | async function listVideos (req: express.Request, res: express.Response) { | 488 | async function listVideos (req: express.Request, res: express.Response) { |
484 | const resultList = await VideoModel.listForApi({ | 489 | const apiOptions = await Hooks.wrapObject({ |
485 | start: req.query.start, | 490 | start: req.query.start, |
486 | count: req.query.count, | 491 | count: req.query.count, |
487 | sort: req.query.sort, | 492 | sort: req.query.sort, |
@@ -495,7 +500,12 @@ async function listVideos (req: express.Request, res: express.Response) { | |||
495 | filter: req.query.filter as VideoFilter, | 500 | filter: req.query.filter as VideoFilter, |
496 | withFiles: false, | 501 | withFiles: false, |
497 | user: res.locals.oauth ? res.locals.oauth.token.User : undefined | 502 | user: res.locals.oauth ? res.locals.oauth.token.User : undefined |
498 | }) | 503 | }, 'filter:api.videos.list.params') |
504 | |||
505 | const resultList = await Hooks.wrapPromise( | ||
506 | VideoModel.listForApi(apiOptions), | ||
507 | 'filter:api.videos.list.result' | ||
508 | ) | ||
499 | 509 | ||
500 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 510 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
501 | } | 511 | } |
@@ -510,5 +520,7 @@ async function removeVideo (req: express.Request, res: express.Response) { | |||
510 | auditLogger.delete(getAuditIdFromRes(res), new VideoAuditView(videoInstance.toFormattedDetailsJSON())) | 520 | auditLogger.delete(getAuditIdFromRes(res), new VideoAuditView(videoInstance.toFormattedDetailsJSON())) |
511 | logger.info('Video with name %s and uuid %s deleted.', videoInstance.name, videoInstance.uuid) | 521 | logger.info('Video with name %s and uuid %s deleted.', videoInstance.name, videoInstance.uuid) |
512 | 522 | ||
523 | Hooks.runAction('action:api.video.deleted', { video: videoInstance }) | ||
524 | |||
513 | return res.type('json').status(204).end() | 525 | return res.type('json').status(204).end() |
514 | } | 526 | } |