diff options
author | Chocobozzz <me@florianbigard.com> | 2022-04-07 10:53:35 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-04-15 09:49:35 +0200 |
commit | 901bcf5c188ea79350fecd499ad76460b866617b (patch) | |
tree | 1e79f26cc3f2b952371d31bfa9b94a2b150be38a /server/controllers/api/videos | |
parent | ac907dc7c158056e9b6a5cb58acd27df5c7c2670 (diff) | |
download | PeerTube-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/videos')
-rw-r--r-- | server/controllers/api/videos/stats.ts | 17 |
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 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer' | 2 | import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer' |
3 | import { VideoStatsTimeserieMetric } from '@shared/models' | 3 | import { VideoStatsTimeserieMetric, VideoStatsTimeserieQuery } from '@shared/models' |
4 | import { | 4 | import { |
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 | |||
72 | function 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 | } | ||