1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

Automatically resize avatars

This commit is contained in:
Chocobozzz 2018-01-03 11:36:03 +01:00
parent 01de67b9a4
commit e8e122002d
No known key found for this signature in database
GPG key ID: 583A612D890159BE
12 changed files with 27 additions and 11 deletions

View file

@ -1,12 +1,13 @@
import * as express from 'express'
import { extname, join } from 'path'
import * as sharp from 'sharp'
import * as uuidv4 from 'uuid/v4'
import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared'
import { renamePromise } from '../../helpers/core-utils'
import { renamePromise, unlinkPromise } from '../../helpers/core-utils'
import { retryTransactionWrapper } from '../../helpers/database-utils'
import { logger } from '../../helpers/logger'
import { createReqFiles, getFormattedObjects } from '../../helpers/utils'
import { AVATAR_MIMETYPE_EXT, CONFIG, sequelizeTypescript } from '../../initializers'
import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers'
import { createUserAccountAndChannel } from '../../lib/user'
import {
asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setPagination, setUsersSort,
@ -239,7 +240,11 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next
const avatarName = uuidv4() + extension
const destination = join(avatarDir, avatarName)
await renamePromise(source, destination)
await sharp(source)
.resize(AVATARS_SIZE.width, AVATARS_SIZE.height)
.toFile(destination)
await unlinkPromise(source)
const { avatar } = await sequelizeTypescript.transaction(async t => {
const avatar = await AvatarModel.create({