]>
Commit | Line | Data |
---|---|---|
c48e82b5 | 1 | import { Transaction } from 'sequelize' |
52b1fd15 | 2 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
7d9ba5c0 C |
3 | import { CONFIG } from '@server/initializers/config' |
4 | import { ActorFollowModel } from '@server/models/actor/actor-follow' | |
8dc8a34e | 5 | import { getServerActor } from '@server/models/application/application' |
7d9ba5c0 C |
6 | import { MActorSignature, MVideoRedundancyVideo } from '@server/types/models' |
7 | import { Activity } from '@shared/models' | |
8 | import { VideoRedundancyModel } from '../models/redundancy/video-redundancy' | |
9 | import { sendUndoCacheFile } from './activitypub/send' | |
c48e82b5 | 10 | |
52b1fd15 C |
11 | const lTags = loggerTagsFactory('redundancy') |
12 | ||
453e83ea | 13 | async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t?: Transaction) { |
c48e82b5 C |
14 | const serverActor = await getServerActor() |
15 | ||
e5565833 C |
16 | // Local cache, send undo to remote instances |
17 | if (videoRedundancy.actorId === serverActor.id) await sendUndoCacheFile(serverActor, videoRedundancy, t) | |
c48e82b5 C |
18 | |
19 | await videoRedundancy.destroy({ transaction: t }) | |
20 | } | |
21 | ||
b764380a C |
22 | async function removeRedundanciesOfServer (serverId: number) { |
23 | const redundancies = await VideoRedundancyModel.listLocalOfServer(serverId) | |
161b061d | 24 | |
b764380a | 25 | for (const redundancy of redundancies) { |
161b061d C |
26 | await removeVideoRedundancy(redundancy) |
27 | } | |
28 | } | |
29 | ||
8c9e7875 C |
30 | async function isRedundancyAccepted (activity: Activity, byActor: MActorSignature) { |
31 | const configAcceptFrom = CONFIG.REMOTE_REDUNDANCY.VIDEOS.ACCEPT_FROM | |
32 | if (configAcceptFrom === 'nobody') { | |
52b1fd15 | 33 | logger.info('Do not accept remote redundancy %s due instance accept policy.', activity.id, lTags()) |
8c9e7875 C |
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) { | |
52b1fd15 C |
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 | ) | |
8c9e7875 C |
46 | return false |
47 | } | |
48 | } | |
49 | ||
50 | return true | |
51 | } | |
52 | ||
c48e82b5 C |
53 | // --------------------------------------------------------------------------- |
54 | ||
55 | export { | |
8c9e7875 | 56 | isRedundancyAccepted, |
b764380a | 57 | removeRedundanciesOfServer, |
c48e82b5 C |
58 | removeVideoRedundancy |
59 | } |