diff options
Diffstat (limited to 'server/controllers/api/users.ts')
-rw-r--r-- | server/controllers/api/users.ts | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 6e5d09695..e3067584e 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -1,13 +1,13 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'multer' | ||
2 | import { extname, join } from 'path' | 3 | import { extname, join } from 'path' |
3 | import * as sharp from 'sharp' | ||
4 | import * as uuidv4 from 'uuid/v4' | 4 | import * as uuidv4 from 'uuid/v4' |
5 | import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' | 5 | import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' |
6 | import { unlinkPromise } from '../../helpers/core-utils' | ||
7 | import { retryTransactionWrapper } from '../../helpers/database-utils' | 6 | import { retryTransactionWrapper } from '../../helpers/database-utils' |
7 | import { processImage } from '../../helpers/image-utils' | ||
8 | import { logger } from '../../helpers/logger' | 8 | import { logger } from '../../helpers/logger' |
9 | import { createReqFiles, getFormattedObjects } from '../../helpers/utils' | 9 | import { createReqFiles, getFormattedObjects } from '../../helpers/utils' |
10 | import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers' | 10 | import { AVATARS_SIZE, CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers' |
11 | import { updateActorAvatarInstance } from '../../lib/activitypub' | 11 | import { updateActorAvatarInstance } from '../../lib/activitypub' |
12 | import { sendUpdateUser } from '../../lib/activitypub/send' | 12 | import { sendUpdateUser } from '../../lib/activitypub/send' |
13 | import { Emailer } from '../../lib/emailer' | 13 | import { Emailer } from '../../lib/emailer' |
@@ -42,7 +42,7 @@ import { UserModel } from '../../models/account/user' | |||
42 | import { OAuthTokenModel } from '../../models/oauth/oauth-token' | 42 | import { OAuthTokenModel } from '../../models/oauth/oauth-token' |
43 | import { VideoModel } from '../../models/video/video' | 43 | import { VideoModel } from '../../models/video/video' |
44 | 44 | ||
45 | const reqAvatarFile = createReqFiles('avatarfile', CONFIG.STORAGE.AVATARS_DIR, AVATAR_MIMETYPE_EXT) | 45 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) |
46 | 46 | ||
47 | const usersRouter = express.Router() | 47 | const usersRouter = express.Router() |
48 | 48 | ||
@@ -288,17 +288,10 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next | |||
288 | const user = res.locals.oauth.token.user | 288 | const user = res.locals.oauth.token.user |
289 | const actor = user.Account.Actor | 289 | const actor = user.Account.Actor |
290 | 290 | ||
291 | const avatarDir = CONFIG.STORAGE.AVATARS_DIR | ||
292 | const source = join(avatarDir, avatarPhysicalFile.filename) | ||
293 | const extension = extname(avatarPhysicalFile.filename) | 291 | const extension = extname(avatarPhysicalFile.filename) |
294 | const avatarName = uuidv4() + extension | 292 | const avatarName = uuidv4() + extension |
295 | const destination = join(avatarDir, avatarName) | 293 | const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) |
296 | 294 | await processImage(avatarPhysicalFile, destination, AVATARS_SIZE) | |
297 | await sharp(source) | ||
298 | .resize(AVATARS_SIZE.width, AVATARS_SIZE.height) | ||
299 | .toFile(destination) | ||
300 | |||
301 | await unlinkPromise(source) | ||
302 | 295 | ||
303 | const avatar = await sequelizeTypescript.transaction(async t => { | 296 | const avatar = await sequelizeTypescript.transaction(async t => { |
304 | const updatedActor = await updateActorAvatarInstance(actor, avatarName, t) | 297 | const updatedActor = await updateActorAvatarInstance(actor, avatarName, t) |