From 2539932e16129992a2c0889b4ff527c265a8e2c7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 27 May 2021 15:59:55 +0200 Subject: Instance homepage support (#4007) * Prepare homepage parsers * Add ability to update instance hompage * Add ability to set homepage as landing page * Add homepage preview in admin * Dynamically update left menu for homepage * Inject home content in homepage * Add videos list and channel miniature custom markup * Remove unused elements in markup service --- server/models/account/actor-custom-page.ts | 69 ++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 server/models/account/actor-custom-page.ts (limited to 'server/models') diff --git a/server/models/account/actor-custom-page.ts b/server/models/account/actor-custom-page.ts new file mode 100644 index 000000000..893023181 --- /dev/null +++ b/server/models/account/actor-custom-page.ts @@ -0,0 +1,69 @@ +import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { CustomPage } from '@shared/models' +import { ActorModel } from '../actor/actor' +import { getServerActor } from '../application/application' + +@Table({ + tableName: 'actorCustomPage', + indexes: [ + { + fields: [ 'actorId', 'type' ], + unique: true + } + ] +}) +export class ActorCustomPageModel extends Model { + + @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' + }) + Actor: ActorModel + + 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 + } + } +} -- cgit v1.2.3