aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-22 16:25:03 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:53 +0100
commit40ff57078e15d5b86ee6b71e198b95d3feb78eaf (patch)
tree88031d4eac6a26597e8a1f2fc63674664e3eae26 /server/controllers/api/videos
parentc46edbc2f6ca310b2f0331f979ac6caf27f6eb92 (diff)
downloadPeerTube-40ff57078e15d5b86ee6b71e198b95d3feb78eaf.tar.gz
PeerTube-40ff57078e15d5b86ee6b71e198b95d3feb78eaf.tar.zst
PeerTube-40ff57078e15d5b86ee6b71e198b95d3feb78eaf.zip
Federate video views
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/index.ts26
1 files changed, 15 insertions, 11 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 0d114dcd2..2b5afd632 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -11,10 +11,15 @@ import {
11 resetSequelizeInstance, 11 resetSequelizeInstance,
12 retryTransactionWrapper 12 retryTransactionWrapper
13} from '../../../helpers' 13} from '../../../helpers'
14import { getServerAccount } from '../../../helpers/utils'
14import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' 15import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers'
15import { database as db } from '../../../initializers/database' 16import { database as db } from '../../../initializers/database'
16import { sendAddVideo } from '../../../lib/activitypub/send/send-add' 17import { sendAddVideo } from '../../../lib/activitypub/send/send-add'
17import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update' 18import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update'
19import { shareVideoByServer } from '../../../lib/activitypub/share'
20import { getVideoActivityPubUrl } from '../../../lib/activitypub/url'
21import { fetchRemoteVideoDescription } from '../../../lib/activitypub/videos'
22import { sendCreateViewToVideoFollowers } from '../../../lib/index'
18import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler' 23import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler'
19import { 24import {
20 asyncMiddleware, 25 asyncMiddleware,
@@ -35,9 +40,7 @@ import { abuseVideoRouter } from './abuse'
35import { blacklistRouter } from './blacklist' 40import { blacklistRouter } from './blacklist'
36import { videoChannelRouter } from './channel' 41import { videoChannelRouter } from './channel'
37import { rateVideoRouter } from './rate' 42import { rateVideoRouter } from './rate'
38import { getVideoActivityPubUrl } from '../../../lib/activitypub/url' 43import { sendCreateViewToOrigin } from '../../../lib/activitypub/send/send-create'
39import { shareVideoByServer } from '../../../lib/activitypub/share'
40import { fetchRemoteVideoDescription } from '../../../lib/activitypub/videos'
41 44
42const videosRouter = express.Router() 45const videosRouter = express.Router()
43 46
@@ -311,17 +314,18 @@ async function updateVideo (req: express.Request, res: express.Response) {
311async function getVideo (req: express.Request, res: express.Response) { 314async function getVideo (req: express.Request, res: express.Response) {
312 const videoInstance = res.locals.video 315 const videoInstance = res.locals.video
313 316
317 const baseIncrementPromise = videoInstance.increment('views')
318 .then(() => getServerAccount())
319
314 if (videoInstance.isOwned()) { 320 if (videoInstance.isOwned()) {
315 // The increment is done directly in the database, not using the instance value 321 // The increment is done directly in the database, not using the instance value
316 // FIXME: make a real view system 322 baseIncrementPromise
317 // For example, only add a view when a user watch a video during 30s etc 323 .then(serverAccount => sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined))
318 videoInstance.increment('views') 324 .catch(err => logger.error('Cannot add view to video/send view to followers for %s.', videoInstance.uuid, err))
319 .then(() => {
320 // TODO: send to followers a notification
321 })
322 .catch(err => logger.error('Cannot add view to video %s.', videoInstance.uuid, err))
323 } else { 325 } else {
324 // TODO: send view event to followers 326 baseIncrementPromise
327 .then(serverAccount => sendCreateViewToOrigin(serverAccount, videoInstance, undefined))
328 .catch(err => logger.error('Cannot send view to origin server for %s.', videoInstance.uuid, err))
325 } 329 }
326 330
327 // Do not wait the view system 331 // Do not wait the view system