aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-03 11:36:03 +0100
committerChocobozzz <me@florianbigard.com>2018-01-03 11:36:03 +0100
commite8e122002d5a6a2bedcf3d66d35657c9b9e1ebaf (patch)
treec29952bef32c5e95c9409724f12d902dcdd8d39e /server/controllers/api
parent01de67b9a4fcdf01102ccc3cb7dc24beebf6c7ea (diff)
downloadPeerTube-e8e122002d5a6a2bedcf3d66d35657c9b9e1ebaf.tar.gz
PeerTube-e8e122002d5a6a2bedcf3d66d35657c9b9e1ebaf.tar.zst
PeerTube-e8e122002d5a6a2bedcf3d66d35657c9b9e1ebaf.zip
Automatically resize avatars
Diffstat (limited to 'server/controllers/api')
-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({