aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-23 12:04:15 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit5b77537ce54832f47931ba47dc513be2a9197f92 (patch)
tree4f968168f1346faa82ac6c9663778e1cca65b02a /server
parentd8e9a42c4b048b2669ab6a61704682ce23fbcf99 (diff)
downloadPeerTube-5b77537ce54832f47931ba47dc513be2a9197f92.tar.gz
PeerTube-5b77537ce54832f47931ba47dc513be2a9197f92.tar.zst
PeerTube-5b77537ce54832f47931ba47dc513be2a9197f92.zip
Correctly notify on auto blacklist
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/blacklist.ts3
-rw-r--r--server/controllers/api/videos/import.ts9
-rw-r--r--server/controllers/api/videos/index.ts19
-rw-r--r--server/helpers/custom-validators/video-channels.ts17
-rw-r--r--server/lib/activitypub/process/process-announce.ts2
-rw-r--r--server/lib/activitypub/process/process-create.ts4
-rw-r--r--server/lib/activitypub/videos.ts13
-rw-r--r--server/lib/job-queue/handlers/video-import.ts4
-rw-r--r--server/lib/job-queue/handlers/video-transcoding.ts4
-rw-r--r--server/lib/notifier.ts4
-rw-r--r--server/lib/schedulers/update-videos-scheduler.ts2
-rw-r--r--server/lib/video-blacklist.ts7
-rw-r--r--server/models/video/video.ts4
-rw-r--r--server/tests/cli/optimize-old-videos.ts2
14 files changed, 46 insertions, 48 deletions
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts
index 0ec518e0d..9ff494def 100644
--- a/server/controllers/api/videos/blacklist.ts
+++ b/server/controllers/api/videos/blacklist.ts
@@ -115,6 +115,7 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex
115 const videoBlacklistType = videoBlacklist.type 115 const videoBlacklistType = videoBlacklist.type
116 116
117 await videoBlacklist.destroy({ transaction: t }) 117 await videoBlacklist.destroy({ transaction: t })
118 video.VideoBlacklist = undefined
118 119
119 // Re federate the video 120 // Re federate the video
120 if (unfederated === true) { 121 if (unfederated === true) {
@@ -131,7 +132,7 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex
131 132
132 // Delete on object so new video notifications will send 133 // Delete on object so new video notifications will send
133 delete video.VideoBlacklist 134 delete video.VideoBlacklist
134 Notifier.Instance.notifyOnNewVideo(video) 135 Notifier.Instance.notifyOnNewVideoIfNeeded(video)
135 } 136 }
136 137
137 logger.info('Video %s removed from blacklist.', res.locals.video.uuid) 138 logger.info('Video %s removed from blacklist.', res.locals.video.uuid)
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index 47c6f122c..1f08fe20a 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -245,7 +245,14 @@ function insertIntoDB (parameters: {
245 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) 245 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
246 if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) 246 if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
247 247
248 await autoBlacklistVideoIfNeeded({ video, user, isRemote: false, isNew: true, transaction: t }) 248 await autoBlacklistVideoIfNeeded({
249 video,
250 user,
251 notify: false,
252 isRemote: false,
253 isNew: true,
254 transaction: t
255 })
249 256
250 // Set tags to the video 257 // Set tags to the video
251 if (tags) { 258 if (tags) {
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 6a79a16c7..973bf1123 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -235,7 +235,7 @@ async function addVideo (req: express.Request, res: express.Response) {
235 // Create the torrent file 235 // Create the torrent file
236 await video.createTorrentAndSetInfoHash(videoFile) 236 await video.createTorrentAndSetInfoHash(videoFile)
237 237
238 const { videoCreated, videoWasAutoBlacklisted } = await sequelizeTypescript.transaction(async t => { 238 const { videoCreated } = await sequelizeTypescript.transaction(async t => {
239 const sequelizeOptions = { transaction: t } 239 const sequelizeOptions = { transaction: t }
240 240
241 const videoCreated = await video.save(sequelizeOptions) 241 const videoCreated = await video.save(sequelizeOptions)
@@ -268,23 +268,22 @@ async function addVideo (req: express.Request, res: express.Response) {
268 }, { transaction: t }) 268 }, { transaction: t })
269 } 269 }
270 270
271 const videoWasAutoBlacklisted = await autoBlacklistVideoIfNeeded({ 271 await autoBlacklistVideoIfNeeded({
272 video, 272 video,
273 user: res.locals.oauth.token.User, 273 user: res.locals.oauth.token.User,
274 isRemote: false, 274 isRemote: false,
275 isNew: true, 275 isNew: true,
276 transaction: t 276 transaction: t
277 }) 277 })
278 if (!videoWasAutoBlacklisted) await federateVideoIfNeeded(video, true, t) 278 await federateVideoIfNeeded(video, true, t)
279 279
280 auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON())) 280 auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON()))
281 logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) 281 logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid)
282 282
283 return { videoCreated, videoWasAutoBlacklisted } 283 return { videoCreated }
284 }) 284 })
285 285
286 if (videoWasAutoBlacklisted) Notifier.Instance.notifyOnVideoAutoBlacklist(videoCreated) 286 Notifier.Instance.notifyOnNewVideoIfNeeded(videoCreated)
287 else Notifier.Instance.notifyOnNewVideo(videoCreated)
288 287
289 if (video.state === VideoState.TO_TRANSCODE) { 288 if (video.state === VideoState.TO_TRANSCODE) {
290 // Put uuid because we don't have id auto incremented for now 289 // Put uuid because we don't have id auto incremented for now
@@ -413,11 +412,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
413 }) 412 })
414 413
415 const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE 414 const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
416 415 await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
417 // Don't send update if the video was unfederated
418 if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) {
419 await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
420 }
421 416
422 auditLogger.update( 417 auditLogger.update(
423 getAuditIdFromRes(res), 418 getAuditIdFromRes(res),
@@ -430,7 +425,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
430 }) 425 })
431 426
432 if (wasUnlistedVideo || wasPrivateVideo) { 427 if (wasUnlistedVideo || wasPrivateVideo) {
433 Notifier.Instance.notifyOnNewVideo(videoInstanceUpdated) 428 Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated)
434 } 429 }
435 430
436 Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated }) 431 Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated })
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts
index 0471f6ec4..f55f0c8ef 100644
--- a/server/helpers/custom-validators/video-channels.ts
+++ b/server/helpers/custom-validators/video-channels.ts
@@ -1,9 +1,7 @@
1import * as express from 'express'
2import 'express-validator' 1import 'express-validator'
3import 'multer' 2import 'multer'
4import * as validator from 'validator' 3import * as validator from 'validator'
5import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 4import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
6import { VideoChannelModel } from '../../models/video/video-channel'
7import { exists } from './misc' 5import { exists } from './misc'
8 6
9const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS 7const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS
@@ -25,18 +23,5 @@ function isVideoChannelSupportValid (value: string) {
25export { 23export {
26 isVideoChannelDescriptionValid, 24 isVideoChannelDescriptionValid,
27 isVideoChannelNameValid, 25 isVideoChannelNameValid,
28 isVideoChannelSupportValid, 26 isVideoChannelSupportValid
29}
30
31function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) {
32 if (!videoChannel) {
33 res.status(404)
34 .json({ error: 'Video channel not found' })
35 .end()
36
37 return false
38 }
39
40 res.locals.videoChannel = videoChannel
41 return true
42} 27}
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts
index bbf1bd3a8..1fe347506 100644
--- a/server/lib/activitypub/process/process-announce.ts
+++ b/server/lib/activitypub/process/process-announce.ts
@@ -63,5 +63,5 @@ async function processVideoShare (actorAnnouncer: ActorModel, activity: Activity
63 return undefined 63 return undefined
64 }) 64 })
65 65
66 if (videoCreated) Notifier.Instance.notifyOnNewVideo(video) 66 if (videoCreated) Notifier.Instance.notifyOnNewVideoIfNeeded(video)
67} 67}
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts
index b9f584aa5..1e893cdeb 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, autoBlacklisted } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoToCreateData }) 51 const { video, created } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoToCreateData })
52 52
53 if (created && !autoBlacklisted) Notifier.Instance.notifyOnNewVideo(video) 53 if (created) Notifier.Instance.notifyOnNewVideoIfNeeded(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 67b433165..d7bc3d650 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -58,8 +58,12 @@ import { Hooks } from '../plugins/hooks'
58import { autoBlacklistVideoIfNeeded } from '../video-blacklist' 58import { autoBlacklistVideoIfNeeded } from '../video-blacklist'
59 59
60async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) { 60async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) {
61 // If the video is not private and is published, we federate it 61 if (
62 if (video.privacy !== VideoPrivacy.PRIVATE && video.state === VideoState.PUBLISHED) { 62 // Check this is not a blacklisted video, or unfederated blacklisted video
63 (video.isBlacklisted() === false || (isNewVideo === false && video.VideoBlacklist.unfederated === false)) &&
64 // Check the video is public/unlisted and published
65 video.privacy !== VideoPrivacy.PRIVATE && video.state === VideoState.PUBLISHED
66 ) {
63 // Fetch more attributes that we will need to serialize in AP object 67 // Fetch more attributes that we will need to serialize in AP object
64 if (isArray(video.VideoCaptions) === false) { 68 if (isArray(video.VideoCaptions) === false) {
65 video.VideoCaptions = await video.$get('VideoCaptions', { 69 video.VideoCaptions = await video.$get('VideoCaptions', {
@@ -354,7 +358,7 @@ async function updateVideoFromAP (options: {
354 } 358 }
355 }) 359 })
356 360
357 const autoBlacklisted = await autoBlacklistVideoIfNeeded({ 361 await autoBlacklistVideoIfNeeded({
358 video, 362 video,
359 user: undefined, 363 user: undefined,
360 isRemote: true, 364 isRemote: true,
@@ -362,8 +366,7 @@ async function updateVideoFromAP (options: {
362 transaction: undefined 366 transaction: undefined
363 }) 367 })
364 368
365 if (autoBlacklisted) Notifier.Instance.notifyOnVideoAutoBlacklist(video) 369 if (wasPrivateVideo || wasUnlistedVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(video) // Notify our users?
366 else if (!wasPrivateVideo || wasUnlistedVideo) Notifier.Instance.notifyOnNewVideo(video) // Notify our users?
367 370
368 logger.info('Remote video with uuid %s updated', videoObject.uuid) 371 logger.info('Remote video with uuid %s updated', videoObject.uuid)
369 } catch (err) { 372 } catch (err) {
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index 50e159245..13b741180 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -199,10 +199,10 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
199 199
200 Notifier.Instance.notifyOnFinishedVideoImport(videoImportUpdated, true) 200 Notifier.Instance.notifyOnFinishedVideoImport(videoImportUpdated, true)
201 201
202 if (videoImportUpdated.Video.VideoBlacklist) { 202 if (videoImportUpdated.Video.isBlacklisted()) {
203 Notifier.Instance.notifyOnVideoAutoBlacklist(videoImportUpdated.Video) 203 Notifier.Instance.notifyOnVideoAutoBlacklist(videoImportUpdated.Video)
204 } else { 204 } else {
205 Notifier.Instance.notifyOnNewVideo(videoImportUpdated.Video) 205 Notifier.Instance.notifyOnNewVideoIfNeeded(videoImportUpdated.Video)
206 } 206 }
207 207
208 // Create transcoding jobs? 208 // Create transcoding jobs?
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts
index e9b84ecd6..981daf9a1 100644
--- a/server/lib/job-queue/handlers/video-transcoding.ts
+++ b/server/lib/job-queue/handlers/video-transcoding.ts
@@ -112,7 +112,7 @@ async function publishNewResolutionIfNeeded (video: VideoModel, payload?: NewRes
112 }) 112 })
113 113
114 if (videoPublished) { 114 if (videoPublished) {
115 Notifier.Instance.notifyOnNewVideo(videoDatabase) 115 Notifier.Instance.notifyOnNewVideoIfNeeded(videoDatabase)
116 Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(videoDatabase) 116 Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(videoDatabase)
117 } 117 }
118 118
@@ -172,7 +172,7 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, payload: Optim
172 return { videoDatabase, videoPublished } 172 return { videoDatabase, videoPublished }
173 }) 173 })
174 174
175 if (payload.isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase) 175 if (payload.isNewVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoDatabase)
176 if (videoPublished) Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(videoDatabase) 176 if (videoPublished) Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(videoDatabase)
177 177
178 const hlsPayload = Object.assign({}, payload, { resolution: videoDatabase.getOriginalFile().resolution }) 178 const hlsPayload = Object.assign({}, payload, { resolution: videoDatabase.getOriginalFile().resolution })
diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts
index c1e63fa8f..a7dfb0979 100644
--- a/server/lib/notifier.ts
+++ b/server/lib/notifier.ts
@@ -22,9 +22,9 @@ class Notifier {
22 22
23 private constructor () {} 23 private constructor () {}
24 24
25 notifyOnNewVideo (video: VideoModel): void { 25 notifyOnNewVideoIfNeeded (video: VideoModel): void {
26 // Only notify on public and published videos which are not blacklisted 26 // Only notify on public and published videos which are not blacklisted
27 if (video.privacy !== VideoPrivacy.PUBLIC || video.state !== VideoState.PUBLISHED || video.VideoBlacklist) return 27 if (video.privacy !== VideoPrivacy.PUBLIC || video.state !== VideoState.PUBLISHED || video.isBlacklisted()) return
28 28
29 this.notifySubscribersOfNewVideo(video) 29 this.notifySubscribersOfNewVideo(video)
30 .catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err })) 30 .catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err }))
diff --git a/server/lib/schedulers/update-videos-scheduler.ts b/server/lib/schedulers/update-videos-scheduler.ts
index 80080a132..5b673b913 100644
--- a/server/lib/schedulers/update-videos-scheduler.ts
+++ b/server/lib/schedulers/update-videos-scheduler.ts
@@ -57,7 +57,7 @@ export class UpdateVideosScheduler extends AbstractScheduler {
57 }) 57 })
58 58
59 for (const v of publishedVideos) { 59 for (const v of publishedVideos) {
60 Notifier.Instance.notifyOnNewVideo(v) 60 Notifier.Instance.notifyOnNewVideoIfNeeded(v)
61 Notifier.Instance.notifyOnVideoPublishedAfterScheduledUpdate(v) 61 Notifier.Instance.notifyOnVideoPublishedAfterScheduledUpdate(v)
62 } 62 }
63 } 63 }
diff --git a/server/lib/video-blacklist.ts b/server/lib/video-blacklist.ts
index 1dd7139f7..bdaecd8e2 100644
--- a/server/lib/video-blacklist.ts
+++ b/server/lib/video-blacklist.ts
@@ -7,15 +7,17 @@ import { VideoModel } from '../models/video/video'
7import { logger } from '../helpers/logger' 7import { 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'
10import { Notifier } from './notifier'
10 11
11async function autoBlacklistVideoIfNeeded (parameters: { 12async function autoBlacklistVideoIfNeeded (parameters: {
12 video: VideoModel, 13 video: VideoModel,
13 user?: UserModel, 14 user?: UserModel,
14 isRemote: boolean, 15 isRemote: boolean,
15 isNew: boolean, 16 isNew: boolean,
17 notify?: boolean,
16 transaction?: Transaction 18 transaction?: Transaction
17}) { 19}) {
18 const { video, user, isRemote, isNew, transaction } = parameters 20 const { video, user, isRemote, isNew, notify = true, transaction } = parameters
19 const doAutoBlacklist = await Hooks.wrapPromiseFun( 21 const doAutoBlacklist = await Hooks.wrapPromiseFun(
20 autoBlacklistNeeded, 22 autoBlacklistNeeded,
21 { video, user, isRemote, isNew }, 23 { video, user, isRemote, isNew },
@@ -37,9 +39,10 @@ async function autoBlacklistVideoIfNeeded (parameters: {
37 defaults: videoBlacklistToCreate, 39 defaults: videoBlacklistToCreate,
38 transaction 40 transaction
39 }) 41 })
40
41 video.VideoBlacklist = videoBlacklist 42 video.VideoBlacklist = videoBlacklist
42 43
44 if (notify) Notifier.Instance.notifyOnVideoAutoBlacklist(video)
45
43 logger.info('Video %s auto-blacklisted.', video.uuid) 46 logger.info('Video %s auto-blacklisted.', video.uuid)
44 47
45 return true 48 return true
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 443aec9c2..c7f2658ed 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1715,6 +1715,10 @@ export class VideoModel extends Model<VideoModel> {
1715 return VIDEO_STATES[ id ] || 'Unknown' 1715 return VIDEO_STATES[ id ] || 'Unknown'
1716 } 1716 }
1717 1717
1718 isBlacklisted () {
1719 return !!this.VideoBlacklist
1720 }
1721
1718 getOriginalFile () { 1722 getOriginalFile () {
1719 if (Array.isArray(this.VideoFiles) === false) return undefined 1723 if (Array.isArray(this.VideoFiles) === false) return undefined
1720 1724
diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts
index 3822fca42..fa82f962c 100644
--- a/server/tests/cli/optimize-old-videos.ts
+++ b/server/tests/cli/optimize-old-videos.ts
@@ -75,7 +75,7 @@ describe('Test optimize old videos', function () {
75 }) 75 })
76 76
77 it('Should run optimize script', async function () { 77 it('Should run optimize script', async function () {
78 this.timeout(120000) 78 this.timeout(200000)
79 79
80 const env = getEnvCli(servers[0]) 80 const env = getEnvCli(servers[0])
81 await execCLI(`${env} npm run optimize-old-videos`) 81 await execCLI(`${env} npm run optimize-old-videos`)