2024-02-22 03:12:04 -06:00
|
|
|
import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Table, UpdatedAt } from 'sequelize-typescript'
|
2023-07-31 07:34:36 -05:00
|
|
|
import { CustomPage } from '@peertube/peertube-models'
|
|
|
|
import { ActorModel } from '../actor/actor.js'
|
|
|
|
import { getServerActor } from '../application/application.js'
|
2024-02-22 03:12:04 -06:00
|
|
|
import { SequelizeModel } from '../shared/index.js'
|
2021-05-27 08:59:55 -05:00
|
|
|
|
|
|
|
@Table({
|
|
|
|
tableName: 'actorCustomPage',
|
|
|
|
indexes: [
|
|
|
|
{
|
|
|
|
fields: [ 'actorId', 'type' ],
|
|
|
|
unique: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2024-02-22 03:12:04 -06:00
|
|
|
export class ActorCustomPageModel extends SequelizeModel<ActorCustomPageModel> {
|
2021-05-27 08:59:55 -05:00
|
|
|
|
|
|
|
@AllowNull(true)
|
|
|
|
@Column(DataType.TEXT)
|
|
|
|
content: string
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
type: 'homepage'
|
|
|
|
|
|
|
|
@CreatedAt
|
|
|
|
createdAt: Date
|
|
|
|
|
|
|
|
@UpdatedAt
|
|
|
|
updatedAt: Date
|
|
|
|
|
|
|
|
@ForeignKey(() => ActorModel)
|
|
|
|
@Column
|
|
|
|
actorId: number
|
|
|
|
|
|
|
|
@BelongsTo(() => ActorModel, {
|
|
|
|
foreignKey: {
|
|
|
|
name: 'actorId',
|
|
|
|
allowNull: false
|
|
|
|
},
|
|
|
|
onDelete: 'cascade'
|
|
|
|
})
|
2023-07-31 07:34:36 -05:00
|
|
|
Actor: Awaited<ActorModel>
|
2021-05-27 08:59:55 -05:00
|
|
|
|
|
|
|
static async updateInstanceHomepage (content: string) {
|
|
|
|
const serverActor = await getServerActor()
|
|
|
|
|
|
|
|
return ActorCustomPageModel.upsert({
|
|
|
|
content,
|
|
|
|
actorId: serverActor.id,
|
|
|
|
type: 'homepage'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
static async loadInstanceHomepage () {
|
|
|
|
const serverActor = await getServerActor()
|
|
|
|
|
|
|
|
return ActorCustomPageModel.findOne({
|
|
|
|
where: {
|
|
|
|
actorId: serverActor.id
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
toFormattedJSON (): CustomPage {
|
|
|
|
return {
|
|
|
|
content: this.content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|