]>
Commit | Line | Data |
---|---|---|
0d0e8dd0 | 1 | import * as validator from 'validator' |
65fcc311 C |
2 | |
3 | import { | |
0d0e8dd0 | 4 | ACTIVITY_PUB |
65fcc311 | 5 | } from '../../../initializers' |
0d0e8dd0 | 6 | import { isDateValid, isUUIDValid } from '../misc' |
65fcc311 | 7 | import { |
65fcc311 | 8 | isVideoViewsValid, |
65fcc311 | 9 | isVideoNSFWValid, |
9567011b | 10 | isVideoTruncatedDescriptionValid, |
65fcc311 | 11 | isVideoDurationValid, |
65fcc311 | 12 | isVideoNameValid, |
0d0e8dd0 | 13 | isVideoTagValid |
65fcc311 | 14 | } from '../videos' |
72c7248b | 15 | import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' |
0d0e8dd0 C |
16 | import { isBaseActivityValid } from './misc' |
17 | ||
18 | function isVideoTorrentAddActivityValid (activity: any) { | |
19 | return isBaseActivityValid(activity, 'Add') && | |
20 | isVideoTorrentObjectValid(activity.object) | |
21 | } | |
22 | ||
23 | function isVideoTorrentUpdateActivityValid (activity: any) { | |
24 | return isBaseActivityValid(activity, 'Update') && | |
25 | isVideoTorrentObjectValid(activity.object) | |
65fcc311 C |
26 | } |
27 | ||
0d0e8dd0 C |
28 | function isVideoTorrentObjectValid (video: any) { |
29 | return video.type === 'Video' && | |
30 | isVideoNameValid(video.name) && | |
31 | isVideoDurationValid(video.duration) && | |
32 | isUUIDValid(video.uuid) && | |
33 | setValidRemoteTags(video) && | |
34 | isRemoteIdentifierValid(video.category) && | |
35 | isRemoteIdentifierValid(video.licence) && | |
36 | isRemoteIdentifierValid(video.language) && | |
37 | isVideoViewsValid(video.video) && | |
38 | isVideoNSFWValid(video.nsfw) && | |
39 | isDateValid(video.published) && | |
40 | isDateValid(video.updated) && | |
41 | isRemoteVideoContentValid(video.mediaType, video.content) && | |
42 | isRemoteVideoIconValid(video.icon) && | |
43 | setValidRemoteVideoUrls(video.url) | |
65fcc311 C |
44 | } |
45 | ||
0d0e8dd0 C |
46 | function isVideoChannelCreateActivityValid (activity: any) { |
47 | return isBaseActivityValid(activity, 'Create') && | |
48 | isVideoChannelObjectValid(activity.object) | |
49 | } | |
50 | ||
51 | function isVideoChannelUpdateActivityValid (activity: any) { | |
52 | return isBaseActivityValid(activity, 'Update') && | |
53 | isVideoChannelObjectValid(activity.object) | |
54 | } | |
55 | ||
56 | function isVideoChannelObjectValid (videoChannel: any) { | |
57 | return videoChannel.type === 'VideoChannel' && | |
58 | isVideoChannelNameValid(videoChannel.name) && | |
59 | isVideoChannelDescriptionValid(videoChannel.description) && | |
60 | isUUIDValid(videoChannel.uuid) | |
65fcc311 C |
61 | } |
62 | ||
63 | // --------------------------------------------------------------------------- | |
64 | ||
65 | export { | |
0d0e8dd0 C |
66 | isVideoTorrentAddActivityValid, |
67 | isVideoChannelCreateActivityValid, | |
68 | isVideoTorrentUpdateActivityValid, | |
69 | isVideoChannelUpdateActivityValid | |
65fcc311 C |
70 | } |
71 | ||
72 | // --------------------------------------------------------------------------- | |
73 | ||
0d0e8dd0 C |
74 | function setValidRemoteTags (video: any) { |
75 | if (Array.isArray(video.tag) === false) return false | |
65fcc311 | 76 | |
0d0e8dd0 C |
77 | const newTag = video.tag.filter(t => { |
78 | return t.type === 'Hashtag' && | |
79 | isVideoTagValid(t.name) | |
80 | }) | |
72c7248b | 81 | |
0d0e8dd0 C |
82 | video.tag = newTag |
83 | return true | |
72c7248b C |
84 | } |
85 | ||
0d0e8dd0 C |
86 | function isRemoteIdentifierValid (data: any) { |
87 | return validator.isInt(data.identifier, { min: 0 }) | |
72c7248b C |
88 | } |
89 | ||
0d0e8dd0 C |
90 | function isRemoteVideoContentValid (mediaType: string, content: string) { |
91 | return mediaType === 'text/markdown' && isVideoTruncatedDescriptionValid(content) | |
72c7248b C |
92 | } |
93 | ||
0d0e8dd0 C |
94 | function isRemoteVideoIconValid (icon: any) { |
95 | return icon.type === 'Image' && | |
96 | validator.isURL(icon.url) && | |
97 | icon.mediaType === 'image/jpeg' && | |
98 | validator.isInt(icon.width, { min: 0 }) && | |
99 | validator.isInt(icon.height, { min: 0 }) | |
72c7248b C |
100 | } |
101 | ||
0d0e8dd0 C |
102 | function setValidRemoteVideoUrls (video: any) { |
103 | if (Array.isArray(video.url) === false) return false | |
65fcc311 | 104 | |
0d0e8dd0 C |
105 | const newUrl = video.url.filter(u => isRemoteVideoUrlValid(u)) |
106 | video.url = newUrl | |
65fcc311 | 107 | |
0d0e8dd0 | 108 | return true |
65fcc311 C |
109 | } |
110 | ||
0d0e8dd0 C |
111 | function isRemoteVideoUrlValid (url: any) { |
112 | return url.type === 'Link' && | |
113 | ACTIVITY_PUB.VIDEO_URL_MIME_TYPES.indexOf(url.mimeType) !== -1 && | |
114 | validator.isURL(url.url) && | |
115 | validator.isInt(url.width, { min: 0 }) && | |
116 | validator.isInt(url.size, { min: 0 }) | |
65fcc311 | 117 | } |