aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-22 11:14:58 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit6691c52280363fc42f7865230ebb3741f02fff23 (patch)
tree071f9a4d7814c46dcfec100268cb0a0cc76e5204 /server/controllers/api
parent89cd12756035a146bbcc4db78cd3cd64f2f3d88d (diff)
downloadPeerTube-6691c52280363fc42f7865230ebb3741f02fff23.tar.gz
PeerTube-6691c52280363fc42f7865230ebb3741f02fff23.tar.zst
PeerTube-6691c52280363fc42f7865230ebb3741f02fff23.zip
Add filter hooks tests
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/videos/comment.ts2
-rw-r--r--server/controllers/api/videos/import.ts2
-rw-r--r--server/controllers/api/videos/index.ts36
3 files changed, 27 insertions, 13 deletions
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index feda71bdd..39d521f5f 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -110,7 +110,7 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo
110 const apiOptions = await Hooks.wrapObject({ 110 const apiOptions = await Hooks.wrapObject({
111 videoId: video.id, 111 videoId: video.id,
112 threadId: res.locals.videoCommentThread.id, 112 threadId: res.locals.videoCommentThread.id,
113 user: user 113 user
114 }, 'filter:api.video-thread-comments.list.params') 114 }, 'filter:api.video-thread-comments.list.params')
115 115
116 resultList = await Hooks.wrapPromiseFun( 116 resultList = await Hooks.wrapPromiseFun(
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index dcba0e08f..47c6f122c 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -245,7 +245,7 @@ function insertIntoDB (parameters: {
245 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) 245 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
246 if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) 246 if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
247 247
248 await autoBlacklistVideoIfNeeded(video, user, t) 248 await autoBlacklistVideoIfNeeded({ video, user, isRemote: false, isNew: true, transaction: t })
249 249
250 // Set tags to the video 250 // Set tags to the video
251 if (tags) { 251 if (tags) {
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 11e468df2..6a79a16c7 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -268,7 +268,13 @@ async function addVideo (req: express.Request, res: express.Response) {
268 }, { transaction: t }) 268 }, { transaction: t })
269 } 269 }
270 270
271 const videoWasAutoBlacklisted = await autoBlacklistVideoIfNeeded(video, res.locals.oauth.token.User, t) 271 const videoWasAutoBlacklisted = await autoBlacklistVideoIfNeeded({
272 video,
273 user: res.locals.oauth.token.User,
274 isRemote: false,
275 isNew: true,
276 transaction: t
277 })
272 if (!videoWasAutoBlacklisted) await federateVideoIfNeeded(video, true, t) 278 if (!videoWasAutoBlacklisted) await federateVideoIfNeeded(video, true, t)
273 279
274 auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON())) 280 auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON()))
@@ -336,16 +342,16 @@ async function updateVideo (req: express.Request, res: express.Response) {
336 const sequelizeOptions = { transaction: t } 342 const sequelizeOptions = { transaction: t }
337 const oldVideoChannel = videoInstance.VideoChannel 343 const oldVideoChannel = videoInstance.VideoChannel
338 344
339 if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name) 345 if (videoInfoToUpdate.name !== undefined) videoInstance.name = videoInfoToUpdate.name
340 if (videoInfoToUpdate.category !== undefined) videoInstance.set('category', videoInfoToUpdate.category) 346 if (videoInfoToUpdate.category !== undefined) videoInstance.category = videoInfoToUpdate.category
341 if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence) 347 if (videoInfoToUpdate.licence !== undefined) videoInstance.licence = videoInfoToUpdate.licence
342 if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language) 348 if (videoInfoToUpdate.language !== undefined) videoInstance.language = videoInfoToUpdate.language
343 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw) 349 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.nsfw = videoInfoToUpdate.nsfw
344 if (videoInfoToUpdate.waitTranscoding !== undefined) videoInstance.set('waitTranscoding', videoInfoToUpdate.waitTranscoding) 350 if (videoInfoToUpdate.waitTranscoding !== undefined) videoInstance.waitTranscoding = videoInfoToUpdate.waitTranscoding
345 if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support) 351 if (videoInfoToUpdate.support !== undefined) videoInstance.support = videoInfoToUpdate.support
346 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) 352 if (videoInfoToUpdate.description !== undefined) videoInstance.description = videoInfoToUpdate.description
347 if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) 353 if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.commentsEnabled = videoInfoToUpdate.commentsEnabled
348 if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled) 354 if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.downloadEnabled = videoInfoToUpdate.downloadEnabled
349 355
350 if (videoInfoToUpdate.originallyPublishedAt !== undefined && videoInfoToUpdate.originallyPublishedAt !== null) { 356 if (videoInfoToUpdate.originallyPublishedAt !== undefined && videoInfoToUpdate.originallyPublishedAt !== null) {
351 videoInstance.originallyPublishedAt = new Date(videoInfoToUpdate.originallyPublishedAt) 357 videoInstance.originallyPublishedAt = new Date(videoInfoToUpdate.originallyPublishedAt)
@@ -398,6 +404,14 @@ async function updateVideo (req: express.Request, res: express.Response) {
398 await ScheduleVideoUpdateModel.deleteByVideoId(videoInstanceUpdated.id, t) 404 await ScheduleVideoUpdateModel.deleteByVideoId(videoInstanceUpdated.id, t)
399 } 405 }
400 406
407 await autoBlacklistVideoIfNeeded({
408 video: videoInstanceUpdated,
409 user: res.locals.oauth.token.User,
410 isRemote: false,
411 isNew: false,
412 transaction: t
413 })
414
401 const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE 415 const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
402 416
403 // Don't send update if the video was unfederated 417 // Don't send update if the video was unfederated