blob: 7e8cfece27776bc45efd82dbd310786e138bd8b8 (
plain) (
tree)
|
|
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 })
}
|