diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 17:30:46 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:43:01 +0100 |
commit | a2431b7dcbc72c05101dcdbe631ff84a823aeb51 (patch) | |
tree | 09278a822905622a70ff976a75e09d99bc45639a /server/helpers/custom-validators/activitypub | |
parent | fcaf1e0aa84213a1b1f1b1a44a3276eae35ebe70 (diff) | |
download | PeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.tar.gz PeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.tar.zst PeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.zip |
Refractor validators
Diffstat (limited to 'server/helpers/custom-validators/activitypub')
-rw-r--r-- | server/helpers/custom-validators/activitypub/account.ts | 63 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/videos.ts | 13 |
2 files changed, 14 insertions, 62 deletions
diff --git a/server/helpers/custom-validators/activitypub/account.ts b/server/helpers/custom-validators/activitypub/account.ts index 645f55a5a..cab39a654 100644 --- a/server/helpers/custom-validators/activitypub/account.ts +++ b/server/helpers/custom-validators/activitypub/account.ts | |||
@@ -5,31 +5,19 @@ import { exists, isUUIDValid } from '../misc' | |||
5 | import { isActivityPubUrlValid, isBaseActivityValid } from './misc' | 5 | import { isActivityPubUrlValid, isBaseActivityValid } from './misc' |
6 | 6 | ||
7 | function isAccountEndpointsObjectValid (endpointObject: any) { | 7 | function isAccountEndpointsObjectValid (endpointObject: any) { |
8 | return isAccountSharedInboxValid(endpointObject.sharedInbox) | 8 | return isActivityPubUrlValid(endpointObject.sharedInbox) |
9 | } | ||
10 | |||
11 | function isAccountSharedInboxValid (sharedInbox: string) { | ||
12 | return isActivityPubUrlValid(sharedInbox) | ||
13 | } | 9 | } |
14 | 10 | ||
15 | function isAccountPublicKeyObjectValid (publicKeyObject: any) { | 11 | function isAccountPublicKeyObjectValid (publicKeyObject: any) { |
16 | return isAccountPublicKeyIdValid(publicKeyObject.id) && | 12 | return isActivityPubUrlValid(publicKeyObject.id) && |
17 | isAccountPublicKeyOwnerValid(publicKeyObject.owner) && | 13 | isActivityPubUrlValid(publicKeyObject.owner) && |
18 | isAccountPublicKeyValid(publicKeyObject.publicKeyPem) | 14 | isAccountPublicKeyValid(publicKeyObject.publicKeyPem) |
19 | } | 15 | } |
20 | 16 | ||
21 | function isAccountPublicKeyIdValid (id: string) { | ||
22 | return isActivityPubUrlValid(id) | ||
23 | } | ||
24 | |||
25 | function isAccountTypeValid (type: string) { | 17 | function isAccountTypeValid (type: string) { |
26 | return type === 'Person' || type === 'Application' | 18 | return type === 'Person' || type === 'Application' |
27 | } | 19 | } |
28 | 20 | ||
29 | function isAccountPublicKeyOwnerValid (owner: string) { | ||
30 | return isActivityPubUrlValid(owner) | ||
31 | } | ||
32 | |||
33 | function isAccountPublicKeyValid (publicKey: string) { | 21 | function isAccountPublicKeyValid (publicKey: string) { |
34 | return exists(publicKey) && | 22 | return exists(publicKey) && |
35 | typeof publicKey === 'string' && | 23 | typeof publicKey === 'string' && |
@@ -38,34 +26,10 @@ function isAccountPublicKeyValid (publicKey: string) { | |||
38 | validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACCOUNTS.PUBLIC_KEY) | 26 | validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACCOUNTS.PUBLIC_KEY) |
39 | } | 27 | } |
40 | 28 | ||
41 | function isAccountIdValid (id: string) { | ||
42 | return isActivityPubUrlValid(id) | ||
43 | } | ||
44 | |||
45 | function isAccountFollowingValid (id: string) { | ||
46 | return isActivityPubUrlValid(id) | ||
47 | } | ||
48 | |||
49 | function isAccountFollowersValid (id: string) { | ||
50 | return isActivityPubUrlValid(id) | ||
51 | } | ||
52 | |||
53 | function isAccountInboxValid (inbox: string) { | ||
54 | return isActivityPubUrlValid(inbox) | ||
55 | } | ||
56 | |||
57 | function isAccountOutboxValid (outbox: string) { | ||
58 | return isActivityPubUrlValid(outbox) | ||
59 | } | ||
60 | |||
61 | function isAccountPreferredUsernameValid (preferredUsername: string) { | 29 | function isAccountPreferredUsernameValid (preferredUsername: string) { |
62 | return isAccountNameValid(preferredUsername) | 30 | return isAccountNameValid(preferredUsername) |
63 | } | 31 | } |
64 | 32 | ||
65 | function isAccountUrlValid (url: string) { | ||
66 | return isActivityPubUrlValid(url) | ||
67 | } | ||
68 | |||
69 | function isAccountPrivateKeyValid (privateKey: string) { | 33 | function isAccountPrivateKeyValid (privateKey: string) { |
70 | return exists(privateKey) && | 34 | return exists(privateKey) && |
71 | typeof privateKey === 'string' && | 35 | typeof privateKey === 'string' && |
@@ -75,15 +39,15 @@ function isAccountPrivateKeyValid (privateKey: string) { | |||
75 | } | 39 | } |
76 | 40 | ||
77 | function isRemoteAccountValid (remoteAccount: any) { | 41 | function isRemoteAccountValid (remoteAccount: any) { |
78 | return isAccountIdValid(remoteAccount.id) && | 42 | return isActivityPubUrlValid(remoteAccount.id) && |
79 | isUUIDValid(remoteAccount.uuid) && | 43 | isUUIDValid(remoteAccount.uuid) && |
80 | isAccountTypeValid(remoteAccount.type) && | 44 | isAccountTypeValid(remoteAccount.type) && |
81 | isAccountFollowingValid(remoteAccount.following) && | 45 | isActivityPubUrlValid(remoteAccount.following) && |
82 | isAccountFollowersValid(remoteAccount.followers) && | 46 | isActivityPubUrlValid(remoteAccount.followers) && |
83 | isAccountInboxValid(remoteAccount.inbox) && | 47 | isActivityPubUrlValid(remoteAccount.inbox) && |
84 | isAccountOutboxValid(remoteAccount.outbox) && | 48 | isActivityPubUrlValid(remoteAccount.outbox) && |
85 | isAccountPreferredUsernameValid(remoteAccount.preferredUsername) && | 49 | isAccountPreferredUsernameValid(remoteAccount.preferredUsername) && |
86 | isAccountUrlValid(remoteAccount.url) && | 50 | isActivityPubUrlValid(remoteAccount.url) && |
87 | isAccountPublicKeyObjectValid(remoteAccount.publicKey) && | 51 | isAccountPublicKeyObjectValid(remoteAccount.publicKey) && |
88 | isAccountEndpointsObjectValid(remoteAccount.endpoints) | 52 | isAccountEndpointsObjectValid(remoteAccount.endpoints) |
89 | } | 53 | } |
@@ -113,19 +77,10 @@ function isAccountAcceptActivityValid (activity: any) { | |||
113 | 77 | ||
114 | export { | 78 | export { |
115 | isAccountEndpointsObjectValid, | 79 | isAccountEndpointsObjectValid, |
116 | isAccountSharedInboxValid, | ||
117 | isAccountPublicKeyObjectValid, | 80 | isAccountPublicKeyObjectValid, |
118 | isAccountPublicKeyIdValid, | ||
119 | isAccountTypeValid, | 81 | isAccountTypeValid, |
120 | isAccountPublicKeyOwnerValid, | ||
121 | isAccountPublicKeyValid, | 82 | isAccountPublicKeyValid, |
122 | isAccountIdValid, | ||
123 | isAccountFollowingValid, | ||
124 | isAccountFollowersValid, | ||
125 | isAccountInboxValid, | ||
126 | isAccountOutboxValid, | ||
127 | isAccountPreferredUsernameValid, | 83 | isAccountPreferredUsernameValid, |
128 | isAccountUrlValid, | ||
129 | isAccountPrivateKeyValid, | 84 | isAccountPrivateKeyValid, |
130 | isRemoteAccountValid, | 85 | isRemoteAccountValid, |
131 | isAccountFollowingCountValid, | 86 | isAccountFollowingCountValid, |
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 55e79c4e8..12c672fd2 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts | |||
@@ -8,7 +8,6 @@ import { | |||
8 | isVideoNSFWValid, | 8 | isVideoNSFWValid, |
9 | isVideoTagValid, | 9 | isVideoTagValid, |
10 | isVideoTruncatedDescriptionValid, | 10 | isVideoTruncatedDescriptionValid, |
11 | isVideoUrlValid, | ||
12 | isVideoViewsValid | 11 | isVideoViewsValid |
13 | } from '../videos' | 12 | } from '../videos' |
14 | import { isActivityPubUrlValid, isBaseActivityValid } from './misc' | 13 | import { isActivityPubUrlValid, isBaseActivityValid } from './misc' |
@@ -77,12 +76,11 @@ export { | |||
77 | function setValidRemoteTags (video: any) { | 76 | function setValidRemoteTags (video: any) { |
78 | if (Array.isArray(video.tag) === false) return false | 77 | if (Array.isArray(video.tag) === false) return false |
79 | 78 | ||
80 | const newTag = video.tag.filter(t => { | 79 | video.tag = video.tag.filter(t => { |
81 | return t.type === 'Hashtag' && | 80 | return t.type === 'Hashtag' && |
82 | isVideoTagValid(t.name) | 81 | isVideoTagValid(t.name) |
83 | }) | 82 | }) |
84 | 83 | ||
85 | video.tag = newTag | ||
86 | return true | 84 | return true |
87 | } | 85 | } |
88 | 86 | ||
@@ -96,7 +94,7 @@ function isRemoteVideoContentValid (mediaType: string, content: string) { | |||
96 | 94 | ||
97 | function isRemoteVideoIconValid (icon: any) { | 95 | function isRemoteVideoIconValid (icon: any) { |
98 | return icon.type === 'Image' && | 96 | return icon.type === 'Image' && |
99 | isVideoUrlValid(icon.url) && | 97 | isActivityPubUrlValid(icon.url) && |
100 | icon.mediaType === 'image/jpeg' && | 98 | icon.mediaType === 'image/jpeg' && |
101 | validator.isInt(icon.width + '', { min: 0 }) && | 99 | validator.isInt(icon.width + '', { min: 0 }) && |
102 | validator.isInt(icon.height + '', { min: 0 }) | 100 | validator.isInt(icon.height + '', { min: 0 }) |
@@ -105,8 +103,7 @@ function isRemoteVideoIconValid (icon: any) { | |||
105 | function setValidRemoteVideoUrls (video: any) { | 103 | function setValidRemoteVideoUrls (video: any) { |
106 | if (Array.isArray(video.url) === false) return false | 104 | if (Array.isArray(video.url) === false) return false |
107 | 105 | ||
108 | const newUrl = video.url.filter(u => isRemoteVideoUrlValid(u)) | 106 | video.url = video.url.filter(u => isRemoteVideoUrlValid(u)) |
109 | video.url = newUrl | ||
110 | 107 | ||
111 | return true | 108 | return true |
112 | } | 109 | } |
@@ -115,13 +112,13 @@ function isRemoteVideoUrlValid (url: any) { | |||
115 | return url.type === 'Link' && | 112 | return url.type === 'Link' && |
116 | ( | 113 | ( |
117 | ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 && | 114 | ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 && |
118 | isVideoUrlValid(url.url) && | 115 | isActivityPubUrlValid(url.url) && |
119 | validator.isInt(url.width + '', { min: 0 }) && | 116 | validator.isInt(url.width + '', { min: 0 }) && |
120 | validator.isInt(url.size + '', { min: 0 }) | 117 | validator.isInt(url.size + '', { min: 0 }) |
121 | ) || | 118 | ) || |
122 | ( | 119 | ( |
123 | ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 && | 120 | ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 && |
124 | isVideoUrlValid(url.url) && | 121 | isActivityPubUrlValid(url.url) && |
125 | validator.isInt(url.width + '', { min: 0 }) | 122 | validator.isInt(url.width + '', { min: 0 }) |
126 | ) || | 123 | ) || |
127 | ( | 124 | ( |