]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/server/server.ts
Fix HLS transcoding
[github/Chocobozzz/PeerTube.git] / server / models / server / server.ts
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 { AccountBlocklistModel } from '../account/account-blocklist'
6 import { ServerBlocklistModel } from './server-blocklist'
7
8 @Table({
9 tableName: 'server',
10 indexes: [
11 {
12 fields: [ 'host' ],
13 unique: true
14 }
15 ]
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
24 @AllowNull(false)
25 @Default(false)
26 @Column
27 redundancyAllowed: boolean
28
29 @CreatedAt
30 createdAt: Date
31
32 @UpdatedAt
33 updatedAt: Date
34
35 @HasMany(() => ActorModel, {
36 foreignKey: {
37 name: 'serverId',
38 allowNull: true
39 },
40 onDelete: 'CASCADE',
41 hooks: true
42 })
43 Actors: ActorModel[]
44
45 @HasMany(() => ServerBlocklistModel, {
46 foreignKey: {
47 allowNull: false
48 },
49 onDelete: 'CASCADE'
50 })
51 BlockedByAccounts: ServerBlocklistModel[]
52
53 static loadByHost (host: string) {
54 const query = {
55 where: {
56 host
57 }
58 }
59
60 return ServerModel.findOne(query)
61 }
62
63 isBlocked () {
64 return this.BlockedByAccounts && this.BlockedByAccounts.length !== 0
65 }
66
67 toFormattedJSON () {
68 return {
69 host: this.host
70 }
71 }
72 }