]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/server/stats.ts
Add error when email system is not configured and using the forgot
[github/Chocobozzz/PeerTube.git] / server / controllers / api / server / stats.ts
index 6f4fe938c3c99a31d63641db029270ae0d9f9088..85803f69ee87e4559f4dbe56bf14f1688122e649 100644 (file)
@@ -5,10 +5,14 @@ import { UserModel } from '../../../models/account/user'
 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
 import { VideoModel } from '../../../models/video/video'
 import { VideoCommentModel } from '../../../models/video/video-comment'
+import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
+import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../../initializers/constants'
+import { cacheRoute } from '../../../middlewares/cache'
 
 const statsRouter = express.Router()
 
 statsRouter.get('/stats',
+  asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.STATS)),
   asyncMiddleware(getStats)
 )
 
@@ -18,6 +22,13 @@ async function getStats (req: express.Request, res: express.Response, next: expr
   const { totalUsers } = await UserModel.getStats()
   const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats()
 
+  const videosRedundancyStats = await Promise.all(
+    CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.map(r => {
+      return VideoRedundancyModel.getStats(r.strategy)
+        .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size }))
+    })
+  )
+
   const data: ServerStats = {
     totalLocalVideos,
     totalLocalVideoViews,
@@ -26,7 +37,8 @@ async function getStats (req: express.Request, res: express.Response, next: expr
     totalVideoComments,
     totalUsers,
     totalInstanceFollowers,
-    totalInstanceFollowing
+    totalInstanceFollowing,
+    videosRedundancy: videosRedundancyStats
   }
 
   return res.json(data).end()