2023-07-27 14:31:52 +09:00
|
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2019-04-29 09:11:57 +09:00
|
|
|
|
import { Entity, Index, JoinColumn, Column, PrimaryColumn, ManyToOne } from 'typeorm';
|
2023-09-20 11:33:36 +09:00
|
|
|
|
import { id } from './util/id.js';
|
2023-08-16 17:51:28 +09:00
|
|
|
|
import { MiUser } from './User.js';
|
|
|
|
|
|
import { MiDriveFile } from './DriveFile.js';
|
2019-04-29 09:11:57 +09:00
|
|
|
|
|
2023-08-16 17:51:28 +09:00
|
|
|
|
@Entity('page')
|
2019-04-29 09:11:57 +09:00
|
|
|
|
@Index(['userId', 'name'], { unique: true })
|
2023-08-16 17:51:28 +09:00
|
|
|
|
export class MiPage {
|
2019-04-29 09:11:57 +09:00
|
|
|
|
@PrimaryColumn(id())
|
|
|
|
|
|
public id: string;
|
|
|
|
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
|
|
@Column('timestamp with time zone', {
|
2021-12-09 23:58:30 +09:00
|
|
|
|
comment: 'The updated date of the Page.',
|
2019-04-29 09:11:57 +09:00
|
|
|
|
})
|
|
|
|
|
|
public updatedAt: Date;
|
|
|
|
|
|
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
|
|
length: 256,
|
|
|
|
|
|
})
|
|
|
|
|
|
public title: string;
|
|
|
|
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
|
|
length: 256,
|
|
|
|
|
|
})
|
|
|
|
|
|
public name: string;
|
|
|
|
|
|
|
|
|
|
|
|
@Column('varchar', {
|
2021-12-09 23:58:30 +09:00
|
|
|
|
length: 256, nullable: true,
|
2019-04-29 09:11:57 +09:00
|
|
|
|
})
|
|
|
|
|
|
public summary: string | null;
|
|
|
|
|
|
|
|
|
|
|
|
@Column('boolean')
|
|
|
|
|
|
public alignCenter: boolean;
|
|
|
|
|
|
|
2019-07-07 06:56:13 +09:00
|
|
|
|
@Column('boolean', {
|
2021-12-09 23:58:30 +09:00
|
|
|
|
default: false,
|
2019-07-07 06:56:13 +09:00
|
|
|
|
})
|
|
|
|
|
|
public hideTitleWhenPinned: boolean;
|
|
|
|
|
|
|
2019-04-29 09:11:57 +09:00
|
|
|
|
@Column('varchar', {
|
|
|
|
|
|
length: 32,
|
|
|
|
|
|
})
|
|
|
|
|
|
public font: string;
|
|
|
|
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
|
|
@Column({
|
|
|
|
|
|
...id(),
|
2021-12-09 23:58:30 +09:00
|
|
|
|
comment: 'The ID of author.',
|
2019-04-29 09:11:57 +09:00
|
|
|
|
})
|
2023-08-16 17:51:28 +09:00
|
|
|
|
public userId: MiUser['id'];
|
2019-04-29 09:11:57 +09:00
|
|
|
|
|
2023-08-16 17:51:28 +09:00
|
|
|
|
@ManyToOne(type => MiUser, {
|
2021-12-09 23:58:30 +09:00
|
|
|
|
onDelete: 'CASCADE',
|
2019-04-29 09:11:57 +09:00
|
|
|
|
})
|
|
|
|
|
|
@JoinColumn()
|
2023-08-16 17:51:28 +09:00
|
|
|
|
public user: MiUser | null;
|
2019-04-29 09:11:57 +09:00
|
|
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
|
|
...id(),
|
|
|
|
|
|
nullable: true,
|
|
|
|
|
|
})
|
2023-08-16 17:51:28 +09:00
|
|
|
|
public eyeCatchingImageId: MiDriveFile['id'] | null;
|
2019-04-29 09:11:57 +09:00
|
|
|
|
|
2023-08-16 17:51:28 +09:00
|
|
|
|
@ManyToOne(type => MiDriveFile, {
|
2021-12-09 23:58:30 +09:00
|
|
|
|
onDelete: 'CASCADE',
|
2019-04-29 09:11:57 +09:00
|
|
|
|
})
|
|
|
|
|
|
@JoinColumn()
|
2023-08-16 17:51:28 +09:00
|
|
|
|
public eyeCatchingImage: MiDriveFile | null;
|
2019-04-29 09:11:57 +09:00
|
|
|
|
|
|
|
|
|
|
@Column('jsonb', {
|
2021-12-09 23:58:30 +09:00
|
|
|
|
default: [],
|
2019-04-29 09:11:57 +09:00
|
|
|
|
})
|
|
|
|
|
|
public content: Record<string, any>[];
|
|
|
|
|
|
|
|
|
|
|
|
@Column('jsonb', {
|
2021-12-09 23:58:30 +09:00
|
|
|
|
default: [],
|
2019-04-29 09:11:57 +09:00
|
|
|
|
})
|
|
|
|
|
|
public variables: Record<string, any>[];
|
|
|
|
|
|
|
2020-04-13 03:23:23 +09:00
|
|
|
|
@Column('varchar', {
|
|
|
|
|
|
length: 16384,
|
2021-12-09 23:58:30 +09:00
|
|
|
|
default: '',
|
2020-04-13 03:23:23 +09:00
|
|
|
|
})
|
|
|
|
|
|
public script: string;
|
|
|
|
|
|
|
2019-04-29 09:11:57 +09:00
|
|
|
|
/**
|
|
|
|
|
|
* public ... 公開
|
|
|
|
|
|
* followers ... フォロワーのみ
|
|
|
|
|
|
* specified ... visibleUserIds で指定したユーザーのみ
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Column('enum', { enum: ['public', 'followers', 'specified'] })
|
|
|
|
|
|
public visibility: 'public' | 'followers' | 'specified';
|
|
|
|
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
|
|
@Column({
|
|
|
|
|
|
...id(),
|
2021-12-09 23:58:30 +09:00
|
|
|
|
array: true, default: '{}',
|
2019-04-29 09:11:57 +09:00
|
|
|
|
})
|
2023-08-16 17:51:28 +09:00
|
|
|
|
public visibleUserIds: MiUser['id'][];
|
2019-04-29 09:11:57 +09:00
|
|
|
|
|
2019-05-17 19:56:47 +09:00
|
|
|
|
@Column('integer', {
|
2021-12-09 23:58:30 +09:00
|
|
|
|
default: 0,
|
2019-05-17 19:56:47 +09:00
|
|
|
|
})
|
|
|
|
|
|
public likedCount: number;
|
|
|
|
|
|
|
2023-08-16 17:51:28 +09:00
|
|
|
|
constructor(data: Partial<MiPage>) {
|
2019-04-29 09:11:57 +09:00
|
|
|
|
if (data == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
for (const [k, v] of Object.entries(data)) {
|
|
|
|
|
|
(this as any)[k] = v;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-11-07 11:14:47 +09:00
|
|
|
|
|
|
|
|
|
|
export const pageNameSchema = { type: 'string', pattern: /^[a-zA-Z0-9_-]{1,256}$/.source } as const;
|
2024-11-07 12:08:29 +09:00
|
|
|
|
|
|
|
|
|
|
const blockBaseSchema = {
|
|
|
|
|
|
type: 'object',
|
|
|
|
|
|
properties: {
|
|
|
|
|
|
id: { type: 'string', nullable: false },
|
|
|
|
|
|
type: { type: 'string', nullable: false },
|
|
|
|
|
|
},
|
|
|
|
|
|
required: ['id', 'type'],
|
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
|
|
const textBlockSchema = {
|
|
|
|
|
|
type: 'object',
|
|
|
|
|
|
properties: {
|
|
|
|
|
|
...blockBaseSchema.properties,
|
|
|
|
|
|
type: { type: 'string', nullable: false, enum: ['text'] },
|
|
|
|
|
|
text: { type: 'string', nullable: false },
|
|
|
|
|
|
},
|
|
|
|
|
|
required: [
|
|
|
|
|
|
...blockBaseSchema.required,
|
|
|
|
|
|
'text',
|
|
|
|
|
|
],
|
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
|
|
const headingBlockSchema = {
|
|
|
|
|
|
type: 'object',
|
|
|
|
|
|
properties: {
|
|
|
|
|
|
...blockBaseSchema.properties,
|
|
|
|
|
|
type: { type: 'string', nullable: false, enum: ['heading'] },
|
|
|
|
|
|
level: { type: 'number', nullable: false },
|
|
|
|
|
|
text: { type: 'string', nullable: false },
|
|
|
|
|
|
},
|
|
|
|
|
|
required: [
|
|
|
|
|
|
...blockBaseSchema.required,
|
|
|
|
|
|
'level',
|
|
|
|
|
|
'text',
|
|
|
|
|
|
],
|
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
|
|
const imageBlockSchema = {
|
|
|
|
|
|
type: 'object',
|
|
|
|
|
|
properties: {
|
|
|
|
|
|
...blockBaseSchema.properties,
|
|
|
|
|
|
type: { type: 'string', nullable: false, enum: ['image'] },
|
|
|
|
|
|
fileId: { type: 'string', nullable: true },
|
|
|
|
|
|
},
|
|
|
|
|
|
required: [
|
|
|
|
|
|
...blockBaseSchema.required,
|
|
|
|
|
|
'fileId',
|
|
|
|
|
|
],
|
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
|
|
const noteBlockSchema = {
|
|
|
|
|
|
type: 'object',
|
|
|
|
|
|
properties: {
|
|
|
|
|
|
...blockBaseSchema.properties,
|
|
|
|
|
|
type: { type: 'string', nullable: false, enum: ['note']},
|
2024-11-07 12:17:18 +09:00
|
|
|
|
detailed: { type: 'boolean', nullable: true },
|
|
|
|
|
|
note: { type: 'string', format: 'misskey:id', nullable: false },
|
2024-11-07 12:08:29 +09:00
|
|
|
|
},
|
|
|
|
|
|
required: [
|
|
|
|
|
|
...blockBaseSchema.required,
|
2024-11-07 12:17:18 +09:00
|
|
|
|
'note',
|
2024-11-07 12:08:29 +09:00
|
|
|
|
],
|
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 要素を入れ子にする必要が(一旦)なくなったので非推奨。headingBlockを使用すること */
|
|
|
|
|
|
const sectionBlockSchema = {
|
|
|
|
|
|
type: 'object',
|
|
|
|
|
|
properties: {
|
|
|
|
|
|
...blockBaseSchema.properties,
|
|
|
|
|
|
type: { type: 'string', nullable: false, enum: ['section'] },
|
|
|
|
|
|
title: { type: 'string', nullable: false },
|
|
|
|
|
|
children: {
|
|
|
|
|
|
type: 'array', nullable: false,
|
|
|
|
|
|
items: {
|
|
|
|
|
|
oneOf: [
|
|
|
|
|
|
textBlockSchema,
|
|
|
|
|
|
{ $ref: '#' },
|
|
|
|
|
|
headingBlockSchema,
|
|
|
|
|
|
imageBlockSchema,
|
|
|
|
|
|
noteBlockSchema,
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
required: [
|
|
|
|
|
|
...blockBaseSchema.required,
|
|
|
|
|
|
'title',
|
|
|
|
|
|
'children',
|
|
|
|
|
|
],
|
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
|
|
export const pageBlockSchema = {
|
|
|
|
|
|
type: 'object',
|
|
|
|
|
|
oneOf: [
|
|
|
|
|
|
textBlockSchema,
|
|
|
|
|
|
sectionBlockSchema,
|
|
|
|
|
|
headingBlockSchema,
|
|
|
|
|
|
imageBlockSchema,
|
|
|
|
|
|
noteBlockSchema,
|
|
|
|
|
|
],
|
|
|
|
|
|
} as const;
|