mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Begin moving video channel to actor
This commit is contained in:
parent
fadf619ad6
commit
50d6de9c28
100 changed files with 1761 additions and 2041 deletions
|
@ -2,28 +2,30 @@ import { ActivityDelete } from '../../../../shared/models/activitypub'
|
|||
import { logger, retryTransactionWrapper } from '../../../helpers'
|
||||
import { sequelizeTypescript } from '../../../initializers'
|
||||
import { AccountModel } from '../../../models/account/account'
|
||||
import { ActorModel } from '../../../models/activitypub/actor'
|
||||
import { VideoModel } from '../../../models/video/video'
|
||||
import { VideoChannelModel } from '../../../models/video/video-channel'
|
||||
import { getOrCreateAccountAndServer } from '../account'
|
||||
import { getOrCreateActorAndServerAndModel } from '../actor'
|
||||
|
||||
async function processDeleteActivity (activity: ActivityDelete) {
|
||||
const account = await getOrCreateAccountAndServer(activity.actor)
|
||||
const actor = await getOrCreateActorAndServerAndModel(activity.actor)
|
||||
|
||||
if (account.url === activity.id) {
|
||||
return processDeleteAccount(account)
|
||||
if (actor.url === activity.id) {
|
||||
if (actor.type === 'Person') {
|
||||
if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.')
|
||||
|
||||
return processDeleteAccount(actor.Account)
|
||||
} else if (actor.type === 'Group') {
|
||||
if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.')
|
||||
|
||||
return processDeleteVideoChannel(actor.VideoChannel)
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let videoObject = await VideoModel.loadByUrlAndPopulateAccount(activity.id)
|
||||
if (videoObject !== undefined) {
|
||||
return processDeleteVideo(account, videoObject)
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let videoChannelObject = await VideoChannelModel.loadByUrl(activity.id)
|
||||
if (videoChannelObject !== undefined) {
|
||||
return processDeleteVideoChannel(account, videoChannelObject)
|
||||
return processDeleteVideo(actor, videoObject)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,21 +40,21 @@ export {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function processDeleteVideo (account: AccountModel, videoToDelete: VideoModel) {
|
||||
async function processDeleteVideo (actor: ActorModel, videoToDelete: VideoModel) {
|
||||
const options = {
|
||||
arguments: [ account, videoToDelete ],
|
||||
arguments: [ actor, videoToDelete ],
|
||||
errorMessage: 'Cannot remove the remote video with many retries.'
|
||||
}
|
||||
|
||||
await retryTransactionWrapper(deleteRemoteVideo, options)
|
||||
}
|
||||
|
||||
async function deleteRemoteVideo (account: AccountModel, videoToDelete: VideoModel) {
|
||||
async function deleteRemoteVideo (actor: ActorModel, videoToDelete: VideoModel) {
|
||||
logger.debug('Removing remote video "%s".', videoToDelete.uuid)
|
||||
|
||||
await sequelizeTypescript.transaction(async t => {
|
||||
if (videoToDelete.VideoChannel.Account.id !== account.id) {
|
||||
throw new Error('Account ' + account.url + ' does not own video channel ' + videoToDelete.VideoChannel.url)
|
||||
if (videoToDelete.VideoChannel.Account.Actor.id !== actor.id) {
|
||||
throw new Error('Account ' + actor.url + ' does not own video channel ' + videoToDelete.VideoChannel.Actor.url)
|
||||
}
|
||||
|
||||
await videoToDelete.destroy({ transaction: t })
|
||||
|
@ -61,29 +63,6 @@ async function deleteRemoteVideo (account: AccountModel, videoToDelete: VideoMod
|
|||
logger.info('Remote video with uuid %s removed.', videoToDelete.uuid)
|
||||
}
|
||||
|
||||
async function processDeleteVideoChannel (account: AccountModel, videoChannelToRemove: VideoChannelModel) {
|
||||
const options = {
|
||||
arguments: [ account, videoChannelToRemove ],
|
||||
errorMessage: 'Cannot remove the remote video channel with many retries.'
|
||||
}
|
||||
|
||||
await retryTransactionWrapper(deleteRemoteVideoChannel, options)
|
||||
}
|
||||
|
||||
async function deleteRemoteVideoChannel (account: AccountModel, videoChannelToRemove: VideoChannelModel) {
|
||||
logger.debug('Removing remote video channel "%s".', videoChannelToRemove.uuid)
|
||||
|
||||
await sequelizeTypescript.transaction(async t => {
|
||||
if (videoChannelToRemove.Account.id !== account.id) {
|
||||
throw new Error('Account ' + account.url + ' does not own video channel ' + videoChannelToRemove.url)
|
||||
}
|
||||
|
||||
await videoChannelToRemove.destroy({ transaction: t })
|
||||
})
|
||||
|
||||
logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.uuid)
|
||||
}
|
||||
|
||||
async function processDeleteAccount (accountToRemove: AccountModel) {
|
||||
const options = {
|
||||
arguments: [ accountToRemove ],
|
||||
|
@ -94,11 +73,30 @@ async function processDeleteAccount (accountToRemove: AccountModel) {
|
|||
}
|
||||
|
||||
async function deleteRemoteAccount (accountToRemove: AccountModel) {
|
||||
logger.debug('Removing remote account "%s".', accountToRemove.uuid)
|
||||
logger.debug('Removing remote account "%s".', accountToRemove.Actor.uuid)
|
||||
|
||||
await sequelizeTypescript.transaction(async t => {
|
||||
await accountToRemove.destroy({ transaction: t })
|
||||
})
|
||||
|
||||
logger.info('Remote account with uuid %s removed.', accountToRemove.uuid)
|
||||
logger.info('Remote account with uuid %s removed.', accountToRemove.Actor.uuid)
|
||||
}
|
||||
|
||||
async function processDeleteVideoChannel (videoChannelToRemove: VideoChannelModel) {
|
||||
const options = {
|
||||
arguments: [ videoChannelToRemove ],
|
||||
errorMessage: 'Cannot remove the remote video channel with many retries.'
|
||||
}
|
||||
|
||||
await retryTransactionWrapper(deleteRemoteVideoChannel, options)
|
||||
}
|
||||
|
||||
async function deleteRemoteVideoChannel (videoChannelToRemove: VideoChannelModel) {
|
||||
logger.debug('Removing remote video channel "%s".', videoChannelToRemove.Actor.uuid)
|
||||
|
||||
await sequelizeTypescript.transaction(async t => {
|
||||
await videoChannelToRemove.destroy({ transaction: t })
|
||||
})
|
||||
|
||||
logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.Actor.uuid)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue