1 import * as validator from 'validator'
2 import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers'
3 import { exists, isArray, isDateValid } from '../misc'
4 import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
6 function sanitizeAndCheckVideoCommentObject (comment: any) {
7 if (!comment || comment.type !== 'Note') return false
9 normalizeComment(comment)
11 return isActivityPubUrlValid(comment.id) &&
12 isCommentContentValid(comment.content) &&
13 isActivityPubUrlValid(comment.inReplyTo) &&
14 isDateValid(comment.published) &&
15 isActivityPubUrlValid(comment.url) &&
16 isArray(comment.to) &&
18 comment.to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ||
19 comment.cc.indexOf(ACTIVITY_PUB.PUBLIC) !== -1
20 ) // Only accept public comments
23 // ---------------------------------------------------------------------------
26 sanitizeAndCheckVideoCommentObject
29 // ---------------------------------------------------------------------------
31 function isCommentContentValid (content: any) {
32 return exists(content) && validator.isLength('' + content, { min: 1 })
35 function normalizeComment (comment: any) {
38 if (typeof comment.url !== 'string') {
39 comment.url = comment.url.href || comment.url.url