diff options
author | Chocobozzz <me@florianbigard.com> | 2022-04-06 08:50:43 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-04-15 09:49:35 +0200 |
commit | ac907dc7c158056e9b6a5cb58acd27df5c7c2670 (patch) | |
tree | f9d8bff22e0543a305c64e1a1808c0df6d512f1e /server/controllers/api/videos/view.ts | |
parent | dfbcefc20dc64f0814b1f2e8e782a4ea1bd24db2 (diff) | |
download | PeerTube-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/view.ts')
-rw-r--r-- | server/controllers/api/videos/view.ts | 10 |
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 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { sendView } from '@server/lib/activitypub/send/send-view' | ||
3 | import { Hooks } from '@server/lib/plugins/hooks' | 2 | import { Hooks } from '@server/lib/plugins/hooks' |
4 | import { VideoViewsManager } from '@server/lib/views/video-views-manager' | 3 | import { VideoViewsManager } from '@server/lib/views/video-views-manager' |
5 | import { getServerActor } from '@server/models/application/application' | ||
6 | import { MVideoId } from '@server/types/models' | 4 | import { MVideoId } from '@server/types/models' |
7 | import { HttpStatusCode, VideoView } from '@shared/models' | 5 | import { HttpStatusCode, VideoView } from '@shared/models' |
8 | import { asyncMiddleware, methodsValidator, openapiOperationDoc, optionalAuthenticate, videoViewValidator } from '../../../middlewares' | 6 | import { 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() |