aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-blacklist.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video-blacklist.ts')
-rw-r--r--server/lib/video-blacklist.ts145
1 files changed, 0 insertions, 145 deletions
diff --git a/server/lib/video-blacklist.ts b/server/lib/video-blacklist.ts
deleted file mode 100644
index d5664a1b9..000000000
--- a/server/lib/video-blacklist.ts
+++ /dev/null
@@ -1,145 +0,0 @@
1import { Transaction } from 'sequelize'
2import { afterCommitIfTransaction } from '@server/helpers/database-utils'
3import { sequelizeTypescript } from '@server/initializers/database'
4import {
5 MUser,
6 MVideoAccountLight,
7 MVideoBlacklist,
8 MVideoBlacklistVideo,
9 MVideoFullLight,
10 MVideoWithBlacklistLight
11} from '@server/types/models'
12import { LiveVideoError, UserRight, VideoBlacklistCreate, VideoBlacklistType } from '../../shared/models'
13import { UserAdminFlag } from '../../shared/models/users/user-flag.model'
14import { logger, loggerTagsFactory } from '../helpers/logger'
15import { CONFIG } from '../initializers/config'
16import { VideoBlacklistModel } from '../models/video/video-blacklist'
17import { sendDeleteVideo } from './activitypub/send'
18import { federateVideoIfNeeded } from './activitypub/videos'
19import { LiveManager } from './live/live-manager'
20import { Notifier } from './notifier'
21import { Hooks } from './plugins/hooks'
22
23const lTags = loggerTagsFactory('blacklist')
24
25async function autoBlacklistVideoIfNeeded (parameters: {
26 video: MVideoWithBlacklistLight
27 user?: MUser
28 isRemote: boolean
29 isNew: boolean
30 isNewFile: boolean
31 notify?: boolean
32 transaction?: Transaction
33}) {
34 const { video, user, isRemote, isNew, isNewFile, notify = true, transaction } = parameters
35 const doAutoBlacklist = await Hooks.wrapFun(
36 autoBlacklistNeeded,
37 { video, user, isRemote, isNew, isNewFile },
38 'filter:video.auto-blacklist.result'
39 )
40
41 if (!doAutoBlacklist) return false
42
43 const videoBlacklistToCreate = {
44 videoId: video.id,
45 unfederated: true,
46 reason: 'Auto-blacklisted. Moderator review required.',
47 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
48 }
49 const [ videoBlacklist ] = await VideoBlacklistModel.findOrCreate<MVideoBlacklistVideo>({
50 where: {
51 videoId: video.id
52 },
53 defaults: videoBlacklistToCreate,
54 transaction
55 })
56 video.VideoBlacklist = videoBlacklist
57
58 videoBlacklist.Video = video
59
60 if (notify) {
61 afterCommitIfTransaction(transaction, () => {
62 Notifier.Instance.notifyOnVideoAutoBlacklist(videoBlacklist)
63 })
64 }
65
66 logger.info('Video %s auto-blacklisted.', video.uuid, lTags(video.uuid))
67
68 return true
69}
70
71async function blacklistVideo (videoInstance: MVideoAccountLight, options: VideoBlacklistCreate) {
72 const blacklist: MVideoBlacklistVideo = await VideoBlacklistModel.create({
73 videoId: videoInstance.id,
74 unfederated: options.unfederate === true,
75 reason: options.reason,
76 type: VideoBlacklistType.MANUAL
77 })
78 blacklist.Video = videoInstance
79
80 if (options.unfederate === true) {
81 await sendDeleteVideo(videoInstance, undefined)
82 }
83
84 if (videoInstance.isLive) {
85 LiveManager.Instance.stopSessionOf(videoInstance.uuid, LiveVideoError.BLACKLISTED)
86 }
87
88 Notifier.Instance.notifyOnVideoBlacklist(blacklist)
89}
90
91async function unblacklistVideo (videoBlacklist: MVideoBlacklist, video: MVideoFullLight) {
92 const videoBlacklistType = await sequelizeTypescript.transaction(async t => {
93 const unfederated = videoBlacklist.unfederated
94 const videoBlacklistType = videoBlacklist.type
95
96 await videoBlacklist.destroy({ transaction: t })
97 video.VideoBlacklist = undefined
98
99 // Re federate the video
100 if (unfederated === true) {
101 await federateVideoIfNeeded(video, true, t)
102 }
103
104 return videoBlacklistType
105 })
106
107 Notifier.Instance.notifyOnVideoUnblacklist(video)
108
109 if (videoBlacklistType === VideoBlacklistType.AUTO_BEFORE_PUBLISHED) {
110 Notifier.Instance.notifyOnVideoPublishedAfterRemovedFromAutoBlacklist(video)
111
112 // Delete on object so new video notifications will send
113 delete video.VideoBlacklist
114 Notifier.Instance.notifyOnNewVideoIfNeeded(video)
115 }
116}
117
118// ---------------------------------------------------------------------------
119
120export {
121 autoBlacklistVideoIfNeeded,
122 blacklistVideo,
123 unblacklistVideo
124}
125
126// ---------------------------------------------------------------------------
127
128function autoBlacklistNeeded (parameters: {
129 video: MVideoWithBlacklistLight
130 isRemote: boolean
131 isNew: boolean
132 isNewFile: boolean
133 user?: MUser
134}) {
135 const { user, video, isRemote, isNew, isNewFile } = parameters
136
137 // Already blacklisted
138 if (video.VideoBlacklist) return false
139 if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED || !user) return false
140 if (isRemote || (isNew === false && isNewFile === false)) return false
141
142 if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)) return false
143
144 return true
145}