]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/application/application.ts
Translated using Weblate (Japanese)
[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'
c795e196 3import { getNodeABIVersion } from '@server/helpers/version'
6b5f72be 4import { AttributesOnly } from '@shared/typescript-utils'
50d6de9c 5import { AccountModel } from '../account/account'
8dc8a34e
C
6
7export const getServerActor = memoizee(async function () {
8 const application = await ApplicationModel.load()
9 if (!application) throw Error('Could not load Application from database.')
10
11 const actor = application.Account.Actor
12 actor.Account = application.Account
13
14 return actor
15}, { promise: true })
3fd3ab2d 16
3acc5084 17@DefaultScope(() => ({
50d6de9c
C
18 include: [
19 {
3acc5084 20 model: AccountModel,
50d6de9c
C
21 required: true
22 }
23 ]
3acc5084 24}))
3fd3ab2d 25@Table({
4f0f2ab2
C
26 tableName: 'application',
27 timestamps: false
3fd3ab2d 28})
16c016e8 29export class ApplicationModel extends Model<Partial<AttributesOnly<ApplicationModel>>> {
3fd3ab2d
C
30
31 @AllowNull(false)
32 @Default(0)
33 @IsInt
34 @Column
35 migrationVersion: number
36
32a18cbf
C
37 @AllowNull(true)
38 @Column
39 latestPeerTubeVersion: string
40
c795e196
C
41 @AllowNull(false)
42 @Column
43 nodeVersion: string
44
45 @AllowNull(false)
46 @Column
47 nodeABIVersion: number
48
50d6de9c
C
49 @HasOne(() => AccountModel, {
50 foreignKey: {
51 allowNull: true
52 },
53 onDelete: 'cascade'
54 })
55 Account: AccountModel
56
3fd3ab2d
C
57 static countTotal () {
58 return ApplicationModel.count()
59 }
50d6de9c
C
60
61 static load () {
62 return ApplicationModel.findOne()
63 }
c795e196
C
64
65 static async nodeABIChanged () {
66 const application = await this.load()
67
68 return application.nodeABIVersion !== getNodeABIVersion()
69 }
70
71 static async updateNodeVersions () {
72 const application = await this.load()
73
74 application.nodeABIVersion = getNodeABIVersion()
75 application.nodeVersion = process.version
94278907
C
76
77 await application.save()
c795e196 78 }
00d6b0dd 79}