diff options
author | Chocobozzz <me@florianbigard.com> | 2020-01-31 16:56:52 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-02-03 08:31:02 +0100 |
commit | a15871560f80e07386c1dabb8370cd2664ecfd1f (patch) | |
tree | 44440e140c9e43b0d7f97ade777a76e649e0553d /server/helpers/custom-validators | |
parent | a22046d166805222ca76060e471b6cb3d419a32d (diff) | |
download | PeerTube-a15871560f80e07386c1dabb8370cd2664ecfd1f.tar.gz PeerTube-a15871560f80e07386c1dabb8370cd2664ecfd1f.tar.zst PeerTube-a15871560f80e07386c1dabb8370cd2664ecfd1f.zip |
Move to eslintcontain
Diffstat (limited to 'server/helpers/custom-validators')
10 files changed, 17 insertions, 24 deletions
diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts index fa58e163f..fec67823d 100644 --- a/server/helpers/custom-validators/activitypub/actor.ts +++ b/server/helpers/custom-validators/activitypub/actor.ts | |||
@@ -6,7 +6,7 @@ import { isHostValid } from '../servers' | |||
6 | import { peertubeTruncate } from '@server/helpers/core-utils' | 6 | import { peertubeTruncate } from '@server/helpers/core-utils' |
7 | 7 | ||
8 | function isActorEndpointsObjectValid (endpointObject: any) { | 8 | function isActorEndpointsObjectValid (endpointObject: any) { |
9 | if (endpointObject && endpointObject.sharedInbox) { | 9 | if (endpointObject?.sharedInbox) { |
10 | return isActivityPubUrlValid(endpointObject.sharedInbox) | 10 | return isActivityPubUrlValid(endpointObject.sharedInbox) |
11 | } | 11 | } |
12 | 12 | ||
@@ -101,8 +101,6 @@ function normalizeActor (actor: any) { | |||
101 | actor.summary = null | 101 | actor.summary = null |
102 | } | 102 | } |
103 | } | 103 | } |
104 | |||
105 | return | ||
106 | } | 104 | } |
107 | 105 | ||
108 | function isValidActorHandle (handle: string) { | 106 | function isValidActorHandle (handle: string) { |
diff --git a/server/helpers/custom-validators/activitypub/video-comments.ts b/server/helpers/custom-validators/activitypub/video-comments.ts index aa3c246b5..ea852c491 100644 --- a/server/helpers/custom-validators/activitypub/video-comments.ts +++ b/server/helpers/custom-validators/activitypub/video-comments.ts | |||
@@ -48,8 +48,6 @@ function normalizeComment (comment: any) { | |||
48 | if (typeof comment.url === 'object') comment.url = comment.url.href || comment.url.url | 48 | if (typeof comment.url === 'object') comment.url = comment.url.href || comment.url.url |
49 | else comment.url = comment.id | 49 | else comment.url = comment.id |
50 | } | 50 | } |
51 | |||
52 | return | ||
53 | } | 51 | } |
54 | 52 | ||
55 | function isCommentTypeValid (comment: any): boolean { | 53 | function isCommentTypeValid (comment: any): boolean { |
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 89149b3e0..cf32201c4 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts | |||
@@ -94,13 +94,13 @@ function isFileValid ( | |||
94 | if (isArray(files)) return optional | 94 | if (isArray(files)) return optional |
95 | 95 | ||
96 | // Should have a file | 96 | // Should have a file |
97 | const fileArray = files[ field ] | 97 | const fileArray = files[field] |
98 | if (!fileArray || fileArray.length === 0) { | 98 | if (!fileArray || fileArray.length === 0) { |
99 | return optional | 99 | return optional |
100 | } | 100 | } |
101 | 101 | ||
102 | // The file should exist | 102 | // The file should exist |
103 | const file = fileArray[ 0 ] | 103 | const file = fileArray[0] |
104 | if (!file || !file.originalname) return false | 104 | if (!file || !file.originalname) return false |
105 | 105 | ||
106 | // Check size | 106 | // Check size |
diff --git a/server/helpers/custom-validators/plugins.ts b/server/helpers/custom-validators/plugins.ts index 3af72547b..5a4531f72 100644 --- a/server/helpers/custom-validators/plugins.ts +++ b/server/helpers/custom-validators/plugins.ts | |||
@@ -14,7 +14,7 @@ function isPluginTypeValid (value: any) { | |||
14 | function isPluginNameValid (value: string) { | 14 | function isPluginNameValid (value: string) { |
15 | return exists(value) && | 15 | return exists(value) && |
16 | validator.isLength(value, PLUGINS_CONSTRAINTS_FIELDS.NAME) && | 16 | validator.isLength(value, PLUGINS_CONSTRAINTS_FIELDS.NAME) && |
17 | validator.matches(value, /^[a-z\-]+$/) | 17 | validator.matches(value, /^[a-z-]+$/) |
18 | } | 18 | } |
19 | 19 | ||
20 | function isNpmPluginNameValid (value: string) { | 20 | function isNpmPluginNameValid (value: string) { |
@@ -146,8 +146,8 @@ function isPackageJSONValid (packageJSON: PluginPackageJson, pluginType: PluginT | |||
146 | } | 146 | } |
147 | 147 | ||
148 | function isLibraryCodeValid (library: any) { | 148 | function isLibraryCodeValid (library: any) { |
149 | return typeof library.register === 'function' | 149 | return typeof library.register === 'function' && |
150 | && typeof library.unregister === 'function' | 150 | typeof library.unregister === 'function' |
151 | } | 151 | } |
152 | 152 | ||
153 | export { | 153 | export { |
diff --git a/server/helpers/custom-validators/user-notifications.ts b/server/helpers/custom-validators/user-notifications.ts index 5a4d10504..8a33b895b 100644 --- a/server/helpers/custom-validators/user-notifications.ts +++ b/server/helpers/custom-validators/user-notifications.ts | |||
@@ -9,7 +9,8 @@ function isUserNotificationTypeValid (value: any) { | |||
9 | 9 | ||
10 | function isUserNotificationSettingValid (value: any) { | 10 | function isUserNotificationSettingValid (value: any) { |
11 | return exists(value) && | 11 | return exists(value) && |
12 | validator.isInt('' + value) && ( | 12 | validator.isInt('' + value) && |
13 | ( | ||
13 | value === UserNotificationSettingValue.NONE || | 14 | value === UserNotificationSettingValue.NONE || |
14 | value === UserNotificationSettingValue.WEB || | 15 | value === UserNotificationSettingValue.WEB || |
15 | value === UserNotificationSettingValue.EMAIL || | 16 | value === UserNotificationSettingValue.EMAIL || |
diff --git a/server/helpers/custom-validators/video-abuses.ts b/server/helpers/custom-validators/video-abuses.ts index a9478c76a..5c7bc6fd9 100644 --- a/server/helpers/custom-validators/video-abuses.ts +++ b/server/helpers/custom-validators/video-abuses.ts | |||
@@ -1,8 +1,6 @@ | |||
1 | import { Response } from 'express' | ||
2 | import validator from 'validator' | 1 | import validator from 'validator' |
3 | import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' | 2 | import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' |
4 | import { exists } from './misc' | 3 | import { exists } from './misc' |
5 | import { VideoAbuseModel } from '../../models/video/video-abuse' | ||
6 | 4 | ||
7 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES | 5 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES |
8 | 6 | ||
@@ -15,7 +13,7 @@ function isVideoAbuseModerationCommentValid (value: string) { | |||
15 | } | 13 | } |
16 | 14 | ||
17 | function isVideoAbuseStateValid (value: string) { | 15 | function isVideoAbuseStateValid (value: string) { |
18 | return exists(value) && VIDEO_ABUSE_STATES[ value ] !== undefined | 16 | return exists(value) && VIDEO_ABUSE_STATES[value] !== undefined |
19 | } | 17 | } |
20 | 18 | ||
21 | // --------------------------------------------------------------------------- | 19 | // --------------------------------------------------------------------------- |
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts index d06eb3695..9abbce04a 100644 --- a/server/helpers/custom-validators/video-captions.ts +++ b/server/helpers/custom-validators/video-captions.ts | |||
@@ -2,7 +2,7 @@ import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initialize | |||
2 | import { exists, isFileValid } from './misc' | 2 | import { exists, isFileValid } from './misc' |
3 | 3 | ||
4 | function isVideoCaptionLanguageValid (value: any) { | 4 | function isVideoCaptionLanguageValid (value: any) { |
5 | return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined | 5 | return exists(value) && VIDEO_LANGUAGES[value] !== undefined |
6 | } | 6 | } |
7 | 7 | ||
8 | const videoCaptionTypes = Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT) | 8 | const videoCaptionTypes = Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT) |
diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts index ffad482b4..c571f5ddd 100644 --- a/server/helpers/custom-validators/video-imports.ts +++ b/server/helpers/custom-validators/video-imports.ts | |||
@@ -20,7 +20,7 @@ function isVideoImportTargetUrlValid (url: string) { | |||
20 | } | 20 | } |
21 | 21 | ||
22 | function isVideoImportStateValid (value: any) { | 22 | function isVideoImportStateValid (value: any) { |
23 | return exists(value) && VIDEO_IMPORT_STATES[ value ] !== undefined | 23 | return exists(value) && VIDEO_IMPORT_STATES[value] !== undefined |
24 | } | 24 | } |
25 | 25 | ||
26 | const videoTorrentImportTypes = Object.keys(MIMETYPES.TORRENT.MIMETYPE_EXT).map(m => `(${m})`) | 26 | const videoTorrentImportTypes = Object.keys(MIMETYPES.TORRENT.MIMETYPE_EXT).map(m => `(${m})`) |
diff --git a/server/helpers/custom-validators/video-playlists.ts b/server/helpers/custom-validators/video-playlists.ts index 4bb8384ab..180018fc5 100644 --- a/server/helpers/custom-validators/video-playlists.ts +++ b/server/helpers/custom-validators/video-playlists.ts | |||
@@ -1,8 +1,6 @@ | |||
1 | import { exists } from './misc' | 1 | import { exists } from './misc' |
2 | import validator from 'validator' | 2 | import validator from 'validator' |
3 | import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES } from '../../initializers/constants' | 3 | import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES } from '../../initializers/constants' |
4 | import * as express from 'express' | ||
5 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | ||
6 | 4 | ||
7 | const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS | 5 | const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS |
8 | 6 | ||
@@ -15,7 +13,7 @@ function isVideoPlaylistDescriptionValid (value: any) { | |||
15 | } | 13 | } |
16 | 14 | ||
17 | function isVideoPlaylistPrivacyValid (value: number) { | 15 | function isVideoPlaylistPrivacyValid (value: number) { |
18 | return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[ value ] !== undefined | 16 | return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[value] !== undefined |
19 | } | 17 | } |
20 | 18 | ||
21 | function isVideoPlaylistTimestampValid (value: any) { | 19 | function isVideoPlaylistTimestampValid (value: any) { |
@@ -23,7 +21,7 @@ function isVideoPlaylistTimestampValid (value: any) { | |||
23 | } | 21 | } |
24 | 22 | ||
25 | function isVideoPlaylistTypeValid (value: any) { | 23 | function isVideoPlaylistTypeValid (value: any) { |
26 | return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined | 24 | return exists(value) && VIDEO_PLAYLIST_TYPES[value] !== undefined |
27 | } | 25 | } |
28 | 26 | ||
29 | // --------------------------------------------------------------------------- | 27 | // --------------------------------------------------------------------------- |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index a9e859e54..cfb430c63 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -20,15 +20,15 @@ function isVideoFilterValid (filter: VideoFilter) { | |||
20 | } | 20 | } |
21 | 21 | ||
22 | function isVideoCategoryValid (value: any) { | 22 | function isVideoCategoryValid (value: any) { |
23 | return value === null || VIDEO_CATEGORIES[ value ] !== undefined | 23 | return value === null || VIDEO_CATEGORIES[value] !== undefined |
24 | } | 24 | } |
25 | 25 | ||
26 | function isVideoStateValid (value: any) { | 26 | function isVideoStateValid (value: any) { |
27 | return exists(value) && VIDEO_STATES[ value ] !== undefined | 27 | return exists(value) && VIDEO_STATES[value] !== undefined |
28 | } | 28 | } |
29 | 29 | ||
30 | function isVideoLicenceValid (value: any) { | 30 | function isVideoLicenceValid (value: any) { |
31 | return value === null || VIDEO_LICENCES[ value ] !== undefined | 31 | return value === null || VIDEO_LICENCES[value] !== undefined |
32 | } | 32 | } |
33 | 33 | ||
34 | function isVideoLanguageValid (value: any) { | 34 | function isVideoLanguageValid (value: any) { |
@@ -98,7 +98,7 @@ function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } | | |||
98 | } | 98 | } |
99 | 99 | ||
100 | function isVideoPrivacyValid (value: number) { | 100 | function isVideoPrivacyValid (value: number) { |
101 | return VIDEO_PRIVACIES[ value ] !== undefined | 101 | return VIDEO_PRIVACIES[value] !== undefined |
102 | } | 102 | } |
103 | 103 | ||
104 | function isScheduleVideoUpdatePrivacyValid (value: number) { | 104 | function isScheduleVideoUpdatePrivacyValid (value: number) { |