1 import memoizee from 'memoizee'
2 import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript'
3 import { getNodeABIVersion } from '@server/helpers/version'
4 import { AttributesOnly } from '@shared/typescript-utils'
5 import { AccountModel } from '../account/account'
7 export const getServerActor = memoizee(async function () {
8 const application = await ApplicationModel.load()
9 if (!application) throw Error('Could not load Application from database.')
11 const actor = application.Account.Actor
12 actor.Account = application.Account
17 @DefaultScope(() => ({
26 tableName: 'application',
29 export class ApplicationModel extends Model<Partial<AttributesOnly<ApplicationModel>>> {
35 migrationVersion: number
39 latestPeerTubeVersion: string
47 nodeABIVersion: number
49 @HasOne(() => AccountModel, {
57 static countTotal () {
58 return ApplicationModel.count()
62 return ApplicationModel.findOne()
65 static async nodeABIChanged () {
66 const application = await this.load()
68 return application.nodeABIVersion !== getNodeABIVersion()
71 static async updateNodeVersions () {
72 const application = await this.load()
74 application.nodeABIVersion = getNodeABIVersion()
75 application.nodeVersion = process.version
77 await application.save()