aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-04-06 08:50:43 +0200
committerChocobozzz <chocobozzz@cpy.re>2022-04-15 09:49:35 +0200
commitac907dc7c158056e9b6a5cb58acd27df5c7c2670 (patch)
treef9d8bff22e0543a305c64e1a1808c0df6d512f1e /server/controllers/api/videos
parentdfbcefc20dc64f0814b1f2e8e782a4ea1bd24db2 (diff)
downloadPeerTube-ac907dc7c158056e9b6a5cb58acd27df5c7c2670.tar.gz
PeerTube-ac907dc7c158056e9b6a5cb58acd27df5c7c2670.tar.zst
PeerTube-ac907dc7c158056e9b6a5cb58acd27df5c7c2670.zip
Improve viewer counter
More precise, avoid weird decrease, reuse an id to federate viewers
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/view.ts10
1 files changed, 1 insertions, 9 deletions
diff --git a/server/controllers/api/videos/view.ts b/server/controllers/api/videos/view.ts
index e28cf371a..db1091f2d 100644
--- a/server/controllers/api/videos/view.ts
+++ b/server/controllers/api/videos/view.ts
@@ -1,8 +1,6 @@
1import express from 'express' 1import express from 'express'
2import { sendView } from '@server/lib/activitypub/send/send-view'
3import { Hooks } from '@server/lib/plugins/hooks' 2import { Hooks } from '@server/lib/plugins/hooks'
4import { VideoViewsManager } from '@server/lib/views/video-views-manager' 3import { VideoViewsManager } from '@server/lib/views/video-views-manager'
5import { getServerActor } from '@server/models/application/application'
6import { MVideoId } from '@server/types/models' 4import { MVideoId } from '@server/types/models'
7import { HttpStatusCode, VideoView } from '@shared/models' 5import { HttpStatusCode, VideoView } from '@shared/models'
8import { asyncMiddleware, methodsValidator, openapiOperationDoc, optionalAuthenticate, videoViewValidator } from '../../../middlewares' 6import { asyncMiddleware, methodsValidator, openapiOperationDoc, optionalAuthenticate, videoViewValidator } from '../../../middlewares'
@@ -33,7 +31,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
33 const body = req.body as VideoView 31 const body = req.body as VideoView
34 32
35 const ip = req.ip 33 const ip = req.ip
36 const { successView, successViewer } = await VideoViewsManager.Instance.processLocalView({ 34 const { successView } = await VideoViewsManager.Instance.processLocalView({
37 video, 35 video,
38 ip, 36 ip,
39 currentTime: body.currentTime, 37 currentTime: body.currentTime,
@@ -41,15 +39,9 @@ async function viewVideo (req: express.Request, res: express.Response) {
41 }) 39 })
42 40
43 if (successView) { 41 if (successView) {
44 await sendView({ byActor: await getServerActor(), video, type: 'view' })
45
46 Hooks.runAction('action:api.video.viewed', { video: video, ip, req, res }) 42 Hooks.runAction('action:api.video.viewed', { video: video, ip, req, res })
47 } 43 }
48 44
49 if (successViewer) {
50 await sendView({ byActor: await getServerActor(), video, type: 'viewer' })
51 }
52
53 await updateUserHistoryIfNeeded(body, video, res) 45 await updateUserHistoryIfNeeded(body, video, res)
54 46
55 return res.status(HttpStatusCode.NO_CONTENT_204).end() 47 return res.status(HttpStatusCode.NO_CONTENT_204).end()