]>
Commit | Line | Data |
---|---|---|
6d852470 | 1 | import * as validator from 'validator' |
74dc3bca | 2 | import { ACTIVITY_PUB } from '../../../initializers/constants' |
66ee325f | 3 | import { exists, isArray, isDateValid } from '../misc' |
74dc3bca | 4 | import { isActivityPubUrlValid } from './misc' |
6d852470 | 5 | |
5cf13500 | 6 | function sanitizeAndCheckVideoCommentObject (comment: any) { |
c049d791 | 7 | if (!comment || comment.type !== 'Note') return false |
5cf13500 C |
8 | |
9 | normalizeComment(comment) | |
10 | ||
11 | return isActivityPubUrlValid(comment.id) && | |
6d852470 C |
12 | isCommentContentValid(comment.content) && |
13 | isActivityPubUrlValid(comment.inReplyTo) && | |
14 | isDateValid(comment.published) && | |
66ee325f C |
15 | isActivityPubUrlValid(comment.url) && |
16 | isArray(comment.to) && | |
20760d91 C |
17 | ( |
18 | comment.to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 || | |
19 | comment.cc.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 | |
20 | ) // Only accept public comments | |
6d852470 C |
21 | } |
22 | ||
23 | // --------------------------------------------------------------------------- | |
24 | ||
25 | export { | |
5cf13500 | 26 | sanitizeAndCheckVideoCommentObject |
6d852470 C |
27 | } |
28 | ||
29 | // --------------------------------------------------------------------------- | |
30 | ||
6d852470 C |
31 | function isCommentContentValid (content: any) { |
32 | return exists(content) && validator.isLength('' + content, { min: 1 }) | |
33 | } | |
5cf13500 C |
34 | |
35 | function normalizeComment (comment: any) { | |
36 | if (!comment) return | |
37 | ||
938d3fa0 | 38 | if (typeof comment.url !== 'string') { |
ee79b60e C |
39 | if (typeof comment.url === 'object') comment.url = comment.url.href || comment.url.url |
40 | else comment.url = comment.id | |
5cf13500 C |
41 | } |
42 | ||
43 | return | |
44 | } |