]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/server.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / server.ts
index e62a17163905848a7200db29fac7e4177136fb39..fe67047168ea8164908211d8d41f1623f0da3070 100644 (file)
@@ -3,11 +3,11 @@ import { logger } from '../../helpers/logger'
 import { areValidationErrors } from './utils'
 import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers'
 import { ServerModel } from '../../models/server/server'
-import { body } from 'express-validator/check'
+import { body } from 'express-validator'
 import { isUserDisplayNameValid } from '../../helpers/custom-validators/users'
-import { Emailer } from '../../lib/emailer'
 import { Redis } from '../../lib/redis'
-import { CONFIG } from '../../initializers/constants'
+import { CONFIG, isEmailEnabled } from '../../initializers/config'
+import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
 
 const serverGetValidator = [
   body('host').custom(isHostValid).withMessage('Should have a valid host'),
@@ -19,9 +19,9 @@ const serverGetValidator = [
 
     const server = await ServerModel.loadByHost(req.body.host)
     if (!server) {
-      return res.status(404)
-         .send({ error: 'Server host not found.' })
-         .end()
+      return res.status(HttpStatusCode.NOT_FOUND_404)
+                .send({ error: 'Server host not found.' })
+                .end()
     }
 
     res.locals.server = server
@@ -45,14 +45,14 @@ const contactAdministratorValidator = [
 
     if (CONFIG.CONTACT_FORM.ENABLED === false) {
       return res
-        .status(409)
+        .status(HttpStatusCode.CONFLICT_409)
         .send({ error: 'Contact form is not enabled on this instance.' })
         .end()
     }
 
-    if (Emailer.isEnabled() === false) {
+    if (isEmailEnabled() === false) {
       return res
-        .status(409)
+        .status(HttpStatusCode.CONFLICT_409)
         .send({ error: 'Emailer is not enabled on this instance.' })
         .end()
     }
@@ -61,7 +61,7 @@ const contactAdministratorValidator = [
       logger.info('Refusing a contact form by %s: already sent one recently.', req.ip)
 
       return res
-        .status(403)
+        .status(HttpStatusCode.FORBIDDEN_403)
         .send({ error: 'You already sent a contact form recently.' })
         .end()
     }