]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Resolve enums at compile time
authorChocobozzz <me@florianbigard.com>
Tue, 28 Dec 2021 14:30:36 +0000 (15:30 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 28 Dec 2021 14:34:55 +0000 (15:34 +0100)
server/helpers/custom-validators/users.ts
shared/models/http/http-error-codes.ts
shared/models/http/http-methods.ts
shared/models/plugins/plugin.type.ts
shared/models/users/user-role.ts

index 105c366002fc271d40f548042634bdc3af402309..b04970108ef5171174af2509d2ba36b63f2959c0 100644 (file)
@@ -90,7 +90,7 @@ function isUserBlockedReasonValid (value: any) {
 }
 
 function isUserRoleValid (value: any) {
-  return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined
+  return exists(value) && validator.isInt('' + value) && [ UserRole.ADMINISTRATOR, UserRole.MODERATOR, UserRole.USER ].includes(value)
 }
 
 // ---------------------------------------------------------------------------
index b2fbdfc5a09e40d41fa3083cb23be9fa3b0198b6..5ebff1cb5990be8909988a49c894e651ff6e7196 100644 (file)
@@ -4,7 +4,7 @@
  *
  * WebDAV and other codes useless with regards to PeerTube are not listed.
  */
-export enum HttpStatusCode {
+export const enum HttpStatusCode {
 
   /**
    * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.1
index 1cfa458b954fb24793fc7f5a411d548bafeb286e..3f4adafe2bd86f2bcf633a2cbe2aff761a7b272f 100644 (file)
@@ -1,5 +1,5 @@
 /** HTTP request method to indicate the desired action to be performed for a given resource. */
-export enum HttpMethod {
+export const enum HttpMethod {
   /** The CONNECT method establishes a tunnel to the server identified by the target resource. */
   CONNECT = 'CONNECT',
   /** The DELETE method deletes the specified resource. */
index b6766821af4661f402fb9e6f2ebd837eb68aeafd..016219cebc1dbafb1d651e329c830c56baaab290 100644 (file)
@@ -1,4 +1,4 @@
-export enum PluginType {
+export const enum PluginType {
   PLUGIN = 1,
   THEME = 2
 }
index 94413abca3fbc4927b82be6e8dca2a34da051706..687a2aa0d5613799548673219ff502fa63c68d01 100644 (file)
@@ -1,5 +1,5 @@
 // Keep the order
-export enum UserRole {
+export const enum UserRole {
   ADMINISTRATOR = 0,
   MODERATOR = 1,
   USER = 2