]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/custom-validators/activitypub/video-comments.ts
Merge branch 'release/v1.2.0'
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / activitypub / video-comments.ts
CommitLineData
6d852470 1import * as validator from 'validator'
5cf13500 2import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers'
66ee325f 3import { exists, isArray, isDateValid } from '../misc'
6d852470 4import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
6d852470 5
5cf13500 6function sanitizeAndCheckVideoCommentObject (comment: any) {
c049d791 7 if (!comment || comment.type !== 'Note') return false
5cf13500
C
8
9 normalizeComment(comment)
10
11 return isActivityPubUrlValid(comment.id) &&
6d852470
C
12 isCommentContentValid(comment.content) &&
13 isActivityPubUrlValid(comment.inReplyTo) &&
14 isDateValid(comment.published) &&
66ee325f
C
15 isActivityPubUrlValid(comment.url) &&
16 isArray(comment.to) &&
20760d91
C
17 (
18 comment.to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ||
19 comment.cc.indexOf(ACTIVITY_PUB.PUBLIC) !== -1
20 ) // Only accept public comments
6d852470
C
21}
22
23// ---------------------------------------------------------------------------
24
25export {
5cf13500 26 sanitizeAndCheckVideoCommentObject
6d852470
C
27}
28
29// ---------------------------------------------------------------------------
30
6d852470
C
31function isCommentContentValid (content: any) {
32 return exists(content) && validator.isLength('' + content, { min: 1 })
33}
5cf13500
C
34
35function normalizeComment (comment: any) {
36 if (!comment) return
37
938d3fa0 38 if (typeof comment.url !== 'string') {
5cf13500
C
39 comment.url = comment.url.href || comment.url.url
40 }
41
42 return
43}