aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-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
8 files changed, 23 insertions, 17 deletions
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