diff options
author | Chocobozzz <me@florianbigard.com> | 2020-05-07 14:58:24 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-05-07 15:07:01 +0200 |
commit | 80fdaf064562aff968f4c9cea1cf220bc12a70da (patch) | |
tree | a0ec49f433b828660f741b394dfd87056cd2c6ef /server/lib/video-blacklist.ts | |
parent | 3cc665f48fd233d09f778d7e887488dde6f03ef6 (diff) | |
download | PeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.tar.gz PeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.tar.zst PeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.zip |
Add moderation helpers to plugins
Diffstat (limited to 'server/lib/video-blacklist.ts')
-rw-r--r-- | server/lib/video-blacklist.ts | 80 |
1 files changed, 69 insertions, 11 deletions
diff --git a/server/lib/video-blacklist.ts b/server/lib/video-blacklist.ts index 3b90b1b94..bd60c6201 100644 --- a/server/lib/video-blacklist.ts +++ b/server/lib/video-blacklist.ts | |||
@@ -1,12 +1,22 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { sequelizeTypescript } from '@server/initializers/database' | ||
3 | import { | ||
4 | MUser, | ||
5 | MVideoAccountLight, | ||
6 | MVideoBlacklist, | ||
7 | MVideoBlacklistVideo, | ||
8 | MVideoFullLight, | ||
9 | MVideoWithBlacklistLight | ||
10 | } from '@server/typings/models' | ||
11 | import { UserRight, VideoBlacklistCreate, VideoBlacklistType } from '../../shared/models' | ||
12 | import { UserAdminFlag } from '../../shared/models/users/user-flag.model' | ||
13 | import { logger } from '../helpers/logger' | ||
2 | import { CONFIG } from '../initializers/config' | 14 | import { CONFIG } from '../initializers/config' |
3 | import { UserRight, VideoBlacklistType } from '../../shared/models' | ||
4 | import { VideoBlacklistModel } from '../models/video/video-blacklist' | 15 | import { VideoBlacklistModel } from '../models/video/video-blacklist' |
5 | import { logger } from '../helpers/logger' | 16 | import { sendDeleteVideo } from './activitypub/send' |
6 | import { UserAdminFlag } from '../../shared/models/users/user-flag.model' | 17 | import { federateVideoIfNeeded } from './activitypub/videos' |
7 | import { Hooks } from './plugins/hooks' | ||
8 | import { Notifier } from './notifier' | 18 | import { Notifier } from './notifier' |
9 | import { MUser, MVideoBlacklistVideo, MVideoWithBlacklistLight } from '@server/typings/models' | 19 | import { Hooks } from './plugins/hooks' |
10 | 20 | ||
11 | async function autoBlacklistVideoIfNeeded (parameters: { | 21 | async function autoBlacklistVideoIfNeeded (parameters: { |
12 | video: MVideoWithBlacklistLight | 22 | video: MVideoWithBlacklistLight |
@@ -49,6 +59,60 @@ async function autoBlacklistVideoIfNeeded (parameters: { | |||
49 | return true | 59 | return true |
50 | } | 60 | } |
51 | 61 | ||
62 | async function blacklistVideo (videoInstance: MVideoAccountLight, options: VideoBlacklistCreate) { | ||
63 | const blacklist: MVideoBlacklistVideo = await VideoBlacklistModel.create({ | ||
64 | videoId: videoInstance.id, | ||
65 | unfederated: options.unfederate === true, | ||
66 | reason: options.reason, | ||
67 | type: VideoBlacklistType.MANUAL | ||
68 | } | ||
69 | ) | ||
70 | blacklist.Video = videoInstance | ||
71 | |||
72 | if (options.unfederate === true) { | ||
73 | await sendDeleteVideo(videoInstance, undefined) | ||
74 | } | ||
75 | |||
76 | Notifier.Instance.notifyOnVideoBlacklist(blacklist) | ||
77 | } | ||
78 | |||
79 | async function unblacklistVideo (videoBlacklist: MVideoBlacklist, video: MVideoFullLight) { | ||
80 | const videoBlacklistType = await sequelizeTypescript.transaction(async t => { | ||
81 | const unfederated = videoBlacklist.unfederated | ||
82 | const videoBlacklistType = videoBlacklist.type | ||
83 | |||
84 | await videoBlacklist.destroy({ transaction: t }) | ||
85 | video.VideoBlacklist = undefined | ||
86 | |||
87 | // Re federate the video | ||
88 | if (unfederated === true) { | ||
89 | await federateVideoIfNeeded(video, true, t) | ||
90 | } | ||
91 | |||
92 | return videoBlacklistType | ||
93 | }) | ||
94 | |||
95 | Notifier.Instance.notifyOnVideoUnblacklist(video) | ||
96 | |||
97 | if (videoBlacklistType === VideoBlacklistType.AUTO_BEFORE_PUBLISHED) { | ||
98 | Notifier.Instance.notifyOnVideoPublishedAfterRemovedFromAutoBlacklist(video) | ||
99 | |||
100 | // Delete on object so new video notifications will send | ||
101 | delete video.VideoBlacklist | ||
102 | Notifier.Instance.notifyOnNewVideoIfNeeded(video) | ||
103 | } | ||
104 | } | ||
105 | |||
106 | // --------------------------------------------------------------------------- | ||
107 | |||
108 | export { | ||
109 | autoBlacklistVideoIfNeeded, | ||
110 | blacklistVideo, | ||
111 | unblacklistVideo | ||
112 | } | ||
113 | |||
114 | // --------------------------------------------------------------------------- | ||
115 | |||
52 | function autoBlacklistNeeded (parameters: { | 116 | function autoBlacklistNeeded (parameters: { |
53 | video: MVideoWithBlacklistLight | 117 | video: MVideoWithBlacklistLight |
54 | isRemote: boolean | 118 | isRemote: boolean |
@@ -66,9 +130,3 @@ function autoBlacklistNeeded (parameters: { | |||
66 | 130 | ||
67 | return true | 131 | return true |
68 | } | 132 | } |
69 | |||
70 | // --------------------------------------------------------------------------- | ||
71 | |||
72 | export { | ||
73 | autoBlacklistVideoIfNeeded | ||
74 | } | ||