adjust types & api for pages

This commit is contained in:
Johann150 2022-07-31 21:28:48 +02:00
parent 95d92a711a
commit 90d35b951f
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
5 changed files with 11 additions and 44 deletions

View file

@ -75,21 +75,10 @@ export class Page {
@JoinColumn() @JoinColumn()
public eyeCatchingImage: DriveFile | null; public eyeCatchingImage: DriveFile | null;
@Column('jsonb', { @Column('text', {
default: [],
})
public content: Record<string, any>[];
@Column('jsonb', {
default: [],
})
public variables: Record<string, any>[];
@Column('varchar', {
length: 16384,
default: '', default: '',
}) })
public script: string; public text: string;
/** /**
* public ... * public ...

View file

@ -62,15 +62,13 @@ export const PageRepository = db.getRepository(Page).extend({
updatedAt: page.updatedAt.toISOString(), updatedAt: page.updatedAt.toISOString(),
userId: page.userId, userId: page.userId,
user: Users.pack(page.user || page.userId, me), // { detail: true } すると無限ループするので注意 user: Users.pack(page.user || page.userId, me), // { detail: true } すると無限ループするので注意
content: page.content, text: page.text,
variables: page.variables,
title: page.title, title: page.title,
name: page.name, name: page.name,
summary: page.summary, summary: page.summary,
hideTitleWhenPinned: page.hideTitleWhenPinned, hideTitleWhenPinned: page.hideTitleWhenPinned,
alignCenter: page.alignCenter, alignCenter: page.alignCenter,
font: page.font, font: page.font,
script: page.script,
eyeCatchingImageId: page.eyeCatchingImageId, eyeCatchingImageId: page.eyeCatchingImageId,
eyeCatchingImage: page.eyeCatchingImageId ? await DriveFiles.pack(page.eyeCatchingImageId) : null, eyeCatchingImage: page.eyeCatchingImageId ? await DriveFiles.pack(page.eyeCatchingImageId) : null,
attachedFiles: DriveFiles.packMany((await Promise.all(attachedFiles)).filter((x): x is DriveFile => x != null)), attachedFiles: DriveFiles.packMany((await Promise.all(attachedFiles)).filter((x): x is DriveFile => x != null)),

View file

@ -29,12 +29,8 @@ export const packedPageSchema = {
type: 'string', type: 'string',
optional: false, nullable: true, optional: false, nullable: true,
}, },
content: { text: {
type: 'array', type: 'string',
optional: false, nullable: false,
},
variables: {
type: 'array',
optional: false, nullable: false, optional: false, nullable: false,
}, },
userId: { userId: {

View file

@ -43,19 +43,13 @@ export const paramDef = {
title: { type: 'string' }, title: { type: 'string' },
name: { type: 'string', minLength: 1 }, name: { type: 'string', minLength: 1 },
summary: { type: 'string', nullable: true }, summary: { type: 'string', nullable: true },
content: { type: 'array', items: { text: { type: 'string', minLength: 1 },
type: 'object', additionalProperties: true,
} },
variables: { type: 'array', items: {
type: 'object', additionalProperties: true,
} },
script: { type: 'string' },
eyeCatchingImageId: { type: 'string', format: 'misskey:id', nullable: true }, eyeCatchingImageId: { type: 'string', format: 'misskey:id', nullable: true },
font: { type: 'string', enum: ['serif', 'sans-serif'], default: 'sans-serif' }, font: { type: 'string', enum: ['serif', 'sans-serif'], default: 'sans-serif' },
alignCenter: { type: 'boolean', default: false }, alignCenter: { type: 'boolean', default: false },
hideTitleWhenPinned: { type: 'boolean', default: false }, hideTitleWhenPinned: { type: 'boolean', default: false },
}, },
required: ['title', 'name', 'content', 'variables', 'script'], required: ['title', 'name', 'text'],
} as const; } as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@ -88,9 +82,7 @@ export default define(meta, paramDef, async (ps, user) => {
title: ps.title, title: ps.title,
name: ps.name, name: ps.name,
summary: ps.summary, summary: ps.summary,
content: ps.content, text: ps.text,
variables: ps.variables,
script: ps.script,
eyeCatchingImageId: eyeCatchingImage ? eyeCatchingImage.id : null, eyeCatchingImageId: eyeCatchingImage ? eyeCatchingImage.id : null,
userId: user.id, userId: user.id,
visibility: 'public', visibility: 'public',

View file

@ -49,19 +49,13 @@ export const paramDef = {
title: { type: 'string' }, title: { type: 'string' },
name: { type: 'string', minLength: 1 }, name: { type: 'string', minLength: 1 },
summary: { type: 'string', nullable: true }, summary: { type: 'string', nullable: true },
content: { type: 'array', items: { text: { type: 'string', minLength: 1 },
type: 'object', additionalProperties: true,
} },
variables: { type: 'array', items: {
type: 'object', additionalProperties: true,
} },
script: { type: 'string' },
eyeCatchingImageId: { type: 'string', format: 'misskey:id', nullable: true }, eyeCatchingImageId: { type: 'string', format: 'misskey:id', nullable: true },
font: { type: 'string', enum: ['serif', 'sans-serif'] }, font: { type: 'string', enum: ['serif', 'sans-serif'] },
alignCenter: { type: 'boolean' }, alignCenter: { type: 'boolean' },
hideTitleWhenPinned: { type: 'boolean' }, hideTitleWhenPinned: { type: 'boolean' },
}, },
required: ['pageId', 'title', 'name', 'content', 'variables', 'script'], required: ['pageId', 'title', 'name', 'text'],
} as const; } as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@ -101,9 +95,7 @@ export default define(meta, paramDef, async (ps, user) => {
title: ps.title, title: ps.title,
name: ps.name === undefined ? page.name : ps.name, name: ps.name === undefined ? page.name : ps.name,
summary: ps.name === undefined ? page.summary : ps.summary, summary: ps.name === undefined ? page.summary : ps.summary,
content: ps.content, text: ps.text,
variables: ps.variables,
script: ps.script,
alignCenter: ps.alignCenter === undefined ? page.alignCenter : ps.alignCenter, alignCenter: ps.alignCenter === undefined ? page.alignCenter : ps.alignCenter,
hideTitleWhenPinned: ps.hideTitleWhenPinned === undefined ? page.hideTitleWhenPinned : ps.hideTitleWhenPinned, hideTitleWhenPinned: ps.hideTitleWhenPinned === undefined ? page.hideTitleWhenPinned : ps.hideTitleWhenPinned,
font: ps.font === undefined ? page.font : ps.font, font: ps.font === undefined ? page.font : ps.font,