Automatically resize avatars
This commit is contained in:
parent
01de67b9a4
commit
e8e122002d
12 changed files with 27 additions and 11 deletions
|
@ -114,6 +114,7 @@
|
||||||
"@types/request": "^2.0.3",
|
"@types/request": "^2.0.3",
|
||||||
"@types/sanitize-html": "^1.14.0",
|
"@types/sanitize-html": "^1.14.0",
|
||||||
"@types/sequelize": "^4.0.55",
|
"@types/sequelize": "^4.0.55",
|
||||||
|
"@types/sharp": "^0.17.6",
|
||||||
"@types/supertest": "^2.0.3",
|
"@types/supertest": "^2.0.3",
|
||||||
"@types/validator": "^6.2.0",
|
"@types/validator": "^6.2.0",
|
||||||
"@types/webtorrent": "^0.98.4",
|
"@types/webtorrent": "^0.98.4",
|
||||||
|
|
|
@ -164,7 +164,7 @@ function onDatabaseInitDone () {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// ----------- Make the server listening -----------
|
// ----------- Make the server listening -----------
|
||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.FILE_SIZE)
|
VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE)
|
||||||
activitypubHttpJobScheduler.activate()
|
activitypubHttpJobScheduler.activate()
|
||||||
transcodingJobScheduler.activate()
|
transcodingJobScheduler.activate()
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ inboxRouter.post('/inbox',
|
||||||
asyncMiddleware(inboxController)
|
asyncMiddleware(inboxController)
|
||||||
)
|
)
|
||||||
|
|
||||||
inboxRouter.post('/account/:name/inbox',
|
inboxRouter.post('/accounts/:name/inbox',
|
||||||
signatureValidator,
|
signatureValidator,
|
||||||
asyncMiddleware(checkSignature),
|
asyncMiddleware(checkSignature),
|
||||||
localAccountValidator,
|
localAccountValidator,
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { VideoModel } from '../../models/video/video'
|
||||||
|
|
||||||
const outboxRouter = express.Router()
|
const outboxRouter = express.Router()
|
||||||
|
|
||||||
outboxRouter.get('/account/:name/outbox',
|
outboxRouter.get('/accounts/:name/outbox',
|
||||||
localAccountValidator,
|
localAccountValidator,
|
||||||
asyncMiddleware(outboxController)
|
asyncMiddleware(outboxController)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { extname, join } from 'path'
|
import { extname, join } from 'path'
|
||||||
|
import * as sharp from 'sharp'
|
||||||
import * as uuidv4 from 'uuid/v4'
|
import * as uuidv4 from 'uuid/v4'
|
||||||
import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared'
|
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 { retryTransactionWrapper } from '../../helpers/database-utils'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { createReqFiles, getFormattedObjects } from '../../helpers/utils'
|
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 { createUserAccountAndChannel } from '../../lib/user'
|
||||||
import {
|
import {
|
||||||
asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setPagination, setUsersSort,
|
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 avatarName = uuidv4() + extension
|
||||||
const destination = join(avatarDir, avatarName)
|
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 sequelizeTypescript.transaction(async t => {
|
||||||
const avatar = await AvatarModel.create({
|
const avatar = await AvatarModel.create({
|
||||||
|
|
|
@ -316,6 +316,10 @@ const PREVIEWS_SIZE = {
|
||||||
width: 560,
|
width: 560,
|
||||||
height: 315
|
height: 315
|
||||||
}
|
}
|
||||||
|
const AVATARS_SIZE = {
|
||||||
|
width: 120,
|
||||||
|
height: 120
|
||||||
|
}
|
||||||
|
|
||||||
const EMBED_SIZE = {
|
const EMBED_SIZE = {
|
||||||
width: 560,
|
width: 560,
|
||||||
|
@ -355,6 +359,7 @@ CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WE
|
||||||
|
|
||||||
export {
|
export {
|
||||||
API_VERSION,
|
API_VERSION,
|
||||||
|
AVATARS_SIZE,
|
||||||
ACCEPT_HEADERS,
|
ACCEPT_HEADERS,
|
||||||
BCRYPT_SALT_SIZE,
|
BCRYPT_SALT_SIZE,
|
||||||
CACHE,
|
CACHE,
|
||||||
|
|
|
@ -12,7 +12,6 @@ import { isSignupAllowed } from '../../helpers/utils'
|
||||||
import { CONSTRAINTS_FIELDS } from '../../initializers'
|
import { CONSTRAINTS_FIELDS } from '../../initializers'
|
||||||
import { UserModel } from '../../models/account/user'
|
import { UserModel } from '../../models/account/user'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import Multer = require('multer')
|
|
||||||
|
|
||||||
const usersAddValidator = [
|
const usersAddValidator = [
|
||||||
body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'),
|
body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'),
|
||||||
|
@ -105,7 +104,7 @@ const usersUpdateMyAvatarValidator = [
|
||||||
),
|
),
|
||||||
|
|
||||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
logger.debug('Checking usersUpdateMyAvatarValidator parameters', { parameters: req.body })
|
logger.debug('Checking usersUpdateMyAvatarValidator parameters', { files: req.files })
|
||||||
|
|
||||||
if (areValidationErrors(req, res)) return
|
if (areValidationErrors(req, res)) return
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ export class ServerModel extends Model<ServerModel> {
|
||||||
@AllowNull(false)
|
@AllowNull(false)
|
||||||
@Default(SERVERS_SCORE.BASE)
|
@Default(SERVERS_SCORE.BASE)
|
||||||
@IsInt
|
@IsInt
|
||||||
@Max(SERVERS_SCORE.max)
|
@Max(SERVERS_SCORE.MAX)
|
||||||
@Column
|
@Column
|
||||||
score: number
|
score: number
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
|
||||||
|
|
||||||
static listThreadCommentsForApi (videoId: number, threadId: number) {
|
static listThreadCommentsForApi (videoId: number, threadId: number) {
|
||||||
const query = {
|
const query = {
|
||||||
order: [ [ 'createdAt', 'DESC' ] ],
|
order: [ [ 'createdAt', 'ASC' ] ],
|
||||||
where: {
|
where: {
|
||||||
videoId,
|
videoId,
|
||||||
[ Sequelize.Op.or ]: [
|
[ Sequelize.Op.or ]: [
|
||||||
|
|
BIN
server/tests/api/fixtures/avatar-resized.png
Normal file
BIN
server/tests/api/fixtures/avatar-resized.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
|
@ -352,7 +352,7 @@ describe('Test users', function () {
|
||||||
const res = await getMyUserInformation(server.url, accessTokenUser)
|
const res = await getMyUserInformation(server.url, accessTokenUser)
|
||||||
const user = res.body
|
const user = res.body
|
||||||
|
|
||||||
const test = await testVideoImage(server.url, 'avatar', user.account.avatar.path, '.png')
|
const test = await testVideoImage(server.url, 'avatar-resized', user.account.avatar.path, '.png')
|
||||||
expect(test).to.equal(true)
|
expect(test).to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -170,6 +170,12 @@
|
||||||
"@types/express-serve-static-core" "*"
|
"@types/express-serve-static-core" "*"
|
||||||
"@types/mime" "*"
|
"@types/mime" "*"
|
||||||
|
|
||||||
|
"@types/sharp@^0.17.6":
|
||||||
|
version "0.17.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/sharp/-/sharp-0.17.6.tgz#3138602163b30b4969f75a2755a3f90caaaa9be3"
|
||||||
|
dependencies:
|
||||||
|
"@types/node" "*"
|
||||||
|
|
||||||
"@types/simple-peer@*":
|
"@types/simple-peer@*":
|
||||||
version "6.1.4"
|
version "6.1.4"
|
||||||
resolved "https://registry.yarnpkg.com/@types/simple-peer/-/simple-peer-6.1.4.tgz#1d1384e1d8dc17b9e7d1673d704febe91ca48191"
|
resolved "https://registry.yarnpkg.com/@types/simple-peer/-/simple-peer-6.1.4.tgz#1d1384e1d8dc17b9e7d1673d704febe91ca48191"
|
||||||
|
|
Loading…
Reference in a new issue