X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Factivitypub%2Fvideo-comments.ts;h=ea852c4910a3ab43e9a0dce75ae9425bcb1eef97;hb=2b02c520e66ea452687cab39401b371711caa9ed;hp=051c4565abb0fbbe09107fb01eee837535fe9b21;hpb=c049d791f92cc10f569ee3122edff616cff381f9;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/activitypub/video-comments.ts b/server/helpers/custom-validators/activitypub/video-comments.ts index 051c4565a..ea852c491 100644 --- a/server/helpers/custom-validators/activitypub/video-comments.ts +++ b/server/helpers/custom-validators/activitypub/video-comments.ts @@ -1,18 +1,22 @@ -import * as validator from 'validator' -import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers' +import validator from 'validator' +import { ACTIVITY_PUB } from '../../../initializers/constants' import { exists, isArray, isDateValid } from '../misc' -import { isActivityPubUrlValid, isBaseActivityValid } from './misc' - -function isVideoCommentCreateActivityValid (activity: any) { - return isBaseActivityValid(activity, 'Create') && - sanitizeAndCheckVideoCommentObject(activity.object) -} +import { isActivityPubUrlValid } from './misc' function sanitizeAndCheckVideoCommentObject (comment: any) { - if (!comment || comment.type !== 'Note') return false + if (!comment) return false + + if (!isCommentTypeValid(comment)) return false normalizeComment(comment) + if (comment.type === 'Tombstone') { + return isActivityPubUrlValid(comment.id) && + isDateValid(comment.published) && + isDateValid(comment.deleted) && + isActivityPubUrlValid(comment.url) + } + return isActivityPubUrlValid(comment.id) && isCommentContentValid(comment.content) && isActivityPubUrlValid(comment.inReplyTo) && @@ -25,15 +29,9 @@ function sanitizeAndCheckVideoCommentObject (comment: any) { ) // Only accept public comments } -function isVideoCommentDeleteActivityValid (activity: any) { - return isBaseActivityValid(activity, 'Delete') -} - // --------------------------------------------------------------------------- export { - isVideoCommentCreateActivityValid, - isVideoCommentDeleteActivityValid, sanitizeAndCheckVideoCommentObject } @@ -47,8 +45,15 @@ function normalizeComment (comment: any) { if (!comment) return if (typeof comment.url !== 'string') { - comment.url = comment.url.href || comment.url.url + if (typeof comment.url === 'object') comment.url = comment.url.href || comment.url.url + else comment.url = comment.id } +} + +function isCommentTypeValid (comment: any): boolean { + if (comment.type === 'Note') return true + + if (comment.type === 'Tombstone' && comment.formerType === 'Note') return true - return + return false }