1
0
Fork 0
peertube/server/helpers/custom-validators/activitypub/video-comments.ts
2018-04-04 09:59:31 +02:00

41 lines
1.3 KiB
TypeScript

import * as validator from 'validator'
import { ACTIVITY_PUB } from '../../../initializers'
import { exists, isArray, isDateValid } from '../misc'
import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
function isVideoCommentCreateActivityValid (activity: any) {
return isBaseActivityValid(activity, 'Create') &&
isVideoCommentObjectValid(activity.object)
}
function isVideoCommentObjectValid (comment: any) {
return comment.type === 'Note' &&
isActivityPubUrlValid(comment.id) &&
isCommentContentValid(comment.content) &&
isActivityPubUrlValid(comment.inReplyTo) &&
isDateValid(comment.published) &&
isActivityPubUrlValid(comment.url) &&
isArray(comment.to) &&
(
comment.to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ||
comment.cc.indexOf(ACTIVITY_PUB.PUBLIC) !== -1
) // Only accept public comments
}
function isVideoCommentDeleteActivityValid (activity: any) {
return isBaseActivityValid(activity, 'Delete')
}
// ---------------------------------------------------------------------------
export {
isVideoCommentCreateActivityValid,
isVideoCommentDeleteActivityValid,
isVideoCommentObjectValid
}
// ---------------------------------------------------------------------------
function isCommentContentValid (content: any) {
return exists(content) && validator.isLength('' + content, { min: 1 })
}