mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
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
This commit is contained in:
parent
69d48ee30c
commit
b211106695
108 changed files with 2834 additions and 655 deletions
51
shared/server-commands/videos/views-command.ts
Normal file
51
shared/server-commands/videos/views-command.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
|
||||
import { HttpStatusCode, VideoViewEvent } from '@shared/models'
|
||||
import { AbstractCommand, OverrideCommandOptions } from '../shared'
|
||||
|
||||
export class ViewsCommand extends AbstractCommand {
|
||||
|
||||
view (options: OverrideCommandOptions & {
|
||||
id: number | string
|
||||
currentTime?: number
|
||||
viewEvent?: VideoViewEvent
|
||||
xForwardedFor?: string
|
||||
}) {
|
||||
const { id, xForwardedFor, viewEvent, currentTime } = options
|
||||
const path = '/api/v1/videos/' + id + '/views'
|
||||
|
||||
return this.postBodyRequest({
|
||||
...options,
|
||||
|
||||
path,
|
||||
xForwardedFor,
|
||||
fields: {
|
||||
currentTime: currentTime ?? 1,
|
||||
viewEvent
|
||||
},
|
||||
implicitToken: false,
|
||||
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||
})
|
||||
}
|
||||
|
||||
async simulateView (options: OverrideCommandOptions & {
|
||||
id: number | string
|
||||
xForwardedFor?: string
|
||||
}) {
|
||||
await this.view({ ...options, currentTime: 0 })
|
||||
await this.view({ ...options, currentTime: 5 })
|
||||
}
|
||||
|
||||
async simulateViewer (options: OverrideCommandOptions & {
|
||||
id: number | string
|
||||
currentTimes: number[]
|
||||
xForwardedFor?: string
|
||||
}) {
|
||||
let viewEvent: VideoViewEvent = 'seek'
|
||||
|
||||
for (const currentTime of options.currentTimes) {
|
||||
await this.view({ ...options, currentTime, viewEvent })
|
||||
|
||||
viewEvent = undefined
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue