Delete remote actor too

pull/6610/head
Chocobozzz 2024-09-17 08:31:32 +02:00
parent d794988ebd
commit 5ae90e0757
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 28 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import { Account, AccountSummary } from '@peertube/peertube-models'
import { ModelCache } from '@server/models/shared/model-cache.js' import { ModelCache } from '@server/models/shared/model-cache.js'
import { FindOptions, IncludeOptions, Includeable, Op, Transaction, WhereOptions } from 'sequelize' import { FindOptions, IncludeOptions, Includeable, Op, Transaction, WhereOptions } from 'sequelize'
import { import {
AfterDestroy,
AllowNull, AllowNull,
BeforeDestroy, BeforeDestroy,
BelongsTo, Column, BelongsTo, Column,
@ -270,6 +271,18 @@ export class AccountModel extends SequelizeModel<AccountModel> {
return undefined return undefined
} }
@AfterDestroy
static async deleteActorIfRemote (instance: AccountModel, options) {
if (!instance.Actor) {
instance.Actor = await instance.$get('Actor', { transaction: options.transaction })
}
// Remote actor, delete it
if (instance.Actor.serverId) {
await instance.Actor.destroy({ transaction: options.transaction })
}
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
static getSQLAttributes (tableName: string, aliasPrefix = '') { static getSQLAttributes (tableName: string, aliasPrefix = '') {

View File

@ -33,10 +33,11 @@ import { sendDeleteActor } from '../../lib/activitypub/send/index.js'
import { import {
MChannelAP, MChannelAP,
MChannelBannerAccountDefault, MChannelBannerAccountDefault,
MChannelDefault,
MChannelFormattable, MChannelFormattable,
MChannelHost, MChannelHost,
MChannelSummaryFormattable, MChannelSummaryFormattable,
type MChannel, MChannelDefault type MChannel
} from '../../types/models/video/index.js' } from '../../types/models/video/index.js'
import { AccountModel, ScopeNames as AccountModelScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account.js' import { AccountModel, ScopeNames as AccountModelScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account.js'
import { ActorFollowModel } from '../actor/actor-follow.js' import { ActorFollowModel } from '../actor/actor-follow.js'
@ -44,11 +45,11 @@ import { ActorImageModel } from '../actor/actor-image.js'
import { ActorModel, unusedActorAttributesForAPI } from '../actor/actor.js' import { ActorModel, unusedActorAttributesForAPI } from '../actor/actor.js'
import { ServerModel } from '../server/server.js' import { ServerModel } from '../server/server.js'
import { import {
SequelizeModel,
buildServerIdsFollowedBy, buildServerIdsFollowedBy,
buildTrigramSearchIndex, buildTrigramSearchIndex,
createSimilarityAttribute, createSimilarityAttribute,
getSort, getSort,
SequelizeModel,
setAsUpdated, setAsUpdated,
throwIfNotValid throwIfNotValid
} from '../shared/index.js' } from '../shared/index.js'
@ -447,6 +448,18 @@ export class VideoChannelModel extends SequelizeModel<VideoChannelModel> {
return undefined return undefined
} }
@AfterDestroy
static async deleteActorIfRemote (instance: VideoChannelModel, options) {
if (!instance.Actor) {
instance.Actor = await instance.$get('Actor', { transaction: options.transaction })
}
// Remote actor, delete it
if (instance.Actor.serverId) {
await instance.Actor.destroy({ transaction: options.transaction })
}
}
static countByAccount (accountId: number) { static countByAccount (accountId: number) {
const query = { const query = {
where: { where: {