]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos/index.ts
Fix views system behind a proxy
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / index.ts
index 690872320056d3751fe5a4797091e657810aba4f..c0a8ac118a22ec569ad4fbd0e0df6e04e5875451 100644 (file)
@@ -20,7 +20,7 @@ import {
   VIDEO_PRIVACIES
 } from '../../../initializers'
 import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub'
-import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send'
+import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send'
 import { JobQueue } from '../../../lib/job-queue'
 import { Redis } from '../../../lib/redis'
 import {
@@ -353,7 +353,7 @@ 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 ip = req.headers['x-real-ip'] as string || 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)
@@ -365,11 +365,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
 
   const serverAccount = await getServerActor()
 
-  if (videoInstance.isOwned()) {
-    await sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined)
-  } else {
-    await sendCreateViewToOrigin(serverAccount, videoInstance, undefined)
-  }
+  await sendCreateView(serverAccount, videoInstance, undefined)
 
   return res.status(204).end()
 }