aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/redundancy.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/redundancy.ts')
-rw-r--r--server/lib/redundancy.ts59
1 files changed, 0 insertions, 59 deletions
diff --git a/server/lib/redundancy.ts b/server/lib/redundancy.ts
deleted file mode 100644
index 2613d01be..000000000
--- a/server/lib/redundancy.ts
+++ /dev/null
@@ -1,59 +0,0 @@
1import { Transaction } from 'sequelize'
2import { logger, loggerTagsFactory } from '@server/helpers/logger'
3import { CONFIG } from '@server/initializers/config'
4import { ActorFollowModel } from '@server/models/actor/actor-follow'
5import { getServerActor } from '@server/models/application/application'
6import { MActorSignature, MVideoRedundancyVideo } from '@server/types/models'
7import { Activity } from '@shared/models'
8import { VideoRedundancyModel } from '../models/redundancy/video-redundancy'
9import { sendUndoCacheFile } from './activitypub/send'
10
11const lTags = loggerTagsFactory('redundancy')
12
13async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t?: Transaction) {
14 const serverActor = await getServerActor()
15
16 // Local cache, send undo to remote instances
17 if (videoRedundancy.actorId === serverActor.id) await sendUndoCacheFile(serverActor, videoRedundancy, t)
18
19 await videoRedundancy.destroy({ transaction: t })
20}
21
22async function removeRedundanciesOfServer (serverId: number) {
23 const redundancies = await VideoRedundancyModel.listLocalOfServer(serverId)
24
25 for (const redundancy of redundancies) {
26 await removeVideoRedundancy(redundancy)
27 }
28}
29
30async function isRedundancyAccepted (activity: Activity, byActor: MActorSignature) {
31 const configAcceptFrom = CONFIG.REMOTE_REDUNDANCY.VIDEOS.ACCEPT_FROM
32 if (configAcceptFrom === 'nobody') {
33 logger.info('Do not accept remote redundancy %s due instance accept policy.', activity.id, lTags())
34 return false
35 }
36
37 if (configAcceptFrom === 'followings') {
38 const serverActor = await getServerActor()
39 const allowed = await ActorFollowModel.isFollowedBy(byActor.id, serverActor.id)
40
41 if (allowed !== true) {
42 logger.info(
43 'Do not accept remote redundancy %s because actor %s is not followed by our instance.',
44 activity.id, byActor.url, lTags()
45 )
46 return false
47 }
48 }
49
50 return true
51}
52
53// ---------------------------------------------------------------------------
54
55export {
56 isRedundancyAccepted,
57 removeRedundanciesOfServer,
58 removeVideoRedundancy
59}