2024-03-12 10:00:51 -05:00
|
|
|
import { getNodeABIVersion } from '@server/helpers/version.js'
|
2021-08-27 07:32:44 -05:00
|
|
|
import memoizee from 'memoizee'
|
2024-02-22 03:12:04 -06:00
|
|
|
import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Table } from 'sequelize-typescript'
|
2023-07-31 07:34:36 -05:00
|
|
|
import { AccountModel } from '../account/account.js'
|
2024-03-12 10:00:51 -05:00
|
|
|
import { ActorImageModel } from '../actor/actor-image.js'
|
2024-02-22 03:12:04 -06:00
|
|
|
import { SequelizeModel } from '../shared/index.js'
|
2020-04-23 02:32:53 -05: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
|
|
|
|
|
2024-03-12 10:00:51 -05:00
|
|
|
const { avatars, banners } = await ActorImageModel.listActorImages(actor)
|
|
|
|
actor.Avatars = avatars
|
|
|
|
actor.Banners = banners
|
|
|
|
|
2020-04-23 02:32:53 -05:00
|
|
|
return actor
|
|
|
|
}, { promise: true })
|
2017-12-12 10:53:50 -06:00
|
|
|
|
2019-04-23 02:50:57 -05:00
|
|
|
@DefaultScope(() => ({
|
2017-12-14 10:38:41 -06:00
|
|
|
include: [
|
|
|
|
{
|
2019-04-23 02:50:57 -05:00
|
|
|
model: AccountModel,
|
2017-12-14 10:38:41 -06:00
|
|
|
required: true
|
|
|
|
}
|
|
|
|
]
|
2019-04-23 02:50:57 -05:00
|
|
|
}))
|
2017-12-12 10:53:50 -06:00
|
|
|
@Table({
|
2019-04-26 02:16:43 -05:00
|
|
|
tableName: 'application',
|
|
|
|
timestamps: false
|
2017-12-12 10:53:50 -06:00
|
|
|
})
|
2024-02-22 03:12:04 -06:00
|
|
|
export class ApplicationModel extends SequelizeModel<ApplicationModel> {
|
2017-12-12 10:53:50 -06:00
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Default(0)
|
|
|
|
@IsInt
|
|
|
|
@Column
|
|
|
|
migrationVersion: number
|
|
|
|
|
2021-03-11 09:54:52 -06:00
|
|
|
@AllowNull(true)
|
|
|
|
@Column
|
|
|
|
latestPeerTubeVersion: string
|
|
|
|
|
2022-08-03 08:08:36 -05:00
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
nodeVersion: string
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
nodeABIVersion: number
|
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
@HasOne(() => AccountModel, {
|
|
|
|
foreignKey: {
|
|
|
|
allowNull: true
|
|
|
|
},
|
|
|
|
onDelete: 'cascade'
|
|
|
|
})
|
2023-07-31 07:34:36 -05:00
|
|
|
Account: Awaited<AccountModel>
|
2017-12-14 10:38:41 -06:00
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
static countTotal () {
|
|
|
|
return ApplicationModel.count()
|
|
|
|
}
|
2017-12-14 10:38:41 -06:00
|
|
|
|
|
|
|
static load () {
|
|
|
|
return ApplicationModel.findOne()
|
|
|
|
}
|
2022-08-03 08:08:36 -05: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 08:16:56 -05:00
|
|
|
|
|
|
|
await application.save()
|
2022-08-03 08:08:36 -05:00
|
|
|
}
|
2016-09-26 15:36:36 -05:00
|
|
|
}
|