1 import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2 import { MServer, MServerFormattable } from '@server/types/models/server'
3 import { isHostValid } from '../../helpers/custom-validators/servers'
4 import { ActorModel } from '../activitypub/actor'
5 import { throwIfNotValid } from '../utils'
6 import { ServerBlocklistModel } from './server-blocklist'
17 export class ServerModel extends Model {
20 @Is('Host', value => throwIfNotValid(value, isHostValid, 'valid host'))
27 redundancyAllowed: boolean
35 @HasMany(() => ActorModel, {
45 @HasMany(() => ServerBlocklistModel, {
51 BlockedByAccounts: ServerBlocklistModel[]
53 static load (id: number): Promise<MServer> {
60 return ServerModel.findOne(query)
63 static loadByHost (host: string): Promise<MServer> {
70 return ServerModel.findOne(query)
73 static async loadOrCreateByHost (host: string) {
74 let server = await ServerModel.loadByHost(host)
75 if (!server) server = await ServerModel.create({ host })
81 return this.BlockedByAccounts && this.BlockedByAccounts.length !== 0
84 toFormattedJSON (this: MServerFormattable) {