]>
Commit | Line | Data |
---|---|---|
7cde3b9c | 1 | import 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) { |
b5206dfc JM |
7 | if (!comment) return false |
8 | ||
c883db6d | 9 | if (!isCommentTypeValid(comment)) return false |
5cf13500 C |
10 | |
11 | normalizeComment(comment) | |
12 | ||
b5206dfc JM |
13 | if (comment.type === 'Tombstone') { |
14 | return isActivityPubUrlValid(comment.id) && | |
15 | isDateValid(comment.published) && | |
16 | isDateValid(comment.deleted) && | |
17 | isActivityPubUrlValid(comment.url) | |
18 | } | |
19 | ||
5cf13500 | 20 | return isActivityPubUrlValid(comment.id) && |
6d852470 C |
21 | isCommentContentValid(comment.content) && |
22 | isActivityPubUrlValid(comment.inReplyTo) && | |
23 | isDateValid(comment.published) && | |
66ee325f C |
24 | isActivityPubUrlValid(comment.url) && |
25 | isArray(comment.to) && | |
20760d91 C |
26 | ( |
27 | comment.to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 || | |
28 | comment.cc.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 | |
29 | ) // Only accept public comments | |
6d852470 C |
30 | } |
31 | ||
32 | // --------------------------------------------------------------------------- | |
33 | ||
34 | export { | |
5cf13500 | 35 | sanitizeAndCheckVideoCommentObject |
6d852470 C |
36 | } |
37 | ||
38 | // --------------------------------------------------------------------------- | |
39 | ||
6d852470 C |
40 | function isCommentContentValid (content: any) { |
41 | return exists(content) && validator.isLength('' + content, { min: 1 }) | |
42 | } | |
5cf13500 C |
43 | |
44 | function normalizeComment (comment: any) { | |
45 | if (!comment) return | |
46 | ||
938d3fa0 | 47 | if (typeof comment.url !== 'string') { |
ee79b60e C |
48 | if (typeof comment.url === 'object') comment.url = comment.url.href || comment.url.url |
49 | else comment.url = comment.id | |
5cf13500 | 50 | } |
5cf13500 | 51 | } |
c883db6d C |
52 | |
53 | function isCommentTypeValid (comment: any): boolean { | |
54 | if (comment.type === 'Note') return true | |
55 | ||
56 | if (comment.type === 'Tombstone' && comment.formerType === 'Note') return true | |
57 | ||
58 | return false | |
59 | } |