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