1 import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2 import { isHostValid } from '../../helpers/custom-validators/servers'
3 import { ActorModel } from '../activitypub/actor'
4 import { throwIfNotValid } from '../utils'
5 import { ServerBlocklistModel } from './server-blocklist'
6 import * as Bluebird from 'bluebird'
7 import { MServer, MServerFormattable } from '@server/typings/models/server'
18 export class ServerModel extends Model<ServerModel> {
21 @Is('Host', value => throwIfNotValid(value, isHostValid, 'valid host'))
28 redundancyAllowed: boolean
36 @HasMany(() => ActorModel, {
46 @HasMany(() => ServerBlocklistModel, {
52 BlockedByAccounts: ServerBlocklistModel[]
54 static load (id: number): Bluebird<MServer> {
61 return ServerModel.findOne(query)
64 static loadByHost (host: string): Bluebird<MServer> {
71 return ServerModel.findOne(query)
74 static async loadOrCreateByHost (host: string) {
75 let server = await ServerModel.loadByHost(host)
76 if (!server) server = await ServerModel.create({ host })
82 return this.BlockedByAccounts && this.BlockedByAccounts.length !== 0
85 toFormattedJSON (this: MServerFormattable) {