]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/users.ts
Federate video views
[github/Chocobozzz/PeerTube.git] / server / controllers / api / users.ts
index 41ffb64cb202868e878188f49d86ce562032b803..ac7c87517d8d0e9458f4c450edacba9d9aa433db 100644 (file)
@@ -70,7 +70,7 @@ usersRouter.post('/',
 usersRouter.post('/register',
   ensureUserRegistrationAllowed,
   usersRegisterValidator,
-  asyncMiddleware(registerUser)
+  asyncMiddleware(registerUserRetryWrapper)
 )
 
 usersRouter.put('/me',
@@ -113,7 +113,7 @@ async function getUserVideos (req: express.Request, res: express.Response, next:
 
 async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
   const options = {
-    arguments: [ req, res ],
+    arguments: [ req ],
     errorMessage: 'Cannot insert the user with many retries.'
   }
 
@@ -123,7 +123,7 @@ async function createUserRetryWrapper (req: express.Request, res: express.Respon
   return res.type('json').status(204).end()
 }
 
-async function createUser (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function createUser (req: express.Request) {
   const body: UserCreate = req.body
   const user = db.User.build({
     username: body.username,
@@ -139,7 +139,18 @@ async function createUser (req: express.Request, res: express.Response, next: ex
   logger.info('User %s with its channel and account created.', body.username)
 }
 
-async function registerUser (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function registerUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const options = {
+    arguments: [ req ],
+    errorMessage: 'Cannot insert the user with many retries.'
+  }
+
+  await retryTransactionWrapper(registerUser, options)
+
+  return res.type('json').status(204).end()
+}
+
+async function registerUser (req: express.Request) {
   const body: UserCreate = req.body
 
   const user = db.User.build({
@@ -152,7 +163,8 @@ async function registerUser (req: express.Request, res: express.Response, next:
   })
 
   await createUserAccountAndChannel(user)
-  return res.type('json').status(204).end()
+
+  logger.info('User %s with its channel and account registered.', body.username)
 }
 
 async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {