import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../../initializers/constants'
import { cacheRoute } from '../../../middlewares/cache'
+import { VideoFileModel } from '../../../models/video/video-file'
const statsRouter = express.Router()
asyncMiddleware(getStats)
)
-async function getStats (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function getStats (req: express.Request, res: express.Response) {
const { totalLocalVideos, totalLocalVideoViews, totalVideos } = await VideoModel.getStats()
const { totalLocalVideoComments, totalVideoComments } = await VideoCommentModel.getStats()
const { totalUsers } = await UserModel.getStats()
const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats()
+ const { totalLocalVideoFilesSize } = await VideoFileModel.getStats()
const videosRedundancyStats = await Promise.all(
CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.map(r => {
const data: ServerStats = {
totalLocalVideos,
totalLocalVideoViews,
- totalVideos,
+ totalLocalVideoFilesSize,
totalLocalVideoComments,
+ totalVideos,
totalVideoComments,
totalUsers,
totalInstanceFollowers,
]
}
- return VideoRedundancyModel.find(query as any) // FIXME: typings
+ return VideoRedundancyModel.findOne(query as any) // FIXME: typings
.then((r: any) => ({
totalUsed: parseInt(r.totalUsed.toString(), 10),
totalVideos: r.totalVideos,
return VideoFileModel.findById(id, options)
}
+ static async getStats () {
+ let totalLocalVideoFilesSize = await VideoFileModel.sum('size', {
+ include: [
+ {
+ attributes: [],
+ model: VideoModel.unscoped(),
+ where: {
+ remote: false
+ }
+ }
+ ]
+ } as any)
+ // Sequelize could return null...
+ if (!totalLocalVideoFilesSize) totalLocalVideoFilesSize = 0
+
+ return {
+ totalLocalVideoFilesSize
+ }
+ }
+
hasSameUniqueKeysThan (other: VideoFileModel) {
return this.fps === other.fps &&
this.resolution === other.resolution &&
}
await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
- const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, {})
+ const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
const videoUUID = resVideo.body.video.uuid
await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment')
expect(data.totalLocalVideoComments).to.equal(1)
expect(data.totalLocalVideos).to.equal(1)
expect(data.totalLocalVideoViews).to.equal(1)
+ expect(data.totalLocalVideoFilesSize).to.equal(218910)
expect(data.totalUsers).to.equal(2)
expect(data.totalVideoComments).to.equal(1)
expect(data.totalVideos).to.equal(1)
totalLocalVideos: number
totalLocalVideoViews: number
totalLocalVideoComments: number
+ totalLocalVideoFilesSize: number
totalVideos: number
totalVideoComments: number