aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-13 18:17:05 +0100
committerChocobozzz <me@florianbigard.com>2018-02-14 16:03:09 +0100
commitac81d1a06d57b9ae86663831e7f5edcef57b0fa4 (patch)
treeda31775c9533d3e270f68f921e146f086bf7c0b8 /server/controllers/api/users.ts
parente883399fa6caa56bb8519c9a2e22d88001f26661 (diff)
downloadPeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.tar.gz
PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.tar.zst
PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.zip
Add ability to set video thumbnail/preview
Diffstat (limited to 'server/controllers/api/users.ts')
-rw-r--r--server/controllers/api/users.ts19
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'multer'
2import { extname, join } from 'path' 3import { extname, join } from 'path'
3import * as sharp from 'sharp'
4import * as uuidv4 from 'uuid/v4' 4import * as uuidv4 from 'uuid/v4'
5import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' 5import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared'
6import { unlinkPromise } from '../../helpers/core-utils'
7import { retryTransactionWrapper } from '../../helpers/database-utils' 6import { retryTransactionWrapper } from '../../helpers/database-utils'
7import { processImage } from '../../helpers/image-utils'
8import { logger } from '../../helpers/logger' 8import { logger } from '../../helpers/logger'
9import { createReqFiles, getFormattedObjects } from '../../helpers/utils' 9import { createReqFiles, getFormattedObjects } from '../../helpers/utils'
10import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers' 10import { AVATARS_SIZE, CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers'
11import { updateActorAvatarInstance } from '../../lib/activitypub' 11import { updateActorAvatarInstance } from '../../lib/activitypub'
12import { sendUpdateUser } from '../../lib/activitypub/send' 12import { sendUpdateUser } from '../../lib/activitypub/send'
13import { Emailer } from '../../lib/emailer' 13import { Emailer } from '../../lib/emailer'
@@ -42,7 +42,7 @@ import { UserModel } from '../../models/account/user'
42import { OAuthTokenModel } from '../../models/oauth/oauth-token' 42import { OAuthTokenModel } from '../../models/oauth/oauth-token'
43import { VideoModel } from '../../models/video/video' 43import { VideoModel } from '../../models/video/video'
44 44
45const reqAvatarFile = createReqFiles('avatarfile', CONFIG.STORAGE.AVATARS_DIR, AVATAR_MIMETYPE_EXT) 45const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR })
46 46
47const usersRouter = express.Router() 47const 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)