diff options
Diffstat (limited to 'server/lib/redundancy.ts')
-rw-r--r-- | server/lib/redundancy.ts | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/server/lib/redundancy.ts b/server/lib/redundancy.ts index 1b4ecd7c0..361b401a5 100644 --- a/server/lib/redundancy.ts +++ b/server/lib/redundancy.ts | |||
@@ -1,8 +1,12 @@ | |||
1 | import { VideoRedundancyModel } from '../models/redundancy/video-redundancy' | 1 | import { VideoRedundancyModel } from '../models/redundancy/video-redundancy' |
2 | import { sendUndoCacheFile } from './activitypub/send' | 2 | import { sendUndoCacheFile } from './activitypub/send' |
3 | import { Transaction } from 'sequelize' | 3 | import { Transaction } from 'sequelize' |
4 | import { getServerActor } from '../helpers/utils' | 4 | import { MActorSignature, MVideoRedundancyVideo } from '@server/typings/models' |
5 | import { MVideoRedundancyVideo } from '@server/typings/models' | 5 | import { CONFIG } from '@server/initializers/config' |
6 | import { logger } from '@server/helpers/logger' | ||
7 | import { ActorFollowModel } from '@server/models/activitypub/actor-follow' | ||
8 | import { Activity } from '@shared/models' | ||
9 | import { getServerActor } from '@server/models/application/application' | ||
6 | 10 | ||
7 | async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t?: Transaction) { | 11 | async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t?: Transaction) { |
8 | const serverActor = await getServerActor() | 12 | const serverActor = await getServerActor() |
@@ -13,17 +17,38 @@ async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t? | |||
13 | await videoRedundancy.destroy({ transaction: t }) | 17 | await videoRedundancy.destroy({ transaction: t }) |
14 | } | 18 | } |
15 | 19 | ||
16 | async function removeRedundancyOf (serverId: number) { | 20 | async function removeRedundanciesOfServer (serverId: number) { |
17 | const videosRedundancy = await VideoRedundancyModel.listLocalOfServer(serverId) | 21 | const redundancies = await VideoRedundancyModel.listLocalOfServer(serverId) |
18 | 22 | ||
19 | for (const redundancy of videosRedundancy) { | 23 | for (const redundancy of redundancies) { |
20 | await removeVideoRedundancy(redundancy) | 24 | await removeVideoRedundancy(redundancy) |
21 | } | 25 | } |
22 | } | 26 | } |
23 | 27 | ||
28 | async 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 | ||
26 | export { | 50 | export { |
27 | removeRedundancyOf, | 51 | isRedundancyAccepted, |
52 | removeRedundanciesOfServer, | ||
28 | removeVideoRedundancy | 53 | removeVideoRedundancy |
29 | } | 54 | } |