aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r--server/controllers/api/videos/index.ts28
1 files changed, 16 insertions, 12 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 244d91914..e2798830e 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -104,6 +104,10 @@ videosRouter.get('/:id',
104 asyncMiddleware(videosGetValidator), 104 asyncMiddleware(videosGetValidator),
105 getVideo 105 getVideo
106) 106)
107videosRouter.post('/:id/views',
108 asyncMiddleware(videosGetValidator),
109 asyncMiddleware(viewVideo)
110)
107 111
108videosRouter.delete('/:id', 112videosRouter.delete('/:id',
109 authenticate, 113 authenticate,
@@ -311,25 +315,25 @@ async function updateVideo (req: express.Request, res: express.Response) {
311 } 315 }
312} 316}
313 317
314async function getVideo (req: express.Request, res: express.Response) { 318function getVideo (req: express.Request, res: express.Response) {
319 const videoInstance = res.locals.video
320
321 return res.json(videoInstance.toFormattedDetailsJSON())
322}
323
324async function viewVideo (req: express.Request, res: express.Response) {
315 const videoInstance = res.locals.video 325 const videoInstance = res.locals.video
316 326
317 const baseIncrementPromise = videoInstance.increment('views') 327 await videoInstance.increment('views')
318 .then(() => getServerAccount()) 328 const serverAccount = await getServerAccount()
319 329
320 if (videoInstance.isOwned()) { 330 if (videoInstance.isOwned()) {
321 // The increment is done directly in the database, not using the instance value 331 await sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined)
322 baseIncrementPromise
323 .then(serverAccount => sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined))
324 .catch(err => logger.error('Cannot add view to video/send view to followers for %s.', videoInstance.uuid, err))
325 } else { 332 } else {
326 baseIncrementPromise 333 await sendCreateViewToOrigin(serverAccount, videoInstance, undefined)
327 .then(serverAccount => sendCreateViewToOrigin(serverAccount, videoInstance, undefined))
328 .catch(err => logger.error('Cannot send view to origin server for %s.', videoInstance.uuid, err))
329 } 334 }
330 335
331 // Do not wait the view system 336 return res.status(204).end()
332 return res.json(videoInstance.toFormattedDetailsJSON())
333} 337}
334 338
335async function getVideoDescription (req: express.Request, res: express.Response) { 339async function getVideoDescription (req: express.Request, res: express.Response) {