]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/video-blacklist.ts
Move config in its own file
[github/Chocobozzz/PeerTube.git] / server / lib / video-blacklist.ts
1 import * as sequelize from 'sequelize'
2 import { CONFIG } from '../initializers/config'
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 }