import * as uuidv4 from 'uuid/v4'
import * as RateLimit from 'express-rate-limit'
import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared'
-import { retryTransactionWrapper } from '../../helpers/database-utils'
import { processImage } from '../../helpers/image-utils'
import { logger } from '../../helpers/logger'
import { getFormattedObjects } from '../../helpers/utils'
import { createUserAccountAndChannel } from '../../lib/user'
import {
asyncMiddleware,
+ asyncRetryTransactionMiddleware,
authenticate,
ensureUserHasRight,
ensureUserRegistrationAllowed,
authenticate,
ensureUserHasRight(UserRight.MANAGE_USERS),
asyncMiddleware(usersAddValidator),
- asyncMiddleware(createUserRetryWrapper)
+ asyncRetryTransactionMiddleware(createUser)
)
usersRouter.post('/register',
asyncMiddleware(ensureUserRegistrationAllowed),
ensureUserRegistrationAllowedForIP,
asyncMiddleware(usersRegisterValidator),
- asyncMiddleware(registerUserRetryWrapper)
+ asyncRetryTransactionMiddleware(registerUser)
)
usersRouter.put('/me',
false // Display my NSFW videos
)
- const additionalAttributes = { waitTranscoding: true, state: true }
- return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes }))
-}
-
-async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
- const options = {
- arguments: [ req ],
- errorMessage: 'Cannot insert the user with many retries.'
+ const additionalAttributes = {
+ waitTranscoding: true,
+ state: true,
+ scheduledUpdate: true
}
-
- const { user, account } = await retryTransactionWrapper(createUser, options)
-
- return res.json({
- user: {
- id: user.id,
- account: {
- id: account.id,
- uuid: account.Actor.uuid
- }
- }
- }).end()
+ return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes }))
}
-async function createUser (req: express.Request) {
+async function createUser (req: express.Request, res: express.Response) {
const body: UserCreate = req.body
const userToCreate = new UserModel({
username: body.username,
logger.info('User %s with its channel and account created.', body.username)
- return { user, account }
-}
-
-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()
+ return res.json({
+ user: {
+ id: user.id,
+ account: {
+ id: account.id,
+ uuid: account.Actor.uuid
+ }
+ }
+ }).end()
}
-async function registerUser (req: express.Request) {
+async function registerUser (req: express.Request, res: express.Response) {
const body: UserCreate = req.body
const user = new UserModel({
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) {