]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/redundancy.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / redundancy.ts
1 import { VideoRedundancyModel } from '../models/redundancy/video-redundancy'
2 import { sendUndoCacheFile } from './activitypub/send'
3 import { Transaction } from 'sequelize'
4 import { getServerActor } from '../helpers/utils'
5 import { MVideoRedundancyVideo } from '@server/typings/models'
6
7 async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t?: Transaction) {
8 const serverActor = await getServerActor()
9
10 // Local cache, send undo to remote instances
11 if (videoRedundancy.actorId === serverActor.id) await sendUndoCacheFile(serverActor, videoRedundancy, t)
12
13 await videoRedundancy.destroy({ transaction: t })
14 }
15
16 async function removeRedundanciesOfServer (serverId: number) {
17 const redundancies = await VideoRedundancyModel.listLocalOfServer(serverId)
18
19 for (const redundancy of redundancies) {
20 await removeVideoRedundancy(redundancy)
21 }
22 }
23
24 // ---------------------------------------------------------------------------
25
26 export {
27 removeRedundanciesOfServer,
28 removeVideoRedundancy
29 }