]>
Commit | Line | Data |
---|---|---|
c48e82b5 | 1 | import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3fd3ab2d | 2 | import { isHostValid } from '../../helpers/custom-validators/servers' |
f05a1c30 | 3 | import { ActorModel } from '../activitypub/actor' |
3fd3ab2d | 4 | import { throwIfNotValid } from '../utils' |
bfbd9128 C |
5 | import { AccountBlocklistModel } from '../account/account-blocklist' |
6 | import { ServerBlocklistModel } from './server-blocklist' | |
60862425 | 7 | |
3fd3ab2d C |
8 | @Table({ |
9 | tableName: 'server', | |
10 | indexes: [ | |
60862425 | 11 | { |
3fd3ab2d C |
12 | fields: [ 'host' ], |
13 | unique: true | |
60862425 | 14 | } |
60862425 | 15 | ] |
3fd3ab2d C |
16 | }) |
17 | export class ServerModel extends Model<ServerModel> { | |
18 | ||
19 | @AllowNull(false) | |
20 | @Is('Host', value => throwIfNotValid(value, isHostValid, 'valid host')) | |
21 | @Column | |
22 | host: string | |
23 | ||
c48e82b5 C |
24 | @AllowNull(false) |
25 | @Default(false) | |
26 | @Column | |
27 | redundancyAllowed: boolean | |
28 | ||
3fd3ab2d C |
29 | @CreatedAt |
30 | createdAt: Date | |
31 | ||
32 | @UpdatedAt | |
33 | updatedAt: Date | |
f05a1c30 C |
34 | |
35 | @HasMany(() => ActorModel, { | |
36 | foreignKey: { | |
37 | name: 'serverId', | |
38 | allowNull: true | |
39 | }, | |
40 | onDelete: 'CASCADE', | |
41 | hooks: true | |
42 | }) | |
43 | Actors: ActorModel[] | |
c48e82b5 | 44 | |
bfbd9128 C |
45 | @HasMany(() => ServerBlocklistModel, { |
46 | foreignKey: { | |
47 | allowNull: false | |
48 | }, | |
49 | onDelete: 'CASCADE' | |
50 | }) | |
51 | BlockedByAccounts: ServerBlocklistModel[] | |
52 | ||
c48e82b5 C |
53 | static loadByHost (host: string) { |
54 | const query = { | |
55 | where: { | |
56 | host | |
57 | } | |
58 | } | |
59 | ||
60 | return ServerModel.findOne(query) | |
61 | } | |
7ad9b984 | 62 | |
bfbd9128 C |
63 | isBlocked () { |
64 | return this.BlockedByAccounts && this.BlockedByAccounts.length !== 0 | |
65 | } | |
66 | ||
7ad9b984 C |
67 | toFormattedJSON () { |
68 | return { | |
69 | host: this.host | |
70 | } | |
71 | } | |
39445ead | 72 | } |