Handle thumbnail update

pull/297/head
Chocobozzz 2018-02-14 15:33:49 +01:00
parent a0922eb9b3
commit e3a682a877
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 21 additions and 6 deletions

View File

@ -158,8 +158,13 @@ app.use(function (req, res, next) {
})
app.use(function (err, req, res, next) {
logger.error('Error in controller.', { error: err.stack || err.message || err })
res.sendStatus(err.status || 500)
let error = 'Unknown error.'
if (err) {
error = err.stack || err.message || err
}
logger.error('Error in controller.', { error })
return res.status(err.status || 500).end()
})
// ----------- Run -----------

View File

@ -195,7 +195,10 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
const videoFile = new VideoFileModel(videoFileData)
const videoDir = CONFIG.STORAGE.VIDEOS_DIR
const destination = join(videoDir, video.getVideoFilename(videoFile))
await renamePromise(videoPhysicalFile.path, destination)
// This is important in case if there is another attempt in the retry process
videoPhysicalFile.filename = video.getVideoFilename(videoFile)
// Process thumbnail or create it from the video
const thumbnailField = req.files['thumbnailfile']

View File

@ -21,7 +21,7 @@ function keysExcluder (key, value) {
return excludedKeys[key] === true ? undefined : value
}
const loggerFormat = winston.format.printf((info) => {
const loggerFormat = winston.format.printf(info => {
let additionalInfos = JSON.stringify(info, keysExcluder, 2)
if (additionalInfos === '{}') additionalInfos = ''
else additionalInfos = ' ' + additionalInfos

View File

@ -11,7 +11,10 @@ import { ActorModel } from '../../../models/activitypub/actor'
import { TagModel } from '../../../models/video/tag'
import { VideoFileModel } from '../../../models/video/video-file'
import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor'
import { getOrCreateAccountAndVideoAndChannel, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from '../videos'
import {
generateThumbnailFromUrl, getOrCreateAccountAndVideoAndChannel, videoActivityObjectToDBAttributes,
videoFileActivityUrlToDBAttributes
} from '../videos'
async function processUpdateActivity (activity: ActivityUpdate) {
const actor = await getOrCreateActorAndServerAndModel(activity.actor)
@ -82,6 +85,10 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
await videoInstance.save(sequelizeOptions)
// Don't block on request
generateThumbnailFromUrl(videoInstance, videoAttributesToUpdate.icon)
.catch(err => logger.warn('Cannot generate thumbnail of %s.', videoAttributesToUpdate.id, err))
// Remove old video files
const videoFileDestroyTasks: Bluebird<void>[] = []
for (const videoFile of videoInstance.VideoFiles) {

View File

@ -11,12 +11,12 @@ function asyncMiddleware (fun: RequestPromiseHandler | RequestPromiseHandler[])
if (Array.isArray(fun) === true) {
return eachSeries(fun as RequestHandler[], (f, cb) => {
Promise.resolve(f(req, res, cb))
.catch(next)
.catch(err => next(err))
}, next)
}
return Promise.resolve((fun as RequestHandler)(req, res, next))
.catch(next)
.catch(err => next(err))
}
}