mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
server/server -> server/core
This commit is contained in:
parent
114327d4ce
commit
5a3d0650c9
838 changed files with 111 additions and 111 deletions
75
server/core/controllers/api/videos/stats.ts
Normal file
75
server/core/controllers/api/videos/stats.ts
Normal file
|
@ -0,0 +1,75 @@
|
|||
import express from 'express'
|
||||
import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer.js'
|
||||
import { VideoStatsOverallQuery, VideoStatsTimeserieMetric, VideoStatsTimeserieQuery } from '@peertube/peertube-models'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
authenticate,
|
||||
videoOverallStatsValidator,
|
||||
videoRetentionStatsValidator,
|
||||
videoTimeserieStatsValidator
|
||||
} from '../../../middlewares/index.js'
|
||||
|
||||
const statsRouter = express.Router()
|
||||
|
||||
statsRouter.get('/:videoId/stats/overall',
|
||||
authenticate,
|
||||
asyncMiddleware(videoOverallStatsValidator),
|
||||
asyncMiddleware(getOverallStats)
|
||||
)
|
||||
|
||||
statsRouter.get('/:videoId/stats/timeseries/:metric',
|
||||
authenticate,
|
||||
asyncMiddleware(videoTimeserieStatsValidator),
|
||||
asyncMiddleware(getTimeserieStats)
|
||||
)
|
||||
|
||||
statsRouter.get('/:videoId/stats/retention',
|
||||
authenticate,
|
||||
asyncMiddleware(videoRetentionStatsValidator),
|
||||
asyncMiddleware(getRetentionStats)
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
statsRouter
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function getOverallStats (req: express.Request, res: express.Response) {
|
||||
const video = res.locals.videoAll
|
||||
const query = req.query as VideoStatsOverallQuery
|
||||
|
||||
const stats = await LocalVideoViewerModel.getOverallStats({
|
||||
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
|
||||
|
||||
const stats = await LocalVideoViewerModel.getRetentionStats(video)
|
||||
|
||||
return res.json(stats)
|
||||
}
|
||||
|
||||
async function getTimeserieStats (req: express.Request, res: express.Response) {
|
||||
const video = res.locals.videoAll
|
||||
const metric = req.params.metric as VideoStatsTimeserieMetric
|
||||
|
||||
const query = req.query as VideoStatsTimeserieQuery
|
||||
|
||||
const stats = await LocalVideoViewerModel.getTimeserieStats({
|
||||
video,
|
||||
metric,
|
||||
startDate: query.startDate ?? video.createdAt.toISOString(),
|
||||
endDate: query.endDate ?? new Date().toISOString()
|
||||
})
|
||||
|
||||
return res.json(stats)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue