]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos/stats.ts
Translated using Weblate (Vietnamese)
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / stats.ts
index 5f8513e9e6ad5566b2a254fc86b74206b59a6b94..71452d9f00156f74d123056e68e8ce3285bc885e 100644 (file)
@@ -1,6 +1,6 @@
 import express from 'express'
 import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer'
-import { VideoStatsTimeserieMetric } from '@shared/models'
+import { VideoStatsTimeserieMetric, VideoStatsTimeserieQuery } from '@shared/models'
 import {
   asyncMiddleware,
   authenticate,
@@ -57,10 +57,23 @@ 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
+    metric,
+    startDate: query.startDate ?? buildOneMonthAgo().toISOString(),
+    endDate: query.endDate ?? new Date().toISOString()
   })
 
   return res.json(stats)
 }
+
+function buildOneMonthAgo () {
+  const monthAgo = new Date()
+  monthAgo.setHours(0, 0, 0, 0)
+
+  monthAgo.setDate(monthAgo.getDate() - 29)
+
+  return monthAgo
+}