diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-14 15:33:49 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-14 16:03:09 +0100 |
commit | e3a682a877a10833cb54ac3595e55110bda95647 (patch) | |
tree | 4c9e2e31be234720a72988f2e9ad8f4a002ec4c8 | |
parent | a0922eb9b3750ab6de31116531b625643930b38c (diff) | |
download | PeerTube-e3a682a877a10833cb54ac3595e55110bda95647.tar.gz PeerTube-e3a682a877a10833cb54ac3595e55110bda95647.tar.zst PeerTube-e3a682a877a10833cb54ac3595e55110bda95647.zip |
Handle thumbnail update
-rw-r--r-- | server.ts | 9 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 3 | ||||
-rw-r--r-- | server/helpers/logger.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 9 | ||||
-rw-r--r-- | server/middlewares/async.ts | 4 |
5 files changed, 21 insertions, 6 deletions
@@ -158,8 +158,13 @@ app.use(function (req, res, next) { | |||
158 | }) | 158 | }) |
159 | 159 | ||
160 | app.use(function (err, req, res, next) { | 160 | app.use(function (err, req, res, next) { |
161 | logger.error('Error in controller.', { error: err.stack || err.message || err }) | 161 | let error = 'Unknown error.' |
162 | res.sendStatus(err.status || 500) | 162 | if (err) { |
163 | error = err.stack || err.message || err | ||
164 | } | ||
165 | |||
166 | logger.error('Error in controller.', { error }) | ||
167 | return res.status(err.status || 500).end() | ||
163 | }) | 168 | }) |
164 | 169 | ||
165 | // ----------- Run ----------- | 170 | // ----------- 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 | |||
195 | const videoFile = new VideoFileModel(videoFileData) | 195 | const videoFile = new VideoFileModel(videoFileData) |
196 | const videoDir = CONFIG.STORAGE.VIDEOS_DIR | 196 | const videoDir = CONFIG.STORAGE.VIDEOS_DIR |
197 | const destination = join(videoDir, video.getVideoFilename(videoFile)) | 197 | const destination = join(videoDir, video.getVideoFilename(videoFile)) |
198 | |||
198 | await renamePromise(videoPhysicalFile.path, destination) | 199 | await renamePromise(videoPhysicalFile.path, destination) |
200 | // This is important in case if there is another attempt in the retry process | ||
201 | videoPhysicalFile.filename = video.getVideoFilename(videoFile) | ||
199 | 202 | ||
200 | // Process thumbnail or create it from the video | 203 | // Process thumbnail or create it from the video |
201 | const thumbnailField = req.files['thumbnailfile'] | 204 | 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) { | |||
21 | return excludedKeys[key] === true ? undefined : value | 21 | return excludedKeys[key] === true ? undefined : value |
22 | } | 22 | } |
23 | 23 | ||
24 | const loggerFormat = winston.format.printf((info) => { | 24 | const loggerFormat = winston.format.printf(info => { |
25 | let additionalInfos = JSON.stringify(info, keysExcluder, 2) | 25 | let additionalInfos = JSON.stringify(info, keysExcluder, 2) |
26 | if (additionalInfos === '{}') additionalInfos = '' | 26 | if (additionalInfos === '{}') additionalInfos = '' |
27 | else additionalInfos = ' ' + additionalInfos | 27 | 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' | |||
11 | import { TagModel } from '../../../models/video/tag' | 11 | import { TagModel } from '../../../models/video/tag' |
12 | import { VideoFileModel } from '../../../models/video/video-file' | 12 | import { VideoFileModel } from '../../../models/video/video-file' |
13 | import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' | 13 | import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' |
14 | import { getOrCreateAccountAndVideoAndChannel, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from '../videos' | 14 | import { |
15 | generateThumbnailFromUrl, getOrCreateAccountAndVideoAndChannel, videoActivityObjectToDBAttributes, | ||
16 | videoFileActivityUrlToDBAttributes | ||
17 | } from '../videos' | ||
15 | 18 | ||
16 | async function processUpdateActivity (activity: ActivityUpdate) { | 19 | async function processUpdateActivity (activity: ActivityUpdate) { |
17 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) | 20 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) |
@@ -82,6 +85,10 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) { | |||
82 | 85 | ||
83 | await videoInstance.save(sequelizeOptions) | 86 | await videoInstance.save(sequelizeOptions) |
84 | 87 | ||
88 | // Don't block on request | ||
89 | generateThumbnailFromUrl(videoInstance, videoAttributesToUpdate.icon) | ||
90 | .catch(err => logger.warn('Cannot generate thumbnail of %s.', videoAttributesToUpdate.id, err)) | ||
91 | |||
85 | // Remove old video files | 92 | // Remove old video files |
86 | const videoFileDestroyTasks: Bluebird<void>[] = [] | 93 | const videoFileDestroyTasks: Bluebird<void>[] = [] |
87 | for (const videoFile of videoInstance.VideoFiles) { | 94 | 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[]) | |||
11 | if (Array.isArray(fun) === true) { | 11 | if (Array.isArray(fun) === true) { |
12 | return eachSeries(fun as RequestHandler[], (f, cb) => { | 12 | return eachSeries(fun as RequestHandler[], (f, cb) => { |
13 | Promise.resolve(f(req, res, cb)) | 13 | Promise.resolve(f(req, res, cb)) |
14 | .catch(next) | 14 | .catch(err => next(err)) |
15 | }, next) | 15 | }, next) |
16 | } | 16 | } |
17 | 17 | ||
18 | return Promise.resolve((fun as RequestHandler)(req, res, next)) | 18 | return Promise.resolve((fun as RequestHandler)(req, res, next)) |
19 | .catch(next) | 19 | .catch(err => next(err)) |
20 | } | 20 | } |
21 | } | 21 | } |
22 | 22 | ||