]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/application/application.ts
Merge branch 'release/4.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / models / application / application.ts
CommitLineData
41fb13c3 1import memoizee from 'memoizee'
50d6de9c 2import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript'
6b5f72be 3import { AttributesOnly } from '@shared/typescript-utils'
50d6de9c 4import { AccountModel } from '../account/account'
8dc8a34e
C
5
6export 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 })
3fd3ab2d 15
3acc5084 16@DefaultScope(() => ({
50d6de9c
C
17 include: [
18 {
3acc5084 19 model: AccountModel,
50d6de9c
C
20 required: true
21 }
22 ]
3acc5084 23}))
3fd3ab2d 24@Table({
4f0f2ab2
C
25 tableName: 'application',
26 timestamps: false
3fd3ab2d 27})
16c016e8 28export class ApplicationModel extends Model<Partial<AttributesOnly<ApplicationModel>>> {
3fd3ab2d
C
29
30 @AllowNull(false)
31 @Default(0)
32 @IsInt
33 @Column
34 migrationVersion: number
35
32a18cbf
C
36 @AllowNull(true)
37 @Column
38 latestPeerTubeVersion: string
39
50d6de9c
C
40 @HasOne(() => AccountModel, {
41 foreignKey: {
42 allowNull: true
43 },
44 onDelete: 'cascade'
45 })
46 Account: AccountModel
47
3fd3ab2d
C
48 static countTotal () {
49 return ApplicationModel.count()
50 }
50d6de9c
C
51
52 static load () {
53 return ApplicationModel.findOne()
54 }
00d6b0dd 55}