2021-08-27 08:32:44 -04:00
|
|
|
import memoizee from 'memoizee'
|
2017-12-14 11:38:41 -05:00
|
|
|
import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript'
|
2022-08-03 09:08:36 -04:00
|
|
|
import { getNodeABIVersion } from '@server/helpers/version'
|
2021-12-16 12:04:16 -05:00
|
|
|
import { AttributesOnly } from '@shared/typescript-utils'
|
2017-12-14 11:38:41 -05:00
|
|
|
import { AccountModel } from '../account/account'
|
2020-04-23 03:32:53 -04:00
|
|
|
|
|
|
|
export const getServerActor = memoizee(async function () {
|
|
|
|
const application = await ApplicationModel.load()
|
|
|
|
if (!application) throw Error('Could not load Application from database.')
|
|
|
|
|
|
|
|
const actor = application.Account.Actor
|
|
|
|
actor.Account = application.Account
|
|
|
|
|
|
|
|
return actor
|
|
|
|
}, { promise: true })
|
2017-12-12 11:53:50 -05:00
|
|
|
|
2019-04-23 03:50:57 -04:00
|
|
|
@DefaultScope(() => ({
|
2017-12-14 11:38:41 -05:00
|
|
|
include: [
|
|
|
|
{
|
2019-04-23 03:50:57 -04:00
|
|
|
model: AccountModel,
|
2017-12-14 11:38:41 -05:00
|
|
|
required: true
|
|
|
|
}
|
|
|
|
]
|
2019-04-23 03:50:57 -04:00
|
|
|
}))
|
2017-12-12 11:53:50 -05:00
|
|
|
@Table({
|
2019-04-26 03:16:43 -04:00
|
|
|
tableName: 'application',
|
|
|
|
timestamps: false
|
2017-12-12 11:53:50 -05:00
|
|
|
})
|
2021-05-12 08:09:04 -04:00
|
|
|
export class ApplicationModel extends Model<Partial<AttributesOnly<ApplicationModel>>> {
|
2017-12-12 11:53:50 -05:00
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Default(0)
|
|
|
|
@IsInt
|
|
|
|
@Column
|
|
|
|
migrationVersion: number
|
|
|
|
|
2021-03-11 10:54:52 -05:00
|
|
|
@AllowNull(true)
|
|
|
|
@Column
|
|
|
|
latestPeerTubeVersion: string
|
|
|
|
|
2022-08-03 09:08:36 -04:00
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
nodeVersion: string
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
nodeABIVersion: number
|
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
@HasOne(() => AccountModel, {
|
|
|
|
foreignKey: {
|
|
|
|
allowNull: true
|
|
|
|
},
|
|
|
|
onDelete: 'cascade'
|
|
|
|
})
|
|
|
|
Account: AccountModel
|
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
static countTotal () {
|
|
|
|
return ApplicationModel.count()
|
|
|
|
}
|
2017-12-14 11:38:41 -05:00
|
|
|
|
|
|
|
static load () {
|
|
|
|
return ApplicationModel.findOne()
|
|
|
|
}
|
2022-08-03 09:08:36 -04:00
|
|
|
|
|
|
|
static async nodeABIChanged () {
|
|
|
|
const application = await this.load()
|
|
|
|
|
|
|
|
return application.nodeABIVersion !== getNodeABIVersion()
|
|
|
|
}
|
|
|
|
|
|
|
|
static async updateNodeVersions () {
|
|
|
|
const application = await this.load()
|
|
|
|
|
|
|
|
application.nodeABIVersion = getNodeABIVersion()
|
|
|
|
application.nodeVersion = process.version
|
2022-08-03 09:16:56 -04:00
|
|
|
|
|
|
|
await application.save()
|
2022-08-03 09:08:36 -04:00
|
|
|
}
|
2016-09-26 16:36:36 -04:00
|
|
|
}
|