]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/activitypub/actor.ts
Add avatar in comments
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / activitypub / actor.ts
index ec8da33509c27a4dbac6d4f247450e626bae21f1..e1a4b5b8f8a40d880b281ebaa1757e2708aeea72 100644 (file)
@@ -1,8 +1,6 @@
 import * as validator from 'validator'
 import { CONSTRAINTS_FIELDS } from '../../../initializers'
-import { isAccountNameValid } from '../accounts'
 import { exists } from '../misc'
-import { isVideoChannelNameValid } from '../video-channels'
 import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
 
 function isActorEndpointsObjectValid (endpointObject: any) {
@@ -24,7 +22,7 @@ function isActorPublicKeyValid (publicKey: string) {
     typeof publicKey === 'string' &&
     publicKey.startsWith('-----BEGIN PUBLIC KEY-----') &&
     publicKey.indexOf('-----END PUBLIC KEY-----') !== -1 &&
-    validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACTOR.PUBLIC_KEY)
+    validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACTORS.PUBLIC_KEY)
 }
 
 const actorNameRegExp = new RegExp('[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_]+')
@@ -32,34 +30,31 @@ function isActorPreferredUsernameValid (preferredUsername: string) {
   return exists(preferredUsername) && validator.matches(preferredUsername, actorNameRegExp)
 }
 
-function isActorNameValid (name: string) {
-  return isAccountNameValid(name) || isVideoChannelNameValid(name)
-}
-
 function isActorPrivateKeyValid (privateKey: string) {
   return exists(privateKey) &&
     typeof privateKey === 'string' &&
     privateKey.startsWith('-----BEGIN RSA PRIVATE KEY-----') &&
     // Sometimes there is a \n at the end, so just assert the string contains the end mark
     privateKey.indexOf('-----END RSA PRIVATE KEY-----') !== -1 &&
-    validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACTOR.PRIVATE_KEY)
+    validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACTORS.PRIVATE_KEY)
 }
 
-function isRemoteActorValid (remoteActor: any) {
-  return isActivityPubUrlValid(remoteActor.id) &&
-    isActorTypeValid(remoteActor.type) &&
-    isActivityPubUrlValid(remoteActor.following) &&
-    isActivityPubUrlValid(remoteActor.followers) &&
-    isActivityPubUrlValid(remoteActor.inbox) &&
-    isActivityPubUrlValid(remoteActor.outbox) &&
-    isActorPreferredUsernameValid(remoteActor.preferredUsername) &&
-    isActivityPubUrlValid(remoteActor.url) &&
-    isActorPublicKeyObjectValid(remoteActor.publicKey) &&
-    isActorEndpointsObjectValid(remoteActor.endpoints) &&
-    setValidAttributedTo(remoteActor) &&
+function isActorObjectValid (actor: any) {
+  return exists(actor) &&
+    isActivityPubUrlValid(actor.id) &&
+    isActorTypeValid(actor.type) &&
+    isActivityPubUrlValid(actor.following) &&
+    isActivityPubUrlValid(actor.followers) &&
+    isActivityPubUrlValid(actor.inbox) &&
+    isActivityPubUrlValid(actor.outbox) &&
+    isActorPreferredUsernameValid(actor.preferredUsername) &&
+    isActivityPubUrlValid(actor.url) &&
+    isActorPublicKeyObjectValid(actor.publicKey) &&
+    isActorEndpointsObjectValid(actor.endpoints) &&
+    setValidAttributedTo(actor) &&
     // If this is not an account, it should be attributed to an account
     // In PeerTube we use this to attach a video channel to a specific account
-    (remoteActor.type === 'Person' || remoteActor.attributedTo.length !== 0)
+    (actor.type === 'Person' || actor.attributedTo.length !== 0)
 }
 
 function isActorFollowingCountValid (value: string) {
@@ -83,6 +78,11 @@ function isActorAcceptActivityValid (activity: any) {
   return isBaseActivityValid(activity, 'Accept')
 }
 
+function isActorUpdateActivityValid (activity: any) {
+  return isBaseActivityValid(activity, 'Update') &&
+    isActorObjectValid(activity.object)
+}
+
 // ---------------------------------------------------------------------------
 
 export {
@@ -92,11 +92,11 @@ export {
   isActorPublicKeyValid,
   isActorPreferredUsernameValid,
   isActorPrivateKeyValid,
-  isRemoteActorValid,
+  isActorObjectValid,
   isActorFollowingCountValid,
   isActorFollowersCountValid,
   isActorFollowActivityValid,
   isActorAcceptActivityValid,
   isActorDeleteActivityValid,
-  isActorNameValid
+  isActorUpdateActivityValid
 }