redundancy.ts 949 B

12345678910111213141516171819202122232425262728
  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. async function removeVideoRedundancy (videoRedundancy: VideoRedundancyModel, t?: Transaction) {
  6. const serverActor = await getServerActor()
  7. // Local cache, send undo to remote instances
  8. if (videoRedundancy.actorId === serverActor.id) await sendUndoCacheFile(serverActor, videoRedundancy, t)
  9. await videoRedundancy.destroy({ transaction: t })
  10. }
  11. async function removeRedundancyOf (serverId: number) {
  12. const videosRedundancy = await VideoRedundancyModel.listLocalOfServer(serverId)
  13. for (const redundancy of videosRedundancy) {
  14. await removeVideoRedundancy(redundancy)
  15. }
  16. }
  17. // ---------------------------------------------------------------------------
  18. export {
  19. removeRedundancyOf,
  20. removeVideoRedundancy
  21. }