diff --git a/server.ts b/server.ts index 529194a5e..c19ec4f19 100644 --- a/server.ts +++ b/server.ts @@ -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 ----------- diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 1a4de081f..10b6c000f 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -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'] diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 201ea2235..bcd4885af 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts @@ -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 diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index c0038be64..c7ad412bc 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts @@ -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[] = [] for (const videoFile of videoInstance.VideoFiles) { diff --git a/server/middlewares/async.ts b/server/middlewares/async.ts index 534891899..dd209b115 100644 --- a/server/middlewares/async.ts +++ b/server/middlewares/async.ts @@ -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)) } }