diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-24 13:36:47 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-04-15 09:49:35 +0200 |
commit | b211106695bb82f6c32e53306081b5262c3d109d (patch) | |
tree | fa187de1c33b0956665f5362e29af6b0f6d8bb57 /server/lib/activitypub/process/process-create.ts | |
parent | 69d48ee30c9d47cddf0c3c047dc99a99dcb6e894 (diff) | |
download | PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.gz PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.zst PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.zip |
Support video views/viewers stats in server
* Add "currentTime" and "event" body params to view endpoint
* Merge watching and view endpoints
* Introduce WatchAction AP activity
* Add tables to store viewer information of local videos
* Add endpoints to fetch video views/viewers stats of local videos
* Refactor views/viewers handlers
* Support "views" and "viewers" counters for both VOD and live videos
Diffstat (limited to 'server/lib/activitypub/process/process-create.ts')
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index b5b1a0feb..3e7931bb2 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { isBlockedByServerOrAccount } from '@server/lib/blocklist' | 1 | import { isBlockedByServerOrAccount } from '@server/lib/blocklist' |
2 | import { isRedundancyAccepted } from '@server/lib/redundancy' | 2 | import { isRedundancyAccepted } from '@server/lib/redundancy' |
3 | import { ActivityCreate, CacheFileObject, PlaylistObject, VideoCommentObject, VideoObject } from '@shared/models' | 3 | import { VideoModel } from '@server/models/video/video' |
4 | import { ActivityCreate, CacheFileObject, PlaylistObject, VideoCommentObject, VideoObject, WatchActionObject } from '@shared/models' | ||
4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 5 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
5 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
6 | import { sequelizeTypescript } from '../../../initializers/database' | 7 | import { sequelizeTypescript } from '../../../initializers/database' |
@@ -8,6 +9,7 @@ import { APProcessorOptions } from '../../../types/activitypub-processor.model' | |||
8 | import { MActorSignature, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../../types/models' | 9 | import { MActorSignature, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../../types/models' |
9 | import { Notifier } from '../../notifier' | 10 | import { Notifier } from '../../notifier' |
10 | import { createOrUpdateCacheFile } from '../cache-file' | 11 | import { createOrUpdateCacheFile } from '../cache-file' |
12 | import { createOrUpdateLocalVideoViewer } from '../local-video-viewer' | ||
11 | import { createOrUpdateVideoPlaylist } from '../playlists' | 13 | import { createOrUpdateVideoPlaylist } from '../playlists' |
12 | import { forwardVideoRelatedActivity } from '../send/shared/send-utils' | 14 | import { forwardVideoRelatedActivity } from '../send/shared/send-utils' |
13 | import { resolveThread } from '../video-comments' | 15 | import { resolveThread } from '../video-comments' |
@@ -32,6 +34,10 @@ async function processCreateActivity (options: APProcessorOptions<ActivityCreate | |||
32 | return retryTransactionWrapper(processCreateVideoComment, activity, byActor, notify) | 34 | return retryTransactionWrapper(processCreateVideoComment, activity, byActor, notify) |
33 | } | 35 | } |
34 | 36 | ||
37 | if (activityType === 'WatchAction') { | ||
38 | return retryTransactionWrapper(processCreateWatchAction, activity) | ||
39 | } | ||
40 | |||
35 | if (activityType === 'CacheFile') { | 41 | if (activityType === 'CacheFile') { |
36 | return retryTransactionWrapper(processCreateCacheFile, activity, byActor) | 42 | return retryTransactionWrapper(processCreateCacheFile, activity, byActor) |
37 | } | 43 | } |
@@ -81,6 +87,19 @@ async function processCreateCacheFile (activity: ActivityCreate, byActor: MActor | |||
81 | } | 87 | } |
82 | } | 88 | } |
83 | 89 | ||
90 | async function processCreateWatchAction (activity: ActivityCreate) { | ||
91 | const watchAction = activity.object as WatchActionObject | ||
92 | |||
93 | if (watchAction.actionStatus !== 'CompletedActionStatus') return | ||
94 | |||
95 | const video = await VideoModel.loadByUrl(watchAction.object) | ||
96 | if (video.remote) return | ||
97 | |||
98 | await sequelizeTypescript.transaction(async t => { | ||
99 | return createOrUpdateLocalVideoViewer(watchAction, video, t) | ||
100 | }) | ||
101 | } | ||
102 | |||
84 | async function processCreateVideoComment (activity: ActivityCreate, byActor: MActorSignature, notify: boolean) { | 103 | async function processCreateVideoComment (activity: ActivityCreate, byActor: MActorSignature, notify: boolean) { |
85 | const commentObject = activity.object as VideoCommentObject | 104 | const commentObject = activity.object as VideoCommentObject |
86 | const byAccount = byActor.Account | 105 | const byAccount = byActor.Account |