X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fusers.ts;h=5374c4b6afdf1e34e8035d1cdd6d69f26f64a18c;hb=ce5496d6a31b9617aba67970f5dc135e73335234;hp=2d77a52494e0e1cec2813db66da6b164b232a2ae;hpb=108af66140713c4beec681a71d360ab788226528;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 2d77a5249..5374c4b6a 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -30,6 +30,11 @@ usersRouter.get('/me', asyncMiddleware(getUserInformation) ) +usersRouter.get('/me/video-quota-used', + authenticate, + asyncMiddleware(getUserVideoQuotaUsed) +) + usersRouter.get('/me/videos', authenticate, paginationValidator, @@ -183,8 +188,18 @@ async function getUserInformation (req: express.Request, res: express.Response, return res.json(user.toFormattedJSON()) } +async function getUserVideoQuotaUsed (req: express.Request, res: express.Response, next: express.NextFunction) { + // We did not load channels in res.locals.user + const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) + const videoQuotaUsed = await UserModel.getOriginalVideoFileTotalFromUser(user) + + return res.json({ + videoQuotaUsed + }) +} + function getUser (req: express.Request, res: express.Response, next: express.NextFunction) { - return res.json(res.locals.user.toFormattedJSON()) + return res.json((res.locals.user as UserModel).toFormattedJSON()) } async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) {