mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Add ability to set video thumbnail/preview
This commit is contained in:
parent
e883399fa6
commit
ac81d1a06d
22 changed files with 454 additions and 143 deletions
|
@ -1,13 +1,13 @@
|
|||
import * as express from 'express'
|
||||
import 'multer'
|
||||
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 { unlinkPromise } from '../../helpers/core-utils'
|
||||
import { retryTransactionWrapper } from '../../helpers/database-utils'
|
||||
import { processImage } from '../../helpers/image-utils'
|
||||
import { logger } from '../../helpers/logger'
|
||||
import { createReqFiles, getFormattedObjects } from '../../helpers/utils'
|
||||
import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers'
|
||||
import { AVATARS_SIZE, CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers'
|
||||
import { updateActorAvatarInstance } from '../../lib/activitypub'
|
||||
import { sendUpdateUser } from '../../lib/activitypub/send'
|
||||
import { Emailer } from '../../lib/emailer'
|
||||
|
@ -42,7 +42,7 @@ import { UserModel } from '../../models/account/user'
|
|||
import { OAuthTokenModel } from '../../models/oauth/oauth-token'
|
||||
import { VideoModel } from '../../models/video/video'
|
||||
|
||||
const reqAvatarFile = createReqFiles('avatarfile', CONFIG.STORAGE.AVATARS_DIR, AVATAR_MIMETYPE_EXT)
|
||||
const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR })
|
||||
|
||||
const usersRouter = express.Router()
|
||||
|
||||
|
@ -288,17 +288,10 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next
|
|||
const user = res.locals.oauth.token.user
|
||||
const actor = user.Account.Actor
|
||||
|
||||
const avatarDir = CONFIG.STORAGE.AVATARS_DIR
|
||||
const source = join(avatarDir, avatarPhysicalFile.filename)
|
||||
const extension = extname(avatarPhysicalFile.filename)
|
||||
const avatarName = uuidv4() + extension
|
||||
const destination = join(avatarDir, avatarName)
|
||||
|
||||
await sharp(source)
|
||||
.resize(AVATARS_SIZE.width, AVATARS_SIZE.height)
|
||||
.toFile(destination)
|
||||
|
||||
await unlinkPromise(source)
|
||||
const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
|
||||
await processImage(avatarPhysicalFile, destination, AVATARS_SIZE)
|
||||
|
||||
const avatar = await sequelizeTypescript.transaction(async t => {
|
||||
const updatedActor = await updateActorAvatarInstance(actor, avatarName, t)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue