PeerTube/server/helpers/custom-validators/activitypub/video-comments.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

import * as validator from 'validator'
import { exists, 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)
}
2018-01-04 04:19:16 -06:00
function isVideoCommentDeleteActivityValid (activity: any) {
return isBaseActivityValid(activity, 'Delete')
}
// ---------------------------------------------------------------------------
export {
2018-01-04 04:19:16 -06:00
isVideoCommentCreateActivityValid,
isVideoCommentDeleteActivityValid
}
// ---------------------------------------------------------------------------
function isCommentContentValid (content: any) {
return exists(content) && validator.isLength('' + content, { min: 1 })
}