Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Support Service AP actors

Chocobozzz346be1d4781d
diff --git a/server/core/helpers/actors.ts b/server/core/helpers/actors.ts
index 5be5c9ee79..5e92fc0082 100644
--- a/server/core/helpers/actors.ts
+++ b/server/core/helpers/actors.ts
@@ -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'
}
diff --git a/server/core/helpers/custom-validators/activitypub/actor.ts b/server/core/helpers/custom-validators/activitypub/actor.ts
index 71ddbc323e..bcd37ffa10 100644
--- a/server/core/helpers/custom-validators/activitypub/actor.ts
+++ b/server/core/helpers/custom-validators/activitypub/actor.ts
@@ -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) {
diff --git a/server/core/lib/activitypub/actors/shared/creator.ts b/server/core/lib/activitypub/actors/shared/creator.ts
index 426f918fbc..a7e3f7f017 100644
--- a/server/core/lib/activitypub/actors/shared/creator.ts
+++ b/server/core/lib/activitypub/actors/shared/creator.ts
@@ -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 })
}
diff --git a/server/core/lib/activitypub/process/process-announce.ts b/server/core/lib/activitypub/process/process-announce.ts
index ac135eae24..8500efd4d5 100644
--- a/server/core/lib/activitypub/process/process-announce.ts
+++ b/server/core/lib/activitypub/process/process-announce.ts
@@ -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)
diff --git a/server/core/lib/activitypub/process/process-delete.ts b/server/core/lib/activitypub/process/process-delete.ts
index 46ca0d73e9..0e9f8888eb 100644
--- a/server/core/lib/activitypub/process/process-delete.ts
+++ b/server/core/lib/activitypub/process/process-delete.ts
@@ -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 }
diff --git a/server/core/lib/activitypub/process/process-update.ts b/server/core/lib/activitypub/process/process-update.ts
index e8a5dcb609..e96d43b708 100644
--- a/server/core/lib/activitypub/process/process-update.ts
+++ b/server/core/lib/activitypub/process/process-update.ts
@@ -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)