diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-23 16:39:51 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-23 16:44:37 +0100 |
commit | b5c0e95544cec5a33cee3df41c1607d2a0cd5403 (patch) | |
tree | 38a5db1faed107f7b75583c32125152812594821 /server/controllers/api/videos/index.ts | |
parent | e3bb78a2134a5e5755b6dbd8987894572ca31269 (diff) | |
download | PeerTube-b5c0e95544cec5a33cee3df41c1607d2a0cd5403.tar.gz PeerTube-b5c0e95544cec5a33cee3df41c1607d2a0cd5403.tar.zst PeerTube-b5c0e95544cec5a33cee3df41c1607d2a0cd5403.zip |
Avoids easy cheating on vidoe views
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r-- | server/controllers/api/videos/index.ts | 10 |
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 { | |||
22 | import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' | 22 | import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' |
23 | import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' | 23 | import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' |
24 | import { JobQueue } from '../../../lib/job-queue' | 24 | import { JobQueue } from '../../../lib/job-queue' |
25 | import { Redis } from '../../../lib/redis' | ||
25 | import { | 26 | import { |
26 | asyncMiddleware, | 27 | asyncMiddleware, |
27 | authenticate, | 28 | authenticate, |
@@ -352,7 +353,16 @@ function getVideo (req: express.Request, res: express.Response) { | |||
352 | async function viewVideo (req: express.Request, res: express.Response) { | 353 | async 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()) { |