diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
commit | 73471b1a52f242e86364ffb077ea6cadb3b07ae2 (patch) | |
tree | 43dbb7748e281f8d80f15326f489cdea10ec857d /server/controllers/api/videos | |
parent | c22419dd265c0c7185bf4197a1cb286eb3d8ebc0 (diff) | |
parent | f5305c04aae14467d6f957b713c5a902275cbb89 (diff) | |
download | PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.gz PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.zst PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.zip |
Merge branch 'release/v1.2.0'
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 3 | ||||
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 31 | ||||
-rw-r--r-- | server/controllers/api/videos/captions.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/videos/comment.ts | 3 | ||||
-rw-r--r-- | server/controllers/api/videos/import.ts | 21 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 45 |
6 files changed, 70 insertions, 37 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index d0c81804b..fe0a95cd5 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -22,6 +22,7 @@ import { VideoModel } from '../../../models/video/video' | |||
22 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 22 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
23 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' | 23 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' |
24 | import { UserModel } from '../../../models/account/user' | 24 | import { UserModel } from '../../../models/account/user' |
25 | import { Notifier } from '../../../lib/notifier' | ||
25 | 26 | ||
26 | const auditLogger = auditLoggerFactory('abuse') | 27 | const auditLogger = auditLoggerFactory('abuse') |
27 | const abuseVideoRouter = express.Router() | 28 | const abuseVideoRouter = express.Router() |
@@ -117,6 +118,8 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) { | |||
117 | await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance) | 118 | await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance) |
118 | } | 119 | } |
119 | 120 | ||
121 | Notifier.Instance.notifyOnNewVideoAbuse(videoAbuseInstance) | ||
122 | |||
120 | auditLogger.create(reporterAccount.Actor.getIdentifier(), new VideoAbuseAuditView(videoAbuseInstance.toFormattedJSON())) | 123 | auditLogger.create(reporterAccount.Actor.getIdentifier(), new VideoAbuseAuditView(videoAbuseInstance.toFormattedJSON())) |
121 | 124 | ||
122 | return videoAbuseInstance | 125 | return videoAbuseInstance |
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 7f803c8e9..43b0516e7 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -16,6 +16,10 @@ import { | |||
16 | } from '../../../middlewares' | 16 | } from '../../../middlewares' |
17 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' | 17 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' |
18 | import { sequelizeTypescript } from '../../../initializers' | 18 | import { sequelizeTypescript } from '../../../initializers' |
19 | import { Notifier } from '../../../lib/notifier' | ||
20 | import { VideoModel } from '../../../models/video/video' | ||
21 | import { sendCreateVideo, sendDeleteVideo, sendUpdateVideo } from '../../../lib/activitypub/send' | ||
22 | import { federateVideoIfNeeded } from '../../../lib/activitypub' | ||
19 | 23 | ||
20 | const blacklistRouter = express.Router() | 24 | const blacklistRouter = express.Router() |
21 | 25 | ||
@@ -64,16 +68,26 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response) | |||
64 | 68 | ||
65 | const toCreate = { | 69 | const toCreate = { |
66 | videoId: videoInstance.id, | 70 | videoId: videoInstance.id, |
71 | unfederated: body.unfederate === true, | ||
67 | reason: body.reason | 72 | reason: body.reason |
68 | } | 73 | } |
69 | 74 | ||
70 | await VideoBlacklistModel.create(toCreate) | 75 | const blacklist = await VideoBlacklistModel.create(toCreate) |
76 | blacklist.Video = videoInstance | ||
77 | |||
78 | if (body.unfederate === true) { | ||
79 | await sendDeleteVideo(videoInstance, undefined) | ||
80 | } | ||
81 | |||
82 | Notifier.Instance.notifyOnVideoBlacklist(blacklist) | ||
83 | |||
84 | logger.info('Video %s blacklisted.', res.locals.video.uuid) | ||
85 | |||
71 | return res.type('json').status(204).end() | 86 | return res.type('json').status(204).end() |
72 | } | 87 | } |
73 | 88 | ||
74 | async function updateVideoBlacklistController (req: express.Request, res: express.Response) { | 89 | async function updateVideoBlacklistController (req: express.Request, res: express.Response) { |
75 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel | 90 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel |
76 | logger.info(videoBlacklist) | ||
77 | 91 | ||
78 | if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason | 92 | if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason |
79 | 93 | ||
@@ -92,11 +106,20 @@ async function listBlacklist (req: express.Request, res: express.Response, next: | |||
92 | 106 | ||
93 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { | 107 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { |
94 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel | 108 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel |
109 | const video: VideoModel = res.locals.video | ||
95 | 110 | ||
96 | await sequelizeTypescript.transaction(t => { | 111 | await sequelizeTypescript.transaction(async t => { |
97 | return videoBlacklist.destroy({ transaction: t }) | 112 | const unfederated = videoBlacklist.unfederated |
113 | await videoBlacklist.destroy({ transaction: t }) | ||
114 | |||
115 | // Re federate the video | ||
116 | if (unfederated === true) { | ||
117 | await federateVideoIfNeeded(video, true, t) | ||
118 | } | ||
98 | }) | 119 | }) |
99 | 120 | ||
121 | Notifier.Instance.notifyOnVideoUnblacklist(video) | ||
122 | |||
100 | logger.info('Video %s removed from blacklist.', res.locals.video.uuid) | 123 | logger.info('Video %s removed from blacklist.', res.locals.video.uuid) |
101 | 124 | ||
102 | return res.type('json').status(204).end() | 125 | return res.type('json').status(204).end() |
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts index 3ba918189..9b3661368 100644 --- a/server/controllers/api/videos/captions.ts +++ b/server/controllers/api/videos/captions.ts | |||
@@ -2,7 +2,7 @@ import * as express from 'express' | |||
2 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' | 2 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' |
3 | import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' | 3 | import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' |
4 | import { createReqFiles } from '../../../helpers/express-utils' | 4 | import { createReqFiles } from '../../../helpers/express-utils' |
5 | import { CONFIG, sequelizeTypescript, VIDEO_CAPTIONS_MIMETYPE_EXT } from '../../../initializers' | 5 | import { CONFIG, MIMETYPES, sequelizeTypescript } from '../../../initializers' |
6 | import { getFormattedObjects } from '../../../helpers/utils' | 6 | import { getFormattedObjects } from '../../../helpers/utils' |
7 | import { VideoCaptionModel } from '../../../models/video/video-caption' | 7 | import { VideoCaptionModel } from '../../../models/video/video-caption' |
8 | import { VideoModel } from '../../../models/video/video' | 8 | import { VideoModel } from '../../../models/video/video' |
@@ -12,7 +12,7 @@ import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | |||
12 | 12 | ||
13 | const reqVideoCaptionAdd = createReqFiles( | 13 | const reqVideoCaptionAdd = createReqFiles( |
14 | [ 'captionfile' ], | 14 | [ 'captionfile' ], |
15 | VIDEO_CAPTIONS_MIMETYPE_EXT, | 15 | MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT, |
16 | { | 16 | { |
17 | captionfile: CONFIG.STORAGE.CAPTIONS_DIR | 17 | captionfile: CONFIG.STORAGE.CAPTIONS_DIR |
18 | } | 18 | } |
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 3875c8f79..70c1148ba 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -26,6 +26,7 @@ import { VideoCommentModel } from '../../../models/video/video-comment' | |||
26 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' | 26 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' |
27 | import { AccountModel } from '../../../models/account/account' | 27 | import { AccountModel } from '../../../models/account/account' |
28 | import { UserModel } from '../../../models/account/user' | 28 | import { UserModel } from '../../../models/account/user' |
29 | import { Notifier } from '../../../lib/notifier' | ||
29 | 30 | ||
30 | const auditLogger = auditLoggerFactory('comments') | 31 | const auditLogger = auditLoggerFactory('comments') |
31 | const videoCommentRouter = express.Router() | 32 | const videoCommentRouter = express.Router() |
@@ -119,6 +120,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons | |||
119 | }, t) | 120 | }, t) |
120 | }) | 121 | }) |
121 | 122 | ||
123 | Notifier.Instance.notifyOnNewComment(comment) | ||
122 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) | 124 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) |
123 | 125 | ||
124 | return res.json({ | 126 | return res.json({ |
@@ -140,6 +142,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Response | |||
140 | }, t) | 142 | }, t) |
141 | }) | 143 | }) |
142 | 144 | ||
145 | Notifier.Instance.notifyOnNewComment(comment) | ||
143 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) | 146 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) |
144 | 147 | ||
145 | return res.json({ comment: comment.toFormattedJSON() }).end() | 148 | return res.json({ comment: comment.toFormattedJSON() }).end() |
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 398fd5a7f..98366cd82 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts | |||
@@ -3,14 +3,7 @@ import * as magnetUtil from 'magnet-uri' | |||
3 | import 'multer' | 3 | import 'multer' |
4 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' | 4 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' |
5 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' | 5 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' |
6 | import { | 6 | import { CONFIG, MIMETYPES, PREVIEWS_SIZE, sequelizeTypescript, THUMBNAILS_SIZE } from '../../../initializers' |
7 | CONFIG, | ||
8 | IMAGE_MIMETYPE_EXT, | ||
9 | PREVIEWS_SIZE, | ||
10 | sequelizeTypescript, | ||
11 | THUMBNAILS_SIZE, | ||
12 | TORRENT_MIMETYPE_EXT | ||
13 | } from '../../../initializers' | ||
14 | import { getYoutubeDLInfo, YoutubeDLInfo } from '../../../helpers/youtube-dl' | 7 | import { getYoutubeDLInfo, YoutubeDLInfo } from '../../../helpers/youtube-dl' |
15 | import { createReqFiles } from '../../../helpers/express-utils' | 8 | import { createReqFiles } from '../../../helpers/express-utils' |
16 | import { logger } from '../../../helpers/logger' | 9 | import { logger } from '../../../helpers/logger' |
@@ -28,18 +21,18 @@ import { VideoChannelModel } from '../../../models/video/video-channel' | |||
28 | import * as Bluebird from 'bluebird' | 21 | import * as Bluebird from 'bluebird' |
29 | import * as parseTorrent from 'parse-torrent' | 22 | import * as parseTorrent from 'parse-torrent' |
30 | import { getSecureTorrentName } from '../../../helpers/utils' | 23 | import { getSecureTorrentName } from '../../../helpers/utils' |
31 | import { readFile, rename } from 'fs-extra' | 24 | import { readFile, move } from 'fs-extra' |
32 | 25 | ||
33 | const auditLogger = auditLoggerFactory('video-imports') | 26 | const auditLogger = auditLoggerFactory('video-imports') |
34 | const videoImportsRouter = express.Router() | 27 | const videoImportsRouter = express.Router() |
35 | 28 | ||
36 | const reqVideoFileImport = createReqFiles( | 29 | const reqVideoFileImport = createReqFiles( |
37 | [ 'thumbnailfile', 'previewfile', 'torrentfile' ], | 30 | [ 'thumbnailfile', 'previewfile', 'torrentfile' ], |
38 | Object.assign({}, TORRENT_MIMETYPE_EXT, IMAGE_MIMETYPE_EXT), | 31 | Object.assign({}, MIMETYPES.TORRENT.MIMETYPE_EXT, MIMETYPES.IMAGE.MIMETYPE_EXT), |
39 | { | 32 | { |
40 | thumbnailfile: CONFIG.STORAGE.THUMBNAILS_DIR, | 33 | thumbnailfile: CONFIG.STORAGE.TMP_DIR, |
41 | previewfile: CONFIG.STORAGE.PREVIEWS_DIR, | 34 | previewfile: CONFIG.STORAGE.TMP_DIR, |
42 | torrentfile: CONFIG.STORAGE.TORRENTS_DIR | 35 | torrentfile: CONFIG.STORAGE.TMP_DIR |
43 | } | 36 | } |
44 | ) | 37 | ) |
45 | 38 | ||
@@ -78,7 +71,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, to | |||
78 | 71 | ||
79 | // Rename the torrent to a secured name | 72 | // Rename the torrent to a secured name |
80 | const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, getSecureTorrentName(torrentName)) | 73 | const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, getSecureTorrentName(torrentName)) |
81 | await rename(torrentfile.path, newTorrentPath) | 74 | await move(torrentfile.path, newTorrentPath) |
82 | torrentfile.path = newTorrentPath | 75 | torrentfile.path = newTorrentPath |
83 | 76 | ||
84 | const buf = await readFile(torrentfile.path) | 77 | const buf = await readFile(torrentfile.path) |
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 | ||