diff options
Diffstat (limited to 'server/lib/video-blacklist.ts')
-rw-r--r-- | server/lib/video-blacklist.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/server/lib/video-blacklist.ts b/server/lib/video-blacklist.ts new file mode 100644 index 000000000..dc4e0aed9 --- /dev/null +++ b/server/lib/video-blacklist.ts | |||
@@ -0,0 +1,31 @@ | |||
1 | import * as sequelize from 'sequelize' | ||
2 | import { CONFIG } from '../initializers/constants' | ||
3 | import { VideoBlacklistType, UserRight } from '../../shared/models' | ||
4 | import { VideoBlacklistModel } from '../models/video/video-blacklist' | ||
5 | import { UserModel } from '../models/account/user' | ||
6 | import { VideoModel } from '../models/video/video' | ||
7 | import { logger } from '../helpers/logger' | ||
8 | |||
9 | async function autoBlacklistVideoIfNeeded (video: VideoModel, user: UserModel, transaction: sequelize.Transaction) { | ||
10 | if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED) return false | ||
11 | |||
12 | if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)) return false | ||
13 | |||
14 | const sequelizeOptions = { transaction } | ||
15 | const videoBlacklistToCreate = { | ||
16 | videoId: video.id, | ||
17 | unfederated: true, | ||
18 | reason: 'Auto-blacklisted. Moderator review required.', | ||
19 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED | ||
20 | } | ||
21 | await VideoBlacklistModel.create(videoBlacklistToCreate, sequelizeOptions) | ||
22 | logger.info('Video %s auto-blacklisted.', video.uuid) | ||
23 | |||
24 | return true | ||
25 | } | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | export { | ||
30 | autoBlacklistVideoIfNeeded | ||
31 | } | ||