aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-04-07 10:53:35 +0200
committerChocobozzz <chocobozzz@cpy.re>2022-04-15 09:49:35 +0200
commit901bcf5c188ea79350fecd499ad76460b866617b (patch)
tree1e79f26cc3f2b952371d31bfa9b94a2b150be38a /server/controllers/api
parentac907dc7c158056e9b6a5cb58acd27df5c7c2670 (diff)
downloadPeerTube-901bcf5c188ea79350fecd499ad76460b866617b.tar.gz
PeerTube-901bcf5c188ea79350fecd499ad76460b866617b.tar.zst
PeerTube-901bcf5c188ea79350fecd499ad76460b866617b.zip
Add ability to set start/end date to timeserie
Diffstat (limited to 'server/controllers/api')
-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}