From b5c0e95544cec5a33cee3df41c1607d2a0cd5403 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 23 Feb 2018 16:39:51 +0100 Subject: Avoids easy cheating on vidoe views --- server/controllers/api/videos/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'server/controllers') 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 { import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' import { JobQueue } from '../../../lib/job-queue' +import { Redis } from '../../../lib/redis' import { asyncMiddleware, authenticate, @@ -352,7 +353,16 @@ function getVideo (req: express.Request, res: express.Response) { async function viewVideo (req: express.Request, res: express.Response) { const videoInstance = res.locals.video + const ip = req.ip + const exists = await Redis.Instance.isViewExists(ip, videoInstance.uuid) + if (exists) { + logger.debug('View for ip %s and video %s already exists.', ip, videoInstance.uuid) + return res.status(204).end() + } + await videoInstance.increment('views') + await Redis.Instance.setView(ip, videoInstance.uuid) + const serverAccount = await getServerActor() if (videoInstance.isOwned()) { -- cgit v1.2.3