diff options
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r-- | server/controllers/api/videos/index.ts | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 3d1b2e1a2..2b2dfa7ca 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -8,14 +8,13 @@ import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../ | |||
8 | import { getFormattedObjects, getServerActor } from '../../../helpers/utils' | 8 | import { getFormattedObjects, getServerActor } from '../../../helpers/utils' |
9 | import { | 9 | import { |
10 | CONFIG, | 10 | CONFIG, |
11 | IMAGE_MIMETYPE_EXT, | 11 | MIMETYPES, |
12 | PREVIEWS_SIZE, | 12 | PREVIEWS_SIZE, |
13 | sequelizeTypescript, | 13 | sequelizeTypescript, |
14 | THUMBNAILS_SIZE, | 14 | THUMBNAILS_SIZE, |
15 | VIDEO_CATEGORIES, | 15 | VIDEO_CATEGORIES, |
16 | VIDEO_LANGUAGES, | 16 | VIDEO_LANGUAGES, |
17 | VIDEO_LICENCES, | 17 | VIDEO_LICENCES, |
18 | VIDEO_MIMETYPE_EXT, | ||
19 | VIDEO_PRIVACIES | 18 | VIDEO_PRIVACIES |
20 | } from '../../../initializers' | 19 | } from '../../../initializers' |
21 | import { | 20 | import { |
@@ -57,27 +56,28 @@ import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-u | |||
57 | import { videoCaptionsRouter } from './captions' | 56 | import { videoCaptionsRouter } from './captions' |
58 | import { videoImportsRouter } from './import' | 57 | import { videoImportsRouter } from './import' |
59 | import { resetSequelizeInstance } from '../../../helpers/database-utils' | 58 | import { resetSequelizeInstance } from '../../../helpers/database-utils' |
60 | import { rename } from 'fs-extra' | 59 | import { move } from 'fs-extra' |
61 | import { watchingRouter } from './watching' | 60 | import { watchingRouter } from './watching' |
61 | import { Notifier } from '../../../lib/notifier' | ||
62 | 62 | ||
63 | const auditLogger = auditLoggerFactory('videos') | 63 | const auditLogger = auditLoggerFactory('videos') |
64 | const videosRouter = express.Router() | 64 | const videosRouter = express.Router() |
65 | 65 | ||
66 | const reqVideoFileAdd = createReqFiles( | 66 | const reqVideoFileAdd = createReqFiles( |
67 | [ 'videofile', 'thumbnailfile', 'previewfile' ], | 67 | [ 'videofile', 'thumbnailfile', 'previewfile' ], |
68 | Object.assign({}, VIDEO_MIMETYPE_EXT, IMAGE_MIMETYPE_EXT), | 68 | Object.assign({}, MIMETYPES.VIDEO.MIMETYPE_EXT, MIMETYPES.IMAGE.MIMETYPE_EXT), |
69 | { | 69 | { |
70 | videofile: CONFIG.STORAGE.VIDEOS_DIR, | 70 | videofile: CONFIG.STORAGE.TMP_DIR, |
71 | thumbnailfile: CONFIG.STORAGE.THUMBNAILS_DIR, | 71 | thumbnailfile: CONFIG.STORAGE.TMP_DIR, |
72 | previewfile: CONFIG.STORAGE.PREVIEWS_DIR | 72 | previewfile: CONFIG.STORAGE.TMP_DIR |
73 | } | 73 | } |
74 | ) | 74 | ) |
75 | const reqVideoFileUpdate = createReqFiles( | 75 | const reqVideoFileUpdate = createReqFiles( |
76 | [ 'thumbnailfile', 'previewfile' ], | 76 | [ 'thumbnailfile', 'previewfile' ], |
77 | IMAGE_MIMETYPE_EXT, | 77 | MIMETYPES.IMAGE.MIMETYPE_EXT, |
78 | { | 78 | { |
79 | thumbnailfile: CONFIG.STORAGE.THUMBNAILS_DIR, | 79 | thumbnailfile: CONFIG.STORAGE.TMP_DIR, |
80 | previewfile: CONFIG.STORAGE.PREVIEWS_DIR | 80 | previewfile: CONFIG.STORAGE.TMP_DIR |
81 | } | 81 | } |
82 | ) | 82 | ) |
83 | 83 | ||
@@ -208,7 +208,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
208 | // Move physical file | 208 | // Move physical file |
209 | const videoDir = CONFIG.STORAGE.VIDEOS_DIR | 209 | const videoDir = CONFIG.STORAGE.VIDEOS_DIR |
210 | const destination = join(videoDir, video.getVideoFilename(videoFile)) | 210 | const destination = join(videoDir, video.getVideoFilename(videoFile)) |
211 | await rename(videoPhysicalFile.path, destination) | 211 | await move(videoPhysicalFile.path, destination) |
212 | // This is important in case if there is another attempt in the retry process | 212 | // This is important in case if there is another attempt in the retry process |
213 | videoPhysicalFile.filename = video.getVideoFilename(videoFile) | 213 | videoPhysicalFile.filename = video.getVideoFilename(videoFile) |
214 | videoPhysicalFile.path = destination | 214 | videoPhysicalFile.path = destination |
@@ -271,6 +271,8 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
271 | return videoCreated | 271 | return videoCreated |
272 | }) | 272 | }) |
273 | 273 | ||
274 | Notifier.Instance.notifyOnNewVideo(videoCreated) | ||
275 | |||
274 | if (video.state === VideoState.TO_TRANSCODE) { | 276 | if (video.state === VideoState.TO_TRANSCODE) { |
275 | // Put uuid because we don't have id auto incremented for now | 277 | // Put uuid because we don't have id auto incremented for now |
276 | const dataInput = { | 278 | const dataInput = { |
@@ -295,6 +297,7 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
295 | const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) | 297 | const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) |
296 | const videoInfoToUpdate: VideoUpdate = req.body | 298 | const videoInfoToUpdate: VideoUpdate = req.body |
297 | const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE | 299 | const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE |
300 | const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED | ||
298 | 301 | ||
299 | // Process thumbnail or create it from the video | 302 | // Process thumbnail or create it from the video |
300 | if (req.files && req.files['thumbnailfile']) { | 303 | if (req.files && req.files['thumbnailfile']) { |
@@ -309,10 +312,8 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
309 | } | 312 | } |
310 | 313 | ||
311 | try { | 314 | try { |
312 | await sequelizeTypescript.transaction(async t => { | 315 | const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => { |
313 | const sequelizeOptions = { | 316 | const sequelizeOptions = { transaction: t } |
314 | transaction: t | ||
315 | } | ||
316 | const oldVideoChannel = videoInstance.VideoChannel | 317 | const oldVideoChannel = videoInstance.VideoChannel |
317 | 318 | ||
318 | if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name) | 319 | if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name) |
@@ -363,7 +364,11 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
363 | } | 364 | } |
364 | 365 | ||
365 | const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE | 366 | const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE |
366 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) | 367 | |
368 | // Don't send update if the video was unfederated | ||
369 | if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) { | ||
370 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) | ||
371 | } | ||
367 | 372 | ||
368 | auditLogger.update( | 373 | auditLogger.update( |
369 | getAuditIdFromRes(res), | 374 | getAuditIdFromRes(res), |
@@ -371,7 +376,13 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
371 | oldVideoAuditView | 376 | oldVideoAuditView |
372 | ) | 377 | ) |
373 | logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid) | 378 | logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid) |
379 | |||
380 | return videoInstanceUpdated | ||
374 | }) | 381 | }) |
382 | |||
383 | if (wasUnlistedVideo || wasPrivateVideo) { | ||
384 | Notifier.Instance.notifyOnNewVideo(videoInstanceUpdated) | ||
385 | } | ||
375 | } catch (err) { | 386 | } catch (err) { |
376 | // Force fields we want to update | 387 | // Force fields we want to update |
377 | // If the transaction is retried, sequelize will think the object has not changed | 388 | // If the transaction is retried, sequelize will think the object has not changed |
@@ -388,7 +399,7 @@ function getVideo (req: express.Request, res: express.Response) { | |||
388 | const videoInstance = res.locals.video | 399 | const videoInstance = res.locals.video |
389 | 400 | ||
390 | if (videoInstance.isOutdated()) { | 401 | if (videoInstance.isOutdated()) { |
391 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', videoUrl: videoInstance.url } }) | 402 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: videoInstance.url } }) |
392 | .catch(err => logger.error('Cannot create AP refresher job for video %s.', videoInstance.url, { err })) | 403 | .catch(err => logger.error('Cannot create AP refresher job for video %s.', videoInstance.url, { err })) |
393 | } | 404 | } |
394 | 405 | ||