aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/stats.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos/stats.ts')
-rw-r--r--server/controllers/api/videos/stats.ts17
1 files changed, 15 insertions, 2 deletions
diff --git a/server/controllers/api/videos/stats.ts b/server/controllers/api/videos/stats.ts
index 5f8513e9e..71452d9f0 100644
--- a/server/controllers/api/videos/stats.ts
+++ b/server/controllers/api/videos/stats.ts
@@ -1,6 +1,6 @@
1import express from 'express' 1import express from 'express'
2import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer' 2import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer'
3import { VideoStatsTimeserieMetric } from '@shared/models' 3import { VideoStatsTimeserieMetric, VideoStatsTimeserieQuery } from '@shared/models'
4import { 4import {
5 asyncMiddleware, 5 asyncMiddleware,
6 authenticate, 6 authenticate,
@@ -57,10 +57,23 @@ async function getTimeserieStats (req: express.Request, res: express.Response) {
57 const video = res.locals.videoAll 57 const video = res.locals.videoAll
58 const metric = req.params.metric as VideoStatsTimeserieMetric 58 const metric = req.params.metric as VideoStatsTimeserieMetric
59 59
60 const query = req.query as VideoStatsTimeserieQuery
61
60 const stats = await LocalVideoViewerModel.getTimeserieStats({ 62 const stats = await LocalVideoViewerModel.getTimeserieStats({
61 video, 63 video,
62 metric 64 metric,
65 startDate: query.startDate ?? buildOneMonthAgo().toISOString(),
66 endDate: query.endDate ?? new Date().toISOString()
63 }) 67 })
64 68
65 return res.json(stats) 69 return res.json(stats)
66} 70}
71
72function buildOneMonthAgo () {
73 const monthAgo = new Date()
74 monthAgo.setHours(0, 0, 0, 0)
75
76 monthAgo.setDate(monthAgo.getDate() - 29)
77
78 return monthAgo
79}