]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/application/application.ts
Merge branch 'master' into develop
[github/Chocobozzz/PeerTube.git] / server / models / application / application.ts
1 import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript'
2 import { AccountModel } from '../account/account'
3 import * as memoizee from 'memoizee'
4
5 export const getServerActor = memoizee(async function () {
6 const application = await ApplicationModel.load()
7 if (!application) throw Error('Could not load Application from database.')
8
9 const actor = application.Account.Actor
10 actor.Account = application.Account
11
12 return actor
13 }, { promise: true })
14
15 @DefaultScope(() => ({
16 include: [
17 {
18 model: AccountModel,
19 required: true
20 }
21 ]
22 }))
23 @Table({
24 tableName: 'application',
25 timestamps: false
26 })
27 export class ApplicationModel extends Model<ApplicationModel> {
28
29 @AllowNull(false)
30 @Default(0)
31 @IsInt
32 @Column
33 migrationVersion: number
34
35 @HasOne(() => AccountModel, {
36 foreignKey: {
37 allowNull: true
38 },
39 onDelete: 'cascade'
40 })
41 Account: AccountModel
42
43 static countTotal () {
44 return ApplicationModel.count()
45 }
46
47 static load () {
48 return ApplicationModel.findOne()
49 }
50 }