mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
add user agent video stats (#6871)
* add user agent video stats closes #6832 * Disable indexes, support start/end dates * move ua parsing to client * Openapi, inline body request, update tests --------- Co-authored-by: Chocobozzz <me@florianbigard.com>
This commit is contained in:
parent
96380859ef
commit
a7be820abc
29 changed files with 765 additions and 147 deletions
|
@ -1,34 +1,49 @@
|
|||
import express from 'express'
|
||||
import {
|
||||
VideoStatsOverallQuery,
|
||||
VideoStatsTimeserieMetric,
|
||||
VideoStatsTimeserieQuery,
|
||||
VideoStatsUserAgentQuery
|
||||
} from '@peertube/peertube-models'
|
||||
import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer.js'
|
||||
import { VideoStatsOverallQuery, VideoStatsTimeserieMetric, VideoStatsTimeserieQuery } from '@peertube/peertube-models'
|
||||
import express from 'express'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
authenticate,
|
||||
videoOverallStatsValidator,
|
||||
videoOverallOrUserAgentStatsValidator,
|
||||
videoRetentionStatsValidator,
|
||||
videoTimeserieStatsValidator
|
||||
videoTimeseriesStatsValidator
|
||||
} from '../../../middlewares/index.js'
|
||||
|
||||
const statsRouter = express.Router()
|
||||
|
||||
statsRouter.get('/:videoId/stats/overall',
|
||||
statsRouter.get(
|
||||
'/:videoId/stats/overall',
|
||||
authenticate,
|
||||
asyncMiddleware(videoOverallStatsValidator),
|
||||
asyncMiddleware(videoOverallOrUserAgentStatsValidator),
|
||||
asyncMiddleware(getOverallStats)
|
||||
)
|
||||
|
||||
statsRouter.get('/:videoId/stats/timeseries/:metric',
|
||||
statsRouter.get(
|
||||
'/:videoId/stats/timeseries/:metric',
|
||||
authenticate,
|
||||
asyncMiddleware(videoTimeserieStatsValidator),
|
||||
asyncMiddleware(getTimeserieStats)
|
||||
asyncMiddleware(videoTimeseriesStatsValidator),
|
||||
asyncMiddleware(getTimeseriesStats)
|
||||
)
|
||||
|
||||
statsRouter.get('/:videoId/stats/retention',
|
||||
statsRouter.get(
|
||||
'/:videoId/stats/retention',
|
||||
authenticate,
|
||||
asyncMiddleware(videoRetentionStatsValidator),
|
||||
asyncMiddleware(getRetentionStats)
|
||||
)
|
||||
|
||||
statsRouter.get(
|
||||
'/:videoId/stats/user-agent',
|
||||
authenticate,
|
||||
asyncMiddleware(videoOverallOrUserAgentStatsValidator),
|
||||
asyncMiddleware(getUserAgentStats)
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
|
@ -50,6 +65,19 @@ async function getOverallStats (req: express.Request, res: express.Response) {
|
|||
return res.json(stats)
|
||||
}
|
||||
|
||||
async function getUserAgentStats (req: express.Request, res: express.Response) {
|
||||
const video = res.locals.videoAll
|
||||
const query = req.query as VideoStatsUserAgentQuery
|
||||
|
||||
const stats = await LocalVideoViewerModel.getUserAgentStats({
|
||||
video,
|
||||
startDate: query.startDate,
|
||||
endDate: query.endDate
|
||||
})
|
||||
|
||||
return res.json(stats)
|
||||
}
|
||||
|
||||
async function getRetentionStats (req: express.Request, res: express.Response) {
|
||||
const video = res.locals.videoAll
|
||||
|
||||
|
@ -58,7 +86,7 @@ async function getRetentionStats (req: express.Request, res: express.Response) {
|
|||
return res.json(stats)
|
||||
}
|
||||
|
||||
async function getTimeserieStats (req: express.Request, res: express.Response) {
|
||||
async function getTimeseriesStats (req: express.Request, res: express.Response) {
|
||||
const video = res.locals.videoAll
|
||||
const metric = req.params.metric as VideoStatsTimeserieMetric
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import express from 'express'
|
||||
import { HttpStatusCode, VideoView } from '@peertube/peertube-models'
|
||||
import { Hooks } from '@server/lib/plugins/hooks.js'
|
||||
import { VideoViewsManager } from '@server/lib/views/video-views-manager.js'
|
||||
import { MVideoId } from '@server/types/models/index.js'
|
||||
import express from 'express'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
methodsValidator,
|
||||
|
@ -35,14 +35,17 @@ async function viewVideo (req: express.Request, res: express.Response) {
|
|||
const video = res.locals.onlyImmutableVideo
|
||||
|
||||
const body = req.body as VideoView
|
||||
|
||||
const ip = req.ip
|
||||
|
||||
const { successView } = await VideoViewsManager.Instance.processLocalView({
|
||||
video,
|
||||
ip,
|
||||
currentTime: body.currentTime,
|
||||
viewEvent: body.viewEvent,
|
||||
sessionId: body.sessionId
|
||||
sessionId: body.sessionId,
|
||||
client: body.client,
|
||||
operatingSystem: body.operatingSystem,
|
||||
device: body.device
|
||||
})
|
||||
|
||||
if (successView) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue