diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/users.ts | 11 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { extname, join } from 'path' | 2 | import { extname, join } from 'path' |
3 | import * as sharp from 'sharp' | ||
3 | import * as uuidv4 from 'uuid/v4' | 4 | import * as uuidv4 from 'uuid/v4' |
4 | import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' | 5 | import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' |
5 | import { renamePromise } from '../../helpers/core-utils' | 6 | import { renamePromise, unlinkPromise } from '../../helpers/core-utils' |
6 | import { retryTransactionWrapper } from '../../helpers/database-utils' | 7 | import { retryTransactionWrapper } from '../../helpers/database-utils' |
7 | import { logger } from '../../helpers/logger' | 8 | import { logger } from '../../helpers/logger' |
8 | import { createReqFiles, getFormattedObjects } from '../../helpers/utils' | 9 | import { createReqFiles, getFormattedObjects } from '../../helpers/utils' |
9 | import { AVATAR_MIMETYPE_EXT, CONFIG, sequelizeTypescript } from '../../initializers' | 10 | import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers' |
10 | import { createUserAccountAndChannel } from '../../lib/user' | 11 | import { createUserAccountAndChannel } from '../../lib/user' |
11 | import { | 12 | import { |
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({ |