-function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
- db.User.loadByUsername(res.locals.oauth.token.user.username)
- .then(user => res.json(user.toFormattedJSON()))
- .catch(err => next(err))
+async function registerUser (req: express.Request, res: express.Response) {
+ const body: UserCreate = req.body
+
+ const user = new UserModel({
+ username: body.username,
+ password: body.password,
+ email: body.email,
+ nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
+ autoPlayVideo: true,
+ role: UserRole.USER,
+ videoQuota: CONFIG.USER.VIDEO_QUOTA
+ })
+
+ await createUserAccountAndChannel(user)
+
+ logger.info('User %s with its channel and account registered.', body.username)
+
+ return res.type('json').status(204).end()
+}
+
+async function getUserInformation (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)
+
+ 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)
+
+ const data: UserVideoQuota = {
+ videoQuotaUsed
+ }
+ return res.json(data)