-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'
+import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
const blockAccountValidator = [
body('accountName').exists().withMessage('Should have an account name with host'),
const accountToBlock = res.locals.account
if (user.Account.id === accountToBlock.id) {
- res.status(409)
- .send({ error: 'You cannot block yourself.' })
- .end()
+ res.status(HttpStatusCode.CONFLICT_409)
+ .json({ error: 'You cannot block yourself.' })
return
}
const host: string = req.body.host
- if (host === CONFIG.WEBSERVER.HOST) {
- return res.status(409)
- .send({ error: 'You cannot block your own server.' })
- .end()
+ if (host === WEBSERVER.HOST) {
+ return res.status(HttpStatusCode.CONFLICT_409)
+ .json({ error: 'You cannot block your own server.' })
}
- const server = await ServerModel.loadByHost(host)
- if (!server) {
- return res.status(404)
- .send({ error: 'Server host not found.' })
- .end()
- }
+ const server = await ServerModel.loadOrCreateByHost(host)
res.locals.server = server
async function doesUnblockAccountExist (accountId: number, targetAccountId: number, res: express.Response) {
const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId)
if (!accountBlock) {
- res.status(404)
- .send({ error: 'Account block entry not found.' })
- .end()
+ res.status(HttpStatusCode.NOT_FOUND_404)
+ .json({ error: 'Account block entry not found.' })
return false
}
async function doesUnblockServerExist (accountId: number, host: string, res: express.Response) {
const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host)
if (!serverBlock) {
- res.status(404)
- .send({ error: 'Server block entry not found.' })
- .end()
+ res.status(HttpStatusCode.NOT_FOUND_404)
+ .json({ error: 'Server block entry not found.' })
return false
}