X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fusers.ts;h=ac7c87517d8d0e9458f4c450edacba9d9aa433db;hb=47e0652b4a98916d4a1d012fbec61afd73a30565;hp=41ffb64cb202868e878188f49d86ce562032b803;hpb=571389d43b8fc8aaf27e77c06f19b320b08dbbc9;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 41ffb64cb..ac7c87517 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -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) {