aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/users.ts')
-rw-r--r--server/controllers/api/users.ts11
1 files changed, 8 insertions, 3 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index 57b98b84a..6c24434f2 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -1,12 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import { extname, join } from 'path' 2import { extname, join } from 'path'
3import * as sharp from 'sharp'
3import * as uuidv4 from 'uuid/v4' 4import * as uuidv4 from 'uuid/v4'
4import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' 5import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared'
5import { renamePromise } from '../../helpers/core-utils' 6import { renamePromise, unlinkPromise } from '../../helpers/core-utils'
6import { retryTransactionWrapper } from '../../helpers/database-utils' 7import { retryTransactionWrapper } from '../../helpers/database-utils'
7import { logger } from '../../helpers/logger' 8import { logger } from '../../helpers/logger'
8import { createReqFiles, getFormattedObjects } from '../../helpers/utils' 9import { createReqFiles, getFormattedObjects } from '../../helpers/utils'
9import { AVATAR_MIMETYPE_EXT, CONFIG, sequelizeTypescript } from '../../initializers' 10import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers'
10import { createUserAccountAndChannel } from '../../lib/user' 11import { createUserAccountAndChannel } from '../../lib/user'
11import { 12import {
12 asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setPagination, setUsersSort, 13 asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setPagination, setUsersSort,
@@ -239,7 +240,11 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next
239 const avatarName = uuidv4() + extension 240 const avatarName = uuidv4() + extension
240 const destination = join(avatarDir, avatarName) 241 const destination = join(avatarDir, avatarName)
241 242
242 await renamePromise(source, destination) 243 await sharp(source)
244 .resize(AVATARS_SIZE.width, AVATARS_SIZE.height)
245 .toFile(destination)
246
247 await unlinkPromise(source)
243 248
244 const { avatar } = await sequelizeTypescript.transaction(async t => { 249 const { avatar } = await sequelizeTypescript.transaction(async t => {
245 const avatar = await AvatarModel.create({ 250 const avatar = await AvatarModel.create({