1 import { VideoRedundancyModel } from '../models/redundancy/video-redundancy'
2 import { sendUndoCacheFile } from './activitypub/send'
3 import { Transaction } from 'sequelize'
4 import { MActorSignature, MVideoRedundancyVideo } from '@server/types/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'
11 async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t?: Transaction) {
12 const serverActor = await getServerActor()
14 // Local cache, send undo to remote instances
15 if (videoRedundancy.actorId === serverActor.id) await sendUndoCacheFile(serverActor, videoRedundancy, t)
17 await videoRedundancy.destroy({ transaction: t })
20 async function removeRedundanciesOfServer (serverId: number) {
21 const redundancies = await VideoRedundancyModel.listLocalOfServer(serverId)
23 for (const redundancy of redundancies) {
24 await removeVideoRedundancy(redundancy)
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)
35 if (configAcceptFrom === 'followings') {
36 const serverActor = await getServerActor()
37 const allowed = await ActorFollowModel.isFollowedBy(byActor.id, serverActor.id)
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)
48 // ---------------------------------------------------------------------------
52 removeRedundanciesOfServer,