aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/activitypub/inbox.ts2
-rw-r--r--server/controllers/activitypub/outbox.ts2
-rw-r--r--server/controllers/api/users.ts11
-rw-r--r--server/initializers/constants.ts5
-rw-r--r--server/middlewares/validators/users.ts3
-rw-r--r--server/models/server/server.ts2
-rw-r--r--server/models/video/video-comment.ts2
-rw-r--r--server/tests/api/fixtures/avatar-resized.pngbin0 -> 2420 bytes
-rw-r--r--server/tests/api/users/users.ts2
9 files changed, 19 insertions, 10 deletions
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts
index bfcb7b369..8d65639f8 100644
--- a/server/controllers/activitypub/inbox.ts
+++ b/server/controllers/activitypub/inbox.ts
@@ -16,7 +16,7 @@ inboxRouter.post('/inbox',
16 asyncMiddleware(inboxController) 16 asyncMiddleware(inboxController)
17) 17)
18 18
19inboxRouter.post('/account/:name/inbox', 19inboxRouter.post('/accounts/:name/inbox',
20 signatureValidator, 20 signatureValidator,
21 asyncMiddleware(checkSignature), 21 asyncMiddleware(checkSignature),
22 localAccountValidator, 22 localAccountValidator,
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts
index 01ba253c6..620f9ee83 100644
--- a/server/controllers/activitypub/outbox.ts
+++ b/server/controllers/activitypub/outbox.ts
@@ -11,7 +11,7 @@ import { VideoModel } from '../../models/video/video'
11 11
12const outboxRouter = express.Router() 12const outboxRouter = express.Router()
13 13
14outboxRouter.get('/account/:name/outbox', 14outboxRouter.get('/accounts/:name/outbox',
15 localAccountValidator, 15 localAccountValidator,
16 asyncMiddleware(outboxController) 16 asyncMiddleware(outboxController)
17) 17)
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({
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index aefb91537..d9b21b389 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -316,6 +316,10 @@ const PREVIEWS_SIZE = {
316 width: 560, 316 width: 560,
317 height: 315 317 height: 315
318} 318}
319const AVATARS_SIZE = {
320 width: 120,
321 height: 120
322}
319 323
320const EMBED_SIZE = { 324const EMBED_SIZE = {
321 width: 560, 325 width: 560,
@@ -355,6 +359,7 @@ CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WE
355 359
356export { 360export {
357 API_VERSION, 361 API_VERSION,
362 AVATARS_SIZE,
358 ACCEPT_HEADERS, 363 ACCEPT_HEADERS,
359 BCRYPT_SALT_SIZE, 364 BCRYPT_SALT_SIZE,
360 CACHE, 365 CACHE,
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 7de3e442c..d22a745b4 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -12,7 +12,6 @@ import { isSignupAllowed } from '../../helpers/utils'
12import { CONSTRAINTS_FIELDS } from '../../initializers' 12import { CONSTRAINTS_FIELDS } from '../../initializers'
13import { UserModel } from '../../models/account/user' 13import { UserModel } from '../../models/account/user'
14import { areValidationErrors } from './utils' 14import { areValidationErrors } from './utils'
15import Multer = require('multer')
16 15
17const usersAddValidator = [ 16const usersAddValidator = [
18 body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), 17 body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'),
@@ -105,7 +104,7 @@ const usersUpdateMyAvatarValidator = [
105 ), 104 ),
106 105
107 (req: express.Request, res: express.Response, next: express.NextFunction) => { 106 (req: express.Request, res: express.Response, next: express.NextFunction) => {
108 logger.debug('Checking usersUpdateMyAvatarValidator parameters', { parameters: req.body }) 107 logger.debug('Checking usersUpdateMyAvatarValidator parameters', { files: req.files })
109 108
110 if (areValidationErrors(req, res)) return 109 if (areValidationErrors(req, res)) return
111 110
diff --git a/server/models/server/server.ts b/server/models/server/server.ts
index 122e5f74f..d35aa0ca4 100644
--- a/server/models/server/server.ts
+++ b/server/models/server/server.ts
@@ -27,7 +27,7 @@ export class ServerModel extends Model<ServerModel> {
27 @AllowNull(false) 27 @AllowNull(false)
28 @Default(SERVERS_SCORE.BASE) 28 @Default(SERVERS_SCORE.BASE)
29 @IsInt 29 @IsInt
30 @Max(SERVERS_SCORE.max) 30 @Max(SERVERS_SCORE.MAX)
31 @Column 31 @Column
32 score: number 32 score: number
33 33
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 829022a51..63675c20b 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -214,7 +214,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
214 214
215 static listThreadCommentsForApi (videoId: number, threadId: number) { 215 static listThreadCommentsForApi (videoId: number, threadId: number) {
216 const query = { 216 const query = {
217 order: [ [ 'createdAt', 'DESC' ] ], 217 order: [ [ 'createdAt', 'ASC' ] ],
218 where: { 218 where: {
219 videoId, 219 videoId,
220 [ Sequelize.Op.or ]: [ 220 [ Sequelize.Op.or ]: [
diff --git a/server/tests/api/fixtures/avatar-resized.png b/server/tests/api/fixtures/avatar-resized.png
new file mode 100644
index 000000000..e05fc07ce
--- /dev/null
+++ b/server/tests/api/fixtures/avatar-resized.png
Binary files differ
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 3390b2d56..f7e5972d3 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -352,7 +352,7 @@ describe('Test users', function () {
352 const res = await getMyUserInformation(server.url, accessTokenUser) 352 const res = await getMyUserInformation(server.url, accessTokenUser)
353 const user = res.body 353 const user = res.body
354 354
355 const test = await testVideoImage(server.url, 'avatar', user.account.avatar.path, '.png') 355 const test = await testVideoImage(server.url, 'avatar-resized', user.account.avatar.path, '.png')
356 expect(test).to.equal(true) 356 expect(test).to.equal(true)
357 }) 357 })
358 358