Support Service AP actors

pull/6449/head
Chocobozzz 2024-06-19 17:08:59 +02:00
parent 42c78c7fcc
commit 346be1d478
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 22 additions and 12 deletions

View File

@ -1,17 +1,22 @@
import { ActivityPubActorType } from '@peertube/peertube-models'
import { WEBSERVER } from '@server/initializers/constants.js'
function handleToNameAndHost (handle: string) {
export function handleToNameAndHost (handle: string) {
let [ name, host ] = handle.split('@')
if (host === WEBSERVER.HOST) host = null
return { name, host, handle }
}
function handlesToNameAndHost (handles: string[]) {
export function handlesToNameAndHost (handles: string[]) {
return handles.map(h => handleToNameAndHost(h))
}
export {
handleToNameAndHost,
handlesToNameAndHost
const accountType = new Set([ 'Person', 'Application', 'Group', 'Service', 'Organization' ])
export function isAccountActor (type: ActivityPubActorType) {
return accountType.has(type)
}
export function isChannelActor (type: ActivityPubActorType) {
return type === 'Group'
}

View File

@ -20,8 +20,9 @@ function isActorPublicKeyObjectValid (publicKeyObject: any) {
isActorPublicKeyValid(publicKeyObject.publicKeyPem)
}
const actorTypes = new Set([ 'Person', 'Application', 'Group', 'Service', 'Organization' ])
function isActorTypeValid (type: string) {
return type === 'Person' || type === 'Application' || type === 'Group' || type === 'Service' || type === 'Organization'
return actorTypes.has(type)
}
function isActorPublicKeyValid (publicKey: string) {

View File

@ -18,6 +18,7 @@ import {
import { updateActorImages } from '../image.js'
import { getActorAttributesFromObject, getActorDisplayNameFromObject, getImagesInfoFromObject } from './object-to-model-attributes.js'
import { fetchActorFollowsCount } from './url-to-object.js'
import { isAccountActor, isChannelActor } from '@server/helpers/actors.js'
export class APActorCreator {
@ -43,12 +44,12 @@ export class APActorCreator {
await this.tryToFixActorUrlIfNeeded(actorCreated, actorInstance, created, t)
if (actorCreated.type === 'Person' || actorCreated.type === 'Application') { // Account or PeerTube instance
if (isAccountActor(actorCreated.type)) {
actorCreated.Account = await this.saveAccount(actorCreated, t) as MAccountDefault
actorCreated.Account.Actor = actorCreated
}
if (actorCreated.type === 'Group') { // Video channel
if (isChannelActor(actorCreated.type)) {
const channel = await this.saveVideoChannel(actorCreated, t)
actorCreated.VideoChannel = Object.assign(channel, { Actor: actorCreated, Account: this.ownerActor.Account })
}

View File

@ -14,7 +14,7 @@ async function processAnnounceActivity (options: APProcessorOptions<ActivityAnno
// Only notify if it is not from a fetcher job
const notify = options.fromFetch !== true
// Announces on accounts are not supported
// Announces by accounts are not supported
if (actorAnnouncer.type !== 'Application' && actorAnnouncer.type !== 'Group') return
return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity, notify)

View File

@ -1,4 +1,5 @@
import { ActivityDelete } from '@peertube/peertube-models'
import { isAccountActor, isChannelActor } from '@server/helpers/actors.js'
import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
import { logger } from '../../../helpers/logger.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
@ -27,14 +28,14 @@ async function processDeleteActivity (options: APProcessorOptions<ActivityDelete
// We need more attributes (all the account and channel)
const byActorFull = await ActorModel.loadByUrlAndPopulateAccountAndChannel(byActor.url)
if (byActorFull.type === 'Person') {
if (isAccountActor(byActorFull.type)) {
if (!byActorFull.Account) throw new Error('Actor ' + byActorFull.url + ' is a person but we cannot find it in database.')
const accountToDelete = byActorFull.Account as MAccountActor
accountToDelete.Actor = byActorFull
return retryTransactionWrapper(processDeleteAccount, accountToDelete)
} else if (byActorFull.type === 'Group') {
} else if (isChannelActor(byActorFull.type)) {
if (!byActorFull.VideoChannel) throw new Error('Actor ' + byActorFull.url + ' is a group but we cannot find it in database.')
const channelToDelete = byActorFull.VideoChannel as MChannelAccountActor & { Actor: MActorFull }

View File

@ -1,11 +1,13 @@
import {
ActivityPubActor,
ActivityPubActorType,
ActivityUpdate,
ActivityUpdateObject,
CacheFileObject,
PlaylistObject,
VideoObject
} from '@peertube/peertube-models'
import { isAccountActor } from '@server/helpers/actors.js'
import { isRedundancyAccepted } from '@server/lib/redundancy.js'
import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file.js'
import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos.js'
@ -32,7 +34,7 @@ async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate
return retryTransactionWrapper(processUpdateVideo, activity)
}
if (objectType === 'Person' || objectType === 'Application' || objectType === 'Group') {
if (isAccountActor(objectType as ActivityPubActorType)) {
// We need more attributes
const byActorFull = await ActorModel.loadByUrlAndPopulateAccountAndChannel(byActor.url)
return retryTransactionWrapper(processUpdateActor, byActorFull, object)