diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-11 15:55:39 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-11 15:55:39 +0200 |
commit | 938d3fa0ffb4cf3e4c88f94dcfcae5eb2ce5e190 (patch) | |
tree | 844768f122c8f06d1f90f006d9fdd0e2e4005aae /server/helpers/custom-validators | |
parent | 5cf135001124cd19183336dbfcae1cd432217b00 (diff) | |
download | PeerTube-938d3fa0ffb4cf3e4c88f94dcfcae5eb2ce5e190.tar.gz PeerTube-938d3fa0ffb4cf3e4c88f94dcfcae5eb2ce5e190.tar.zst PeerTube-938d3fa0ffb4cf3e4c88f94dcfcae5eb2ce5e190.zip |
Move normalize functions in helpers
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/activitypub/actor.ts | 21 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/video-comments.ts | 2 |
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 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import { CONSTRAINTS_FIELDS } from '../../../initializers' | 2 | import { CONSTRAINTS_FIELDS } from '../../../initializers' |
3 | import { normalizeActor } from '../../../lib/activitypub' | ||
4 | import { exists } from '../misc' | 3 | import { exists } from '../misc' |
4 | import { truncate } from 'lodash' | ||
5 | import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' | 5 | import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' |
6 | 6 | ||
7 | function isActorEndpointsObjectValid (endpointObject: any) { | 7 | function isActorEndpointsObjectValid (endpointObject: any) { |
@@ -91,9 +91,28 @@ function isActorUpdateActivityValid (activity: any) { | |||
91 | isActorObjectValid(activity.object) | 91 | isActorObjectValid(activity.object) |
92 | } | 92 | } |
93 | 93 | ||
94 | function 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 | ||
96 | export { | 114 | export { |
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) { | |||
46 | function normalizeComment (comment: any) { | 46 | function 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 | ||