aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/process/process-create.ts4
-rw-r--r--server/lib/activitypub/videos.ts28
-rw-r--r--server/lib/video-blacklist.ts33
3 files changed, 51 insertions, 14 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts
index daf846513..b9f584aa5 100644
--- a/server/lib/activitypub/process/process-create.ts
+++ b/server/lib/activitypub/process/process-create.ts
@@ -48,9 +48,9 @@ export {
48async function processCreateVideo (activity: ActivityCreate) { 48async function processCreateVideo (activity: ActivityCreate) {
49 const videoToCreateData = activity.object as VideoTorrentObject 49 const videoToCreateData = activity.object as VideoTorrentObject
50 50
51 const { video, created } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoToCreateData }) 51 const { video, created, autoBlacklisted } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoToCreateData })
52 52
53 if (created) Notifier.Instance.notifyOnNewVideo(video) 53 if (created && !autoBlacklisted) Notifier.Instance.notifyOnNewVideo(video)
54 54
55 return video 55 return video
56} 56}
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index dade6b55f..67b433165 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -224,11 +224,11 @@ async function getOrCreateVideoAndAccountAndChannel (options: {
224 if (!fetchedVideo) throw new Error('Cannot fetch remote video with url: ' + videoUrl) 224 if (!fetchedVideo) throw new Error('Cannot fetch remote video with url: ' + videoUrl)
225 225
226 const channelActor = await getOrCreateVideoChannelFromVideoObject(fetchedVideo) 226 const channelActor = await getOrCreateVideoChannelFromVideoObject(fetchedVideo)
227 const video = await retryTransactionWrapper(createVideo, fetchedVideo, channelActor, syncParam.thumbnail) 227 const { autoBlacklisted, videoCreated } = await retryTransactionWrapper(createVideo, fetchedVideo, channelActor, syncParam.thumbnail)
228 228
229 await syncVideoExternalAttributes(video, fetchedVideo, syncParam) 229 await syncVideoExternalAttributes(videoCreated, fetchedVideo, syncParam)
230 230
231 return { video, created: true } 231 return { video: videoCreated, created: true, autoBlacklisted }
232} 232}
233 233
234async function updateVideoFromAP (options: { 234async function updateVideoFromAP (options: {
@@ -354,7 +354,13 @@ async function updateVideoFromAP (options: {
354 } 354 }
355 }) 355 })
356 356
357 const autoBlacklisted = await autoBlacklistVideoIfNeeded(video, undefined, undefined) 357 const autoBlacklisted = await autoBlacklistVideoIfNeeded({
358 video,
359 user: undefined,
360 isRemote: true,
361 isNew: false,
362 transaction: undefined
363 })
358 364
359 if (autoBlacklisted) Notifier.Instance.notifyOnVideoAutoBlacklist(video) 365 if (autoBlacklisted) Notifier.Instance.notifyOnVideoAutoBlacklist(video)
360 else if (!wasPrivateVideo || wasUnlistedVideo) Notifier.Instance.notifyOnNewVideo(video) // Notify our users? 366 else if (!wasPrivateVideo || wasUnlistedVideo) Notifier.Instance.notifyOnNewVideo(video) // Notify our users?
@@ -467,7 +473,7 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor
467 thumbnailModel = await promiseThumbnail 473 thumbnailModel = await promiseThumbnail
468 } 474 }
469 475
470 const videoCreated: VideoModel = await sequelizeTypescript.transaction(async t => { 476 const { autoBlacklisted, videoCreated } = await sequelizeTypescript.transaction(async t => {
471 const sequelizeOptions = { transaction: t } 477 const sequelizeOptions = { transaction: t }
472 478
473 const videoCreated = await video.save(sequelizeOptions) 479 const videoCreated = await video.save(sequelizeOptions)
@@ -506,9 +512,17 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor
506 }) 512 })
507 await Promise.all(videoCaptionsPromises) 513 await Promise.all(videoCaptionsPromises)
508 514
515 const autoBlacklisted = await autoBlacklistVideoIfNeeded({
516 video,
517 user: undefined,
518 isRemote: true,
519 isNew: true,
520 transaction: t
521 })
522
509 logger.info('Remote video with uuid %s inserted.', videoObject.uuid) 523 logger.info('Remote video with uuid %s inserted.', videoObject.uuid)
510 524
511 return videoCreated 525 return { autoBlacklisted, videoCreated }
512 }) 526 })
513 527
514 if (waitThumbnail === false) { 528 if (waitThumbnail === false) {
@@ -519,7 +533,7 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor
519 }) 533 })
520 } 534 }
521 535
522 return videoCreated 536 return { autoBlacklisted, videoCreated }
523} 537}
524 538
525async function videoActivityObjectToDBAttributes ( 539async function videoActivityObjectToDBAttributes (
diff --git a/server/lib/video-blacklist.ts b/server/lib/video-blacklist.ts
index 9bc996f5a..9749ce2f6 100644
--- a/server/lib/video-blacklist.ts
+++ b/server/lib/video-blacklist.ts
@@ -8,10 +8,17 @@ import { logger } from '../helpers/logger'
8import { UserAdminFlag } from '../../shared/models/users/user-flag.model' 8import { UserAdminFlag } from '../../shared/models/users/user-flag.model'
9import { Hooks } from './plugins/hooks' 9import { Hooks } from './plugins/hooks'
10 10
11async function autoBlacklistVideoIfNeeded (video: VideoModel, user?: UserModel, transaction?: Transaction) { 11async function autoBlacklistVideoIfNeeded (parameters: {
12 video: VideoModel,
13 user?: UserModel,
14 isRemote: boolean,
15 isNew: boolean,
16 transaction?: Transaction
17}) {
18 const { video, user, isRemote, isNew, transaction } = parameters
12 const doAutoBlacklist = await Hooks.wrapPromiseFun( 19 const doAutoBlacklist = await Hooks.wrapPromiseFun(
13 autoBlacklistNeeded, 20 autoBlacklistNeeded,
14 { video, user }, 21 { video, user, isRemote, isNew },
15 'filter:video.auto-blacklist.result' 22 'filter:video.auto-blacklist.result'
16 ) 23 )
17 24
@@ -23,17 +30,33 @@ async function autoBlacklistVideoIfNeeded (video: VideoModel, user?: UserModel,
23 reason: 'Auto-blacklisted. Moderator review required.', 30 reason: 'Auto-blacklisted. Moderator review required.',
24 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED 31 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
25 } 32 }
26 await VideoBlacklistModel.create(videoBlacklistToCreate, { transaction }) 33 const [ videoBlacklist ] = await VideoBlacklistModel.findOrCreate({
34 where: {
35 videoId: video.id
36 },
37 defaults: videoBlacklistToCreate,
38 transaction
39 })
40
41 video.VideoBlacklist = videoBlacklist
27 42
28 logger.info('Video %s auto-blacklisted.', video.uuid) 43 logger.info('Video %s auto-blacklisted.', video.uuid)
29 44
30 return true 45 return true
31} 46}
32 47
33async function autoBlacklistNeeded (parameters: { video: VideoModel, user?: UserModel }) { 48async function autoBlacklistNeeded (parameters: {
34 const { user } = parameters 49 video: VideoModel,
50 isRemote: boolean,
51 isNew: boolean,
52 user?: UserModel
53}) {
54 const { user, video, isRemote, isNew } = parameters
35 55
56 // Already blacklisted
57 if (video.VideoBlacklist) return false
36 if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED || !user) return false 58 if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED || !user) return false
59 if (isRemote || isNew) return false
37 60
38 if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)) return false 61 if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)) return false
39 62