mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
server/server -> server/core
This commit is contained in:
parent
114327d4ce
commit
5a3d0650c9
838 changed files with 111 additions and 111 deletions
124
server/core/models/runner/runner.ts
Normal file
124
server/core/models/runner/runner.ts
Normal file
|
@ -0,0 +1,124 @@
|
|||
import { FindOptions } from 'sequelize'
|
||||
import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
|
||||
import { MRunner } from '@server/types/models/runners/index.js'
|
||||
import { Runner } from '@peertube/peertube-models'
|
||||
import { AttributesOnly } from '@peertube/peertube-typescript-utils'
|
||||
import { getSort } from '../shared/index.js'
|
||||
import { RunnerRegistrationTokenModel } from './runner-registration-token.js'
|
||||
import { CONSTRAINTS_FIELDS } from '@server/initializers/constants.js'
|
||||
|
||||
@Table({
|
||||
tableName: 'runner',
|
||||
indexes: [
|
||||
{
|
||||
fields: [ 'runnerToken' ],
|
||||
unique: true
|
||||
},
|
||||
{
|
||||
fields: [ 'runnerRegistrationTokenId' ]
|
||||
},
|
||||
{
|
||||
fields: [ 'name' ],
|
||||
unique: true
|
||||
}
|
||||
]
|
||||
})
|
||||
export class RunnerModel extends Model<Partial<AttributesOnly<RunnerModel>>> {
|
||||
|
||||
// Used to identify the appropriate runner when it uses the runner REST API
|
||||
@AllowNull(false)
|
||||
@Column
|
||||
runnerToken: string
|
||||
|
||||
@AllowNull(false)
|
||||
@Column
|
||||
name: string
|
||||
|
||||
@AllowNull(true)
|
||||
@Column(DataType.STRING(CONSTRAINTS_FIELDS.RUNNERS.DESCRIPTION.max))
|
||||
description: string
|
||||
|
||||
@AllowNull(false)
|
||||
@Column
|
||||
lastContact: Date
|
||||
|
||||
@AllowNull(false)
|
||||
@Column
|
||||
ip: string
|
||||
|
||||
@CreatedAt
|
||||
createdAt: Date
|
||||
|
||||
@UpdatedAt
|
||||
updatedAt: Date
|
||||
|
||||
@ForeignKey(() => RunnerRegistrationTokenModel)
|
||||
@Column
|
||||
runnerRegistrationTokenId: number
|
||||
|
||||
@BelongsTo(() => RunnerRegistrationTokenModel, {
|
||||
foreignKey: {
|
||||
allowNull: false
|
||||
},
|
||||
onDelete: 'cascade'
|
||||
})
|
||||
RunnerRegistrationToken: Awaited<RunnerRegistrationTokenModel>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static load (id: number) {
|
||||
return RunnerModel.findByPk(id)
|
||||
}
|
||||
|
||||
static loadByToken (runnerToken: string) {
|
||||
const query = {
|
||||
where: { runnerToken }
|
||||
}
|
||||
|
||||
return RunnerModel.findOne(query)
|
||||
}
|
||||
|
||||
static loadByName (name: string) {
|
||||
const query = {
|
||||
where: { name }
|
||||
}
|
||||
|
||||
return RunnerModel.findOne(query)
|
||||
}
|
||||
|
||||
static listForApi (options: {
|
||||
start: number
|
||||
count: number
|
||||
sort: string
|
||||
}) {
|
||||
const { start, count, sort } = options
|
||||
|
||||
const query: FindOptions = {
|
||||
offset: start,
|
||||
limit: count,
|
||||
order: getSort(sort)
|
||||
}
|
||||
|
||||
return Promise.all([
|
||||
RunnerModel.count(query),
|
||||
RunnerModel.findAll<MRunner>(query)
|
||||
]).then(([ total, data ]) => ({ total, data }))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
toFormattedJSON (this: MRunner): Runner {
|
||||
return {
|
||||
id: this.id,
|
||||
|
||||
name: this.name,
|
||||
description: this.description,
|
||||
|
||||
ip: this.ip,
|
||||
lastContact: this.lastContact,
|
||||
|
||||
createdAt: this.createdAt,
|
||||
updatedAt: this.updatedAt
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue