diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-28 15:30:36 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-28 15:34:55 +0100 |
commit | fba87e27c1cb6c679fff0d2c50be230f7e0c3e56 (patch) | |
tree | d7fe489c57056a8c1cba3d199a90053ff547f4ad | |
parent | 81d02aac56d76227c094d40b17b29875d88417f4 (diff) | |
download | PeerTube-fba87e27c1cb6c679fff0d2c50be230f7e0c3e56.tar.gz PeerTube-fba87e27c1cb6c679fff0d2c50be230f7e0c3e56.tar.zst PeerTube-fba87e27c1cb6c679fff0d2c50be230f7e0c3e56.zip |
Resolve enums at compile time
-rw-r--r-- | server/helpers/custom-validators/users.ts | 2 | ||||
-rw-r--r-- | shared/models/http/http-error-codes.ts | 2 | ||||
-rw-r--r-- | shared/models/http/http-methods.ts | 2 | ||||
-rw-r--r-- | shared/models/plugins/plugin.type.ts | 2 | ||||
-rw-r--r-- | shared/models/users/user-role.ts | 2 |
5 files changed, 5 insertions, 5 deletions
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 105c36600..b04970108 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts | |||
@@ -90,7 +90,7 @@ function isUserBlockedReasonValid (value: any) { | |||
90 | } | 90 | } |
91 | 91 | ||
92 | function isUserRoleValid (value: any) { | 92 | function isUserRoleValid (value: any) { |
93 | return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined | 93 | return exists(value) && validator.isInt('' + value) && [ UserRole.ADMINISTRATOR, UserRole.MODERATOR, UserRole.USER ].includes(value) |
94 | } | 94 | } |
95 | 95 | ||
96 | // --------------------------------------------------------------------------- | 96 | // --------------------------------------------------------------------------- |
diff --git a/shared/models/http/http-error-codes.ts b/shared/models/http/http-error-codes.ts index b2fbdfc5a..5ebff1cb5 100644 --- a/shared/models/http/http-error-codes.ts +++ b/shared/models/http/http-error-codes.ts | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * WebDAV and other codes useless with regards to PeerTube are not listed. | 5 | * WebDAV and other codes useless with regards to PeerTube are not listed. |
6 | */ | 6 | */ |
7 | export enum HttpStatusCode { | 7 | export const enum HttpStatusCode { |
8 | 8 | ||
9 | /** | 9 | /** |
10 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.1 | 10 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.1 |
diff --git a/shared/models/http/http-methods.ts b/shared/models/http/http-methods.ts index 1cfa458b9..3f4adafe2 100644 --- a/shared/models/http/http-methods.ts +++ b/shared/models/http/http-methods.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | /** HTTP request method to indicate the desired action to be performed for a given resource. */ | 1 | /** HTTP request method to indicate the desired action to be performed for a given resource. */ |
2 | export enum HttpMethod { | 2 | export const enum HttpMethod { |
3 | /** The CONNECT method establishes a tunnel to the server identified by the target resource. */ | 3 | /** The CONNECT method establishes a tunnel to the server identified by the target resource. */ |
4 | CONNECT = 'CONNECT', | 4 | CONNECT = 'CONNECT', |
5 | /** The DELETE method deletes the specified resource. */ | 5 | /** The DELETE method deletes the specified resource. */ |
diff --git a/shared/models/plugins/plugin.type.ts b/shared/models/plugins/plugin.type.ts index b6766821a..016219ceb 100644 --- a/shared/models/plugins/plugin.type.ts +++ b/shared/models/plugins/plugin.type.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | export enum PluginType { | 1 | export const enum PluginType { |
2 | PLUGIN = 1, | 2 | PLUGIN = 1, |
3 | THEME = 2 | 3 | THEME = 2 |
4 | } | 4 | } |
diff --git a/shared/models/users/user-role.ts b/shared/models/users/user-role.ts index 94413abca..687a2aa0d 100644 --- a/shared/models/users/user-role.ts +++ b/shared/models/users/user-role.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | // Keep the order | 1 | // Keep the order |
2 | export enum UserRole { | 2 | export const enum UserRole { |
3 | ADMINISTRATOR = 0, | 3 | ADMINISTRATOR = 0, |
4 | MODERATOR = 1, | 4 | MODERATOR = 1, |
5 | USER = 2 | 5 | USER = 2 |