aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-23 16:39:51 +0100
committerChocobozzz <me@florianbigard.com>2018-02-23 16:44:37 +0100
commitb5c0e95544cec5a33cee3df41c1607d2a0cd5403 (patch)
tree38a5db1faed107f7b75583c32125152812594821 /server/controllers/api/videos
parente3bb78a2134a5e5755b6dbd8987894572ca31269 (diff)
downloadPeerTube-b5c0e95544cec5a33cee3df41c1607d2a0cd5403.tar.gz
PeerTube-b5c0e95544cec5a33cee3df41c1607d2a0cd5403.tar.zst
PeerTube-b5c0e95544cec5a33cee3df41c1607d2a0cd5403.zip
Avoids easy cheating on vidoe views
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/index.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index c9334676e..c3d3acd26 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -22,6 +22,7 @@ import {
22import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' 22import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub'
23import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' 23import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send'
24import { JobQueue } from '../../../lib/job-queue' 24import { JobQueue } from '../../../lib/job-queue'
25import { Redis } from '../../../lib/redis'
25import { 26import {
26 asyncMiddleware, 27 asyncMiddleware,
27 authenticate, 28 authenticate,
@@ -352,7 +353,16 @@ function getVideo (req: express.Request, res: express.Response) {
352async function viewVideo (req: express.Request, res: express.Response) { 353async function viewVideo (req: express.Request, res: express.Response) {
353 const videoInstance = res.locals.video 354 const videoInstance = res.locals.video
354 355
356 const ip = req.ip
357 const exists = await Redis.Instance.isViewExists(ip, videoInstance.uuid)
358 if (exists) {
359 logger.debug('View for ip %s and video %s already exists.', ip, videoInstance.uuid)
360 return res.status(204).end()
361 }
362
355 await videoInstance.increment('views') 363 await videoInstance.increment('views')
364 await Redis.Instance.setView(ip, videoInstance.uuid)
365
356 const serverAccount = await getServerActor() 366 const serverAccount = await getServerActor()
357 367
358 if (videoInstance.isOwned()) { 368 if (videoInstance.isOwned()) {