2017-12-22 03:14:50 -05:00
|
|
|
import * as validator from 'validator'
|
2018-05-11 09:41:54 -04:00
|
|
|
import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers'
|
2018-01-26 05:20:46 -05:00
|
|
|
import { exists, isArray, isDateValid } from '../misc'
|
2017-12-22 03:14:50 -05:00
|
|
|
import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
|
|
|
|
|
|
|
|
function isVideoCommentCreateActivityValid (activity: any) {
|
|
|
|
return isBaseActivityValid(activity, 'Create') &&
|
2018-05-11 09:41:54 -04:00
|
|
|
sanitizeAndCheckVideoCommentObject(activity.object)
|
2017-12-22 03:14:50 -05:00
|
|
|
}
|
|
|
|
|
2018-05-11 09:41:54 -04:00
|
|
|
function sanitizeAndCheckVideoCommentObject (comment: any) {
|
|
|
|
if (comment.type !== 'Note') return false
|
|
|
|
|
|
|
|
normalizeComment(comment)
|
|
|
|
|
|
|
|
return isActivityPubUrlValid(comment.id) &&
|
2017-12-22 03:14:50 -05:00
|
|
|
isCommentContentValid(comment.content) &&
|
|
|
|
isActivityPubUrlValid(comment.inReplyTo) &&
|
|
|
|
isDateValid(comment.published) &&
|
2018-01-26 05:20:46 -05:00
|
|
|
isActivityPubUrlValid(comment.url) &&
|
|
|
|
isArray(comment.to) &&
|
2018-04-04 03:52:45 -04:00
|
|
|
(
|
|
|
|
comment.to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ||
|
|
|
|
comment.cc.indexOf(ACTIVITY_PUB.PUBLIC) !== -1
|
|
|
|
) // Only accept public comments
|
2017-12-22 03:14:50 -05:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:19:16 -05:00
|
|
|
function isVideoCommentDeleteActivityValid (activity: any) {
|
|
|
|
return isBaseActivityValid(activity, 'Delete')
|
|
|
|
}
|
|
|
|
|
2017-12-22 03:14:50 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2018-01-04 05:19:16 -05:00
|
|
|
isVideoCommentCreateActivityValid,
|
2018-01-10 11:18:12 -05:00
|
|
|
isVideoCommentDeleteActivityValid,
|
2018-05-11 09:41:54 -04:00
|
|
|
sanitizeAndCheckVideoCommentObject
|
2017-12-22 03:14:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function isCommentContentValid (content: any) {
|
|
|
|
return exists(content) && validator.isLength('' + content, { min: 1 })
|
|
|
|
}
|
2018-05-11 09:41:54 -04:00
|
|
|
|
|
|
|
function normalizeComment (comment: any) {
|
|
|
|
if (!comment) return
|
|
|
|
|
2018-05-11 09:55:39 -04:00
|
|
|
if (typeof comment.url !== 'string') {
|
2018-05-11 09:41:54 -04:00
|
|
|
comment.url = comment.url.href || comment.url.url
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|