diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
commit | 69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch) | |
tree | ad199a18ec3c322460d6f9523fc383ee562554e0 /server/helpers/custom-validators/remote | |
parent | 4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff) | |
download | PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip |
Type functions
Diffstat (limited to 'server/helpers/custom-validators/remote')
-rw-r--r-- | server/helpers/custom-validators/remote/index.ts | 2 | ||||
-rw-r--r-- | server/helpers/custom-validators/remote/videos.ts | 32 |
2 files changed, 22 insertions, 12 deletions
diff --git a/server/helpers/custom-validators/remote/index.ts b/server/helpers/custom-validators/remote/index.ts index d6f9a7e77..e29a9b767 100644 --- a/server/helpers/custom-validators/remote/index.ts +++ b/server/helpers/custom-validators/remote/index.ts | |||
@@ -1 +1 @@ | |||
export * from './videos'; | export * from './videos' | ||
diff --git a/server/helpers/custom-validators/remote/videos.ts b/server/helpers/custom-validators/remote/videos.ts index 4b904d011..1df7316aa 100644 --- a/server/helpers/custom-validators/remote/videos.ts +++ b/server/helpers/custom-validators/remote/videos.ts | |||
@@ -31,7 +31,7 @@ import { | |||
31 | 31 | ||
32 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] | 32 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] |
33 | 33 | ||
34 | function isEachRemoteRequestVideosValid (requests) { | 34 | function isEachRemoteRequestVideosValid (requests: any[]) { |
35 | return isArray(requests) && | 35 | return isArray(requests) && |
36 | requests.every(function (request) { | 36 | requests.every(function (request) { |
37 | const video = request.data | 37 | const video = request.data |
@@ -61,7 +61,7 @@ function isEachRemoteRequestVideosValid (requests) { | |||
61 | }) | 61 | }) |
62 | } | 62 | } |
63 | 63 | ||
64 | function isEachRemoteRequestVideosQaduValid (requests) { | 64 | function isEachRemoteRequestVideosQaduValid (requests: any[]) { |
65 | return isArray(requests) && | 65 | return isArray(requests) && |
66 | requests.every(function (request) { | 66 | requests.every(function (request) { |
67 | const video = request.data | 67 | const video = request.data |
@@ -70,14 +70,14 @@ function isEachRemoteRequestVideosQaduValid (requests) { | |||
70 | 70 | ||
71 | return ( | 71 | return ( |
72 | isVideoRemoteIdValid(video.remoteId) && | 72 | isVideoRemoteIdValid(video.remoteId) && |
73 | (has(video, 'views') === false || isVideoViewsValid) && | 73 | (has(video, 'views') === false || isVideoViewsValid(video.views)) && |
74 | (has(video, 'likes') === false || isVideoLikesValid) && | 74 | (has(video, 'likes') === false || isVideoLikesValid(video.likes)) && |
75 | (has(video, 'dislikes') === false || isVideoDislikesValid) | 75 | (has(video, 'dislikes') === false || isVideoDislikesValid(video.dislikes)) |
76 | ) | 76 | ) |
77 | }) | 77 | }) |
78 | } | 78 | } |
79 | 79 | ||
80 | function isEachRemoteRequestVideosEventsValid (requests) { | 80 | function isEachRemoteRequestVideosEventsValid (requests: any[]) { |
81 | return isArray(requests) && | 81 | return isArray(requests) && |
82 | requests.every(function (request) { | 82 | requests.every(function (request) { |
83 | const eventData = request.data | 83 | const eventData = request.data |
@@ -100,9 +100,19 @@ export { | |||
100 | isEachRemoteRequestVideosEventsValid | 100 | isEachRemoteRequestVideosEventsValid |
101 | } | 101 | } |
102 | 102 | ||
103 | declare global { | ||
104 | namespace ExpressValidator { | ||
105 | export interface Validator { | ||
106 | isEachRemoteRequestVideosValid, | ||
107 | isEachRemoteRequestVideosQaduValid, | ||
108 | isEachRemoteRequestVideosEventsValid | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | |||
103 | // --------------------------------------------------------------------------- | 113 | // --------------------------------------------------------------------------- |
104 | 114 | ||
105 | function isCommonVideoAttributesValid (video) { | 115 | function isCommonVideoAttributesValid (video: any) { |
106 | return isVideoDateValid(video.createdAt) && | 116 | return isVideoDateValid(video.createdAt) && |
107 | isVideoDateValid(video.updatedAt) && | 117 | isVideoDateValid(video.updatedAt) && |
108 | isVideoCategoryValid(video.category) && | 118 | isVideoCategoryValid(video.category) && |
@@ -121,18 +131,18 @@ function isCommonVideoAttributesValid (video) { | |||
121 | isVideoDislikesValid(video.dislikes) | 131 | isVideoDislikesValid(video.dislikes) |
122 | } | 132 | } |
123 | 133 | ||
124 | function isRequestTypeAddValid (value) { | 134 | function isRequestTypeAddValid (value: string) { |
125 | return value === ENDPOINT_ACTIONS.ADD | 135 | return value === ENDPOINT_ACTIONS.ADD |
126 | } | 136 | } |
127 | 137 | ||
128 | function isRequestTypeUpdateValid (value) { | 138 | function isRequestTypeUpdateValid (value: string) { |
129 | return value === ENDPOINT_ACTIONS.UPDATE | 139 | return value === ENDPOINT_ACTIONS.UPDATE |
130 | } | 140 | } |
131 | 141 | ||
132 | function isRequestTypeRemoveValid (value) { | 142 | function isRequestTypeRemoveValid (value: string) { |
133 | return value === ENDPOINT_ACTIONS.REMOVE | 143 | return value === ENDPOINT_ACTIONS.REMOVE |
134 | } | 144 | } |
135 | 145 | ||
136 | function isRequestTypeReportAbuseValid (value) { | 146 | function isRequestTypeReportAbuseValid (value: string) { |
137 | return value === ENDPOINT_ACTIONS.REPORT_ABUSE | 147 | return value === ENDPOINT_ACTIONS.REPORT_ABUSE |
138 | } | 148 | } |