aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/process/process-create.ts3
-rw-r--r--server/lib/activitypub/process/process-update.ts3
-rw-r--r--server/lib/redundancy.ts27
3 files changed, 32 insertions, 1 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts
index bee853721..d375e29e3 100644
--- a/server/lib/activitypub/process/process-create.ts
+++ b/server/lib/activitypub/process/process-create.ts
@@ -12,6 +12,7 @@ import { PlaylistObject } from '../../../../shared/models/activitypub/objects/pl
12import { createOrUpdateVideoPlaylist } from '../playlist' 12import { createOrUpdateVideoPlaylist } from '../playlist'
13import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 13import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
14import { MActorSignature, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../../typings/models' 14import { MActorSignature, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../../typings/models'
15import { isRedundancyAccepted } from '@server/lib/redundancy'
15 16
16async function processCreateActivity (options: APProcessorOptions<ActivityCreate>) { 17async function processCreateActivity (options: APProcessorOptions<ActivityCreate>) {
17 const { activity, byActor } = options 18 const { activity, byActor } = options
@@ -60,6 +61,8 @@ async function processCreateVideo (activity: ActivityCreate, notify: boolean) {
60} 61}
61 62
62async function processCreateCacheFile (activity: ActivityCreate, byActor: MActorSignature) { 63async function processCreateCacheFile (activity: ActivityCreate, byActor: MActorSignature) {
64 if (await isRedundancyAccepted(activity, byActor) !== true) return
65
63 const cacheFile = activity.object as CacheFileObject 66 const cacheFile = activity.object as CacheFileObject
64 67
65 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object }) 68 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object })
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index a47d605d8..9579512b7 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -16,6 +16,7 @@ import { PlaylistObject } from '../../../../shared/models/activitypub/objects/pl
16import { createOrUpdateVideoPlaylist } from '../playlist' 16import { createOrUpdateVideoPlaylist } from '../playlist'
17import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 17import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
18import { MActorSignature, MAccountIdActor } from '../../../typings/models' 18import { MActorSignature, MAccountIdActor } from '../../../typings/models'
19import { isRedundancyAccepted } from '@server/lib/redundancy'
19 20
20async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate>) { 21async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate>) {
21 const { activity, byActor } = options 22 const { activity, byActor } = options
@@ -78,6 +79,8 @@ async function processUpdateVideo (actor: MActorSignature, activity: ActivityUpd
78} 79}
79 80
80async function processUpdateCacheFile (byActor: MActorSignature, activity: ActivityUpdate) { 81async function processUpdateCacheFile (byActor: MActorSignature, activity: ActivityUpdate) {
82 if (await isRedundancyAccepted(activity, byActor) !== true) return
83
81 const cacheFileObject = activity.object as CacheFileObject 84 const cacheFileObject = activity.object as CacheFileObject
82 85
83 if (!isCacheFileObjectValid(cacheFileObject)) { 86 if (!isCacheFileObjectValid(cacheFileObject)) {
diff --git a/server/lib/redundancy.ts b/server/lib/redundancy.ts
index 78d84e02e..aa0e37478 100644
--- a/server/lib/redundancy.ts
+++ b/server/lib/redundancy.ts
@@ -2,7 +2,11 @@ import { VideoRedundancyModel } from '../models/redundancy/video-redundancy'
2import { sendUndoCacheFile } from './activitypub/send' 2import { sendUndoCacheFile } from './activitypub/send'
3import { Transaction } from 'sequelize' 3import { Transaction } from 'sequelize'
4import { getServerActor } from '../helpers/utils' 4import { getServerActor } from '../helpers/utils'
5import { MVideoRedundancyVideo } from '@server/typings/models' 5import { MActorSignature, MVideoRedundancyVideo } from '@server/typings/models'
6import { CONFIG } from '@server/initializers/config'
7import { logger } from '@server/helpers/logger'
8import { ActorFollowModel } from '@server/models/activitypub/actor-follow'
9import { Activity } from '@shared/models'
6 10
7async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t?: Transaction) { 11async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t?: Transaction) {
8 const serverActor = await getServerActor() 12 const serverActor = await getServerActor()
@@ -21,9 +25,30 @@ async function removeRedundanciesOfServer (serverId: number) {
21 } 25 }
22} 26}
23 27
28async function isRedundancyAccepted (activity: Activity, byActor: MActorSignature) {
29 const configAcceptFrom = CONFIG.REMOTE_REDUNDANCY.VIDEOS.ACCEPT_FROM
30 if (configAcceptFrom === 'nobody') {
31 logger.info('Do not accept remote redundancy %s due instance accept policy.', activity.id)
32 return false
33 }
34
35 if (configAcceptFrom === 'followings') {
36 const serverActor = await getServerActor()
37 const allowed = await ActorFollowModel.isFollowedBy(byActor.id, serverActor.id)
38
39 if (allowed !== true) {
40 logger.info('Do not accept remote redundancy %s because actor %s is not followed by our instance.', activity.id, byActor.url)
41 return false
42 }
43 }
44
45 return true
46}
47
24// --------------------------------------------------------------------------- 48// ---------------------------------------------------------------------------
25 49
26export { 50export {
51 isRedundancyAccepted,
27 removeRedundanciesOfServer, 52 removeRedundanciesOfServer,
28 removeVideoRedundancy 53 removeVideoRedundancy
29} 54}