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