1
0
Fork 0
peertube/server/models/application/application.ts
2021-03-24 18:18:41 +01:00

54 lines
1.1 KiB
TypeScript

import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript'
import { AccountModel } from '../account/account'
import * as memoizee from 'memoizee'
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 {
@AllowNull(false)
@Default(0)
@IsInt
@Column
migrationVersion: number
@AllowNull(true)
@Column
latestPeerTubeVersion: string
@HasOne(() => AccountModel, {
foreignKey: {
allowNull: true
},
onDelete: 'cascade'
})
Account: AccountModel
static countTotal () {
return ApplicationModel.count()
}
static load () {
return ApplicationModel.findOne()
}
}