2017-11-20 02:43:39 -06:00
|
|
|
import { ActivityDelete } from '../../../../shared/models/activitypub/activity'
|
|
|
|
import { retryTransactionWrapper } from '../../../helpers/database-utils'
|
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
|
import { database as db } from '../../../initializers'
|
|
|
|
import { AccountInstance } from '../../../models/account/account-interface'
|
|
|
|
import { VideoChannelInstance } from '../../../models/video/video-channel-interface'
|
|
|
|
import { VideoInstance } from '../../../models/video/video-interface'
|
2017-11-21 06:43:29 -06:00
|
|
|
import { getOrCreateAccountAndServer } from '../account'
|
2017-11-13 10:39:41 -06:00
|
|
|
|
|
|
|
async function processDeleteActivity (activity: ActivityDelete) {
|
2017-11-21 06:43:29 -06:00
|
|
|
const account = await getOrCreateAccountAndServer(activity.actor)
|
2017-11-13 10:39:41 -06:00
|
|
|
|
|
|
|
if (account.url === activity.id) {
|
|
|
|
return processDeleteAccount(account)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-11-16 08:55:01 -06:00
|
|
|
let videoObject = await db.Video.loadByUrlAndPopulateAccount(activity.id)
|
2017-11-13 10:39:41 -06:00
|
|
|
if (videoObject !== undefined) {
|
|
|
|
return processDeleteVideo(account, videoObject)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let videoChannelObject = await db.VideoChannel.loadByUrl(activity.id)
|
|
|
|
if (videoChannelObject !== undefined) {
|
|
|
|
return processDeleteVideoChannel(account, videoChannelObject)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 08:52:26 -06:00
|
|
|
return
|
2017-11-13 10:39:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
processDeleteActivity
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
async function processDeleteVideo (account: AccountInstance, videoToDelete: VideoInstance) {
|
|
|
|
const options = {
|
|
|
|
arguments: [ account, videoToDelete ],
|
|
|
|
errorMessage: 'Cannot remove the remote video with many retries.'
|
|
|
|
}
|
|
|
|
|
|
|
|
await retryTransactionWrapper(deleteRemoteVideo, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteRemoteVideo (account: AccountInstance, videoToDelete: VideoInstance) {
|
|
|
|
logger.debug('Removing remote video "%s".', videoToDelete.uuid)
|
|
|
|
|
|
|
|
await db.sequelize.transaction(async t => {
|
|
|
|
if (videoToDelete.VideoChannel.Account.id !== account.id) {
|
|
|
|
throw new Error('Account ' + account.url + ' does not own video channel ' + videoToDelete.VideoChannel.url)
|
|
|
|
}
|
|
|
|
|
|
|
|
await videoToDelete.destroy({ transaction: t })
|
|
|
|
})
|
|
|
|
|
|
|
|
logger.info('Remote video with uuid %s removed.', videoToDelete.uuid)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function processDeleteVideoChannel (account: AccountInstance, videoChannelToRemove: VideoChannelInstance) {
|
|
|
|
const options = {
|
|
|
|
arguments: [ account, videoChannelToRemove ],
|
|
|
|
errorMessage: 'Cannot remove the remote video channel with many retries.'
|
|
|
|
}
|
|
|
|
|
|
|
|
await retryTransactionWrapper(deleteRemoteVideoChannel, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteRemoteVideoChannel (account: AccountInstance, videoChannelToRemove: VideoChannelInstance) {
|
|
|
|
logger.debug('Removing remote video channel "%s".', videoChannelToRemove.uuid)
|
|
|
|
|
|
|
|
await db.sequelize.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: AccountInstance) {
|
|
|
|
const options = {
|
|
|
|
arguments: [ accountToRemove ],
|
|
|
|
errorMessage: 'Cannot remove the remote account with many retries.'
|
|
|
|
}
|
|
|
|
|
|
|
|
await retryTransactionWrapper(deleteRemoteAccount, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteRemoteAccount (accountToRemove: AccountInstance) {
|
|
|
|
logger.debug('Removing remote account "%s".', accountToRemove.uuid)
|
|
|
|
|
|
|
|
await db.sequelize.transaction(async t => {
|
|
|
|
await accountToRemove.destroy({ transaction: t })
|
|
|
|
})
|
|
|
|
|
|
|
|
logger.info('Remote account with uuid %s removed.', accountToRemove.uuid)
|
|
|
|
}
|