aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/activitypub/actor.ts39
1 files changed, 18 insertions, 21 deletions
diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts
index 877345157..675a7b663 100644
--- a/server/helpers/custom-validators/activitypub/actor.ts
+++ b/server/helpers/custom-validators/activitypub/actor.ts
@@ -1,6 +1,6 @@
1import validator from 'validator' 1import validator from 'validator'
2import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 2import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
3import { exists, isArray } from '../misc' 3import { exists, isArray, isDateValid } from '../misc'
4import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' 4import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
5import { isHostValid } from '../servers' 5import { isHostValid } from '../servers'
6import { peertubeTruncate } from '@server/helpers/core-utils' 6import { peertubeTruncate } from '@server/helpers/core-utils'
@@ -47,7 +47,21 @@ function isActorPrivateKeyValid (privateKey: string) {
47 validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACTORS.PRIVATE_KEY) 47 validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACTORS.PRIVATE_KEY)
48} 48}
49 49
50function isActorObjectValid (actor: any) { 50function isActorFollowingCountValid (value: string) {
51 return exists(value) && validator.isInt('' + value, { min: 0 })
52}
53
54function isActorFollowersCountValid (value: string) {
55 return exists(value) && validator.isInt('' + value, { min: 0 })
56}
57
58function isActorDeleteActivityValid (activity: any) {
59 return isBaseActivityValid(activity, 'Delete')
60}
61
62function sanitizeAndCheckActorObject (actor: any) {
63 normalizeActor(actor)
64
51 return exists(actor) && 65 return exists(actor) &&
52 isActivityPubUrlValid(actor.id) && 66 isActivityPubUrlValid(actor.id) &&
53 isActorTypeValid(actor.type) && 67 isActorTypeValid(actor.type) &&
@@ -68,24 +82,6 @@ function isActorObjectValid (actor: any) {
68 (actor.type !== 'Group' || actor.attributedTo.length !== 0) 82 (actor.type !== 'Group' || actor.attributedTo.length !== 0)
69} 83}
70 84
71function isActorFollowingCountValid (value: string) {
72 return exists(value) && validator.isInt('' + value, { min: 0 })
73}
74
75function isActorFollowersCountValid (value: string) {
76 return exists(value) && validator.isInt('' + value, { min: 0 })
77}
78
79function isActorDeleteActivityValid (activity: any) {
80 return isBaseActivityValid(activity, 'Delete')
81}
82
83function sanitizeAndCheckActorObject (object: any) {
84 normalizeActor(object)
85
86 return isActorObjectValid(object)
87}
88
89function normalizeActor (actor: any) { 85function normalizeActor (actor: any) {
90 if (!actor) return 86 if (!actor) return
91 87
@@ -95,6 +91,8 @@ function normalizeActor (actor: any) {
95 actor.url = actor.url.href || actor.url.url 91 actor.url = actor.url.href || actor.url.url
96 } 92 }
97 93
94 if (!isDateValid(actor.published)) actor.published = undefined
95
98 if (actor.summary && typeof actor.summary === 'string') { 96 if (actor.summary && typeof actor.summary === 'string') {
99 actor.summary = peertubeTruncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max }) 97 actor.summary = peertubeTruncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max })
100 98
@@ -135,7 +133,6 @@ export {
135 isActorPublicKeyValid, 133 isActorPublicKeyValid,
136 isActorPreferredUsernameValid, 134 isActorPreferredUsernameValid,
137 isActorPrivateKeyValid, 135 isActorPrivateKeyValid,
138 isActorObjectValid,
139 isActorFollowingCountValid, 136 isActorFollowingCountValid,
140 isActorFollowersCountValid, 137 isActorFollowersCountValid,
141 isActorDeleteActivityValid, 138 isActorDeleteActivityValid,