mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 18:29:27 +02:00
server/server -> server/core
This commit is contained in:
parent
114327d4ce
commit
5a3d0650c9
838 changed files with 111 additions and 111 deletions
79
server/core/models/application/application.ts
Normal file
79
server/core/models/application/application.ts
Normal file
|
@ -0,0 +1,79 @@
|
|||
import memoizee from 'memoizee'
|
||||
import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript'
|
||||
import { getNodeABIVersion } from '@server/helpers/version.js'
|
||||
import { AttributesOnly } from '@peertube/peertube-typescript-utils'
|
||||
import { AccountModel } from '../account/account.js'
|
||||
|
||||
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 })
|
||||
|
||||
@DefaultScope(() => ({
|
||||
include: [
|
||||
{
|
||||
model: AccountModel,
|
||||
required: true
|
||||
}
|
||||
]
|
||||
}))
|
||||
@Table({
|
||||
tableName: 'application',
|
||||
timestamps: false
|
||||
})
|
||||
export class ApplicationModel extends Model<Partial<AttributesOnly<ApplicationModel>>> {
|
||||
|
||||
@AllowNull(false)
|
||||
@Default(0)
|
||||
@IsInt
|
||||
@Column
|
||||
migrationVersion: number
|
||||
|
||||
@AllowNull(true)
|
||||
@Column
|
||||
latestPeerTubeVersion: string
|
||||
|
||||
@AllowNull(false)
|
||||
@Column
|
||||
nodeVersion: string
|
||||
|
||||
@AllowNull(false)
|
||||
@Column
|
||||
nodeABIVersion: number
|
||||
|
||||
@HasOne(() => AccountModel, {
|
||||
foreignKey: {
|
||||
allowNull: true
|
||||
},
|
||||
onDelete: 'cascade'
|
||||
})
|
||||
Account: Awaited<AccountModel>
|
||||
|
||||
static countTotal () {
|
||||
return ApplicationModel.count()
|
||||
}
|
||||
|
||||
static load () {
|
||||
return ApplicationModel.findOne()
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
await application.save()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue