]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/blocklist.ts
Support logout and add id and pass tests
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / blocklist.ts
index f5b295f45808dd3a42aacf3ef3267a544b1d69f6..c00a7e4df5e22c204f7d958e106bd8c7992bf0e4 100644 (file)
@@ -1,15 +1,14 @@
-import { body, param } from 'express-validator/check'
+import { body, param } from 'express-validator'
 import * as express from 'express'
 import { logger } from '../../helpers/logger'
 import { areValidationErrors } from './utils'
-import { doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts'
-import { UserModel } from '../../models/account/user'
 import { AccountBlocklistModel } from '../../models/account/account-blocklist'
 import { isHostValid } from '../../helpers/custom-validators/servers'
 import { ServerBlocklistModel } from '../../models/server/server-blocklist'
 import { ServerModel } from '../../models/server/server'
-import { CONFIG } from '../../initializers'
-import { getServerActor } from '../../helpers/utils'
+import { WEBSERVER } from '../../initializers/constants'
+import { doesAccountNameWithHostExist } from '../../helpers/middlewares'
+import { getServerActor } from '@server/models/application/application'
 
 const blockAccountValidator = [
   body('accountName').exists().withMessage('Should have an account name with host'),
@@ -79,17 +78,15 @@ const blockServerValidator = [
 
     const host: string = req.body.host
 
-    if (host === CONFIG.WEBSERVER.HOST) {
+    if (host === WEBSERVER.HOST) {
       return res.status(409)
         .send({ error: 'You cannot block your own server.' })
         .end()
     }
 
-    const server = await ServerModel.loadByHost(host)
+    let server = await ServerModel.loadByHost(host)
     if (!server) {
-      return res.status(404)
-                .send({ error: 'Server host not found.' })
-                .end()
+      server = await ServerModel.create({ host })
     }
 
     res.locals.server = server