aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/activitypub/video-comments.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/activitypub/video-comments.ts')
-rw-r--r--server/helpers/custom-validators/activitypub/video-comments.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/activitypub/video-comments.ts b/server/helpers/custom-validators/activitypub/video-comments.ts
new file mode 100644
index 000000000..489ff27de
--- /dev/null
+++ b/server/helpers/custom-validators/activitypub/video-comments.ts
@@ -0,0 +1,40 @@
1import * as validator from 'validator'
2import { exists, isDateValid } from '../misc'
3import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
4import * as sanitizeHtml from 'sanitize-html'
5
6function isVideoCommentCreateActivityValid (activity: any) {
7 return isBaseActivityValid(activity, 'Create') &&
8 isVideoCommentObjectValid(activity.object)
9}
10
11function isVideoCommentObjectValid (comment: any) {
12 return comment.type === 'Note' &&
13 isActivityPubUrlValid(comment.id) &&
14 sanitizeCommentHTML(comment) &&
15 isCommentContentValid(comment.content) &&
16 isActivityPubUrlValid(comment.inReplyTo) &&
17 isDateValid(comment.published) &&
18 isActivityPubUrlValid(comment.url)
19}
20
21// ---------------------------------------------------------------------------
22
23export {
24 isVideoCommentCreateActivityValid
25}
26
27// ---------------------------------------------------------------------------
28
29function sanitizeCommentHTML (comment: any) {
30 return sanitizeHtml(comment.content, {
31 allowedTags: [ 'b', 'i', 'em', 'span', 'a' ],
32 allowedAttributes: {
33 'a': [ 'href' ]
34 }
35 })
36}
37
38function isCommentContentValid (content: any) {
39 return exists(content) && validator.isLength('' + content, { min: 1 })
40}