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.ts21
-rw-r--r--server/helpers/custom-validators/activitypub/video-comments.ts2
2 files changed, 21 insertions, 2 deletions
diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts
index 9908be4d3..9a0bb32c1 100644
--- a/server/helpers/custom-validators/activitypub/actor.ts
+++ b/server/helpers/custom-validators/activitypub/actor.ts
@@ -1,7 +1,7 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2import { CONSTRAINTS_FIELDS } from '../../../initializers' 2import { CONSTRAINTS_FIELDS } from '../../../initializers'
3import { normalizeActor } from '../../../lib/activitypub'
4import { exists } from '../misc' 3import { exists } from '../misc'
4import { truncate } from 'lodash'
5import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' 5import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
6 6
7function isActorEndpointsObjectValid (endpointObject: any) { 7function isActorEndpointsObjectValid (endpointObject: any) {
@@ -91,9 +91,28 @@ function isActorUpdateActivityValid (activity: any) {
91 isActorObjectValid(activity.object) 91 isActorObjectValid(activity.object)
92} 92}
93 93
94function normalizeActor (actor: any) {
95 if (!actor) return
96
97 if (typeof actor.url !== 'string') {
98 actor.url = actor.url.href || actor.url.url
99 }
100
101 if (actor.summary && typeof actor.summary === 'string') {
102 actor.summary = truncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max })
103
104 if (actor.summary.length < CONSTRAINTS_FIELDS.USERS.DESCRIPTION.min) {
105 actor.summary = null
106 }
107 }
108
109 return
110}
111
94// --------------------------------------------------------------------------- 112// ---------------------------------------------------------------------------
95 113
96export { 114export {
115 normalizeActor,
97 isActorEndpointsObjectValid, 116 isActorEndpointsObjectValid,
98 isActorPublicKeyObjectValid, 117 isActorPublicKeyObjectValid,
99 isActorTypeValid, 118 isActorTypeValid,
diff --git a/server/helpers/custom-validators/activitypub/video-comments.ts b/server/helpers/custom-validators/activitypub/video-comments.ts
index 151d13075..7a9f7326d 100644
--- a/server/helpers/custom-validators/activitypub/video-comments.ts
+++ b/server/helpers/custom-validators/activitypub/video-comments.ts
@@ -46,7 +46,7 @@ function isCommentContentValid (content: any) {
46function normalizeComment (comment: any) { 46function normalizeComment (comment: any) {
47 if (!comment) return 47 if (!comment) return
48 48
49 if (!comment.url || typeof comment.url !== 'string') { 49 if (typeof comment.url !== 'string') {
50 comment.url = comment.url.href || comment.url.url 50 comment.url = comment.url.href || comment.url.url
51 } 51 }
52 52