aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-22 09:14:50 +0100
committerChocobozzz <me@florianbigard.com>2017-12-22 09:14:50 +0100
commit6d8524702874120a4667269a81a61e3c7c5e300d (patch)
treea462d95c56b558a4cfc42db08ec1cb66b1f99680 /server/helpers
parentfb4fd623d5e5adcfdc9ecf3dffef702b3786f486 (diff)
downloadPeerTube-6d8524702874120a4667269a81a61e3c7c5e300d.tar.gz
PeerTube-6d8524702874120a4667269a81a61e3c7c5e300d.tar.zst
PeerTube-6d8524702874120a4667269a81a61e3c7c5e300d.zip
Create comment on replied mastodon statutes
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/activitypub/activity.ts4
-rw-r--r--server/helpers/custom-validators/activitypub/video-comments.ts40
2 files changed, 43 insertions, 1 deletions
diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts
index c402800a4..f2e137061 100644
--- a/server/helpers/custom-validators/activitypub/activity.ts
+++ b/server/helpers/custom-validators/activitypub/activity.ts
@@ -6,6 +6,7 @@ import { isActivityPubUrlValid } from './misc'
6import { isDislikeActivityValid, isLikeActivityValid } from './rate' 6import { isDislikeActivityValid, isLikeActivityValid } from './rate'
7import { isUndoActivityValid } from './undo' 7import { isUndoActivityValid } from './undo'
8import { isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels' 8import { isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels'
9import { isVideoCommentCreateActivityValid } from './video-comments'
9import { 10import {
10 isVideoFlagValid, 11 isVideoFlagValid,
11 isVideoTorrentCreateActivityValid, 12 isVideoTorrentCreateActivityValid,
@@ -59,7 +60,8 @@ function checkCreateActivity (activity: any) {
59 return isViewActivityValid(activity) || 60 return isViewActivityValid(activity) ||
60 isDislikeActivityValid(activity) || 61 isDislikeActivityValid(activity) ||
61 isVideoTorrentCreateActivityValid(activity) || 62 isVideoTorrentCreateActivityValid(activity) ||
62 isVideoFlagValid(activity) 63 isVideoFlagValid(activity) ||
64 isVideoCommentCreateActivityValid(activity)
63} 65}
64 66
65function checkUpdateActivity (activity: any) { 67function checkUpdateActivity (activity: any) {
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}