X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fusers.ts;h=89105691267786772d361956f22e92acbff9d327;hb=0c237b19fdf9c614293c1442f0ab95a81ce05735;hp=2b40c44d95887608850a2b0ea556c95952043c66;hpb=2186386cca113506791583cb07d6ccacba7af4e0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 2b40c44d9..891056912 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -4,7 +4,6 @@ import { extname, join } from 'path' 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' @@ -16,6 +15,7 @@ import { Redis } from '../../lib/redis' import { createUserAccountAndChannel } from '../../lib/user' import { asyncMiddleware, + asyncRetryTransactionMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, @@ -102,14 +102,14 @@ usersRouter.post('/', 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', @@ -174,30 +174,15 @@ async function getUserVideos (req: express.Request, res: express.Response, next: 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, @@ -213,21 +198,18 @@ async function createUser (req: express.Request) { 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({ @@ -243,6 +225,8 @@ async function registerUser (req: express.Request) { 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) {