From 90d35b951f4f78c846b21ba81fdee5e465e06f8a Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sun, 31 Jul 2022 21:28:48 +0200 Subject: [PATCH] adjust types & api for pages --- packages/backend/src/models/entities/page.ts | 15 ++------------- packages/backend/src/models/repositories/page.ts | 4 +--- packages/backend/src/models/schema/page.ts | 8 ++------ .../src/server/api/endpoints/pages/create.ts | 14 +++----------- .../src/server/api/endpoints/pages/update.ts | 14 +++----------- 5 files changed, 11 insertions(+), 44 deletions(-) diff --git a/packages/backend/src/models/entities/page.ts b/packages/backend/src/models/entities/page.ts index 5b0ac90b2..67da0c13a 100644 --- a/packages/backend/src/models/entities/page.ts +++ b/packages/backend/src/models/entities/page.ts @@ -75,21 +75,10 @@ export class Page { @JoinColumn() public eyeCatchingImage: DriveFile | null; - @Column('jsonb', { - default: [], - }) - public content: Record[]; - - @Column('jsonb', { - default: [], - }) - public variables: Record[]; - - @Column('varchar', { - length: 16384, + @Column('text', { default: '', }) - public script: string; + public text: string; /** * public ... 公開 diff --git a/packages/backend/src/models/repositories/page.ts b/packages/backend/src/models/repositories/page.ts index 092b26b39..2dc67cd58 100644 --- a/packages/backend/src/models/repositories/page.ts +++ b/packages/backend/src/models/repositories/page.ts @@ -62,15 +62,13 @@ export const PageRepository = db.getRepository(Page).extend({ updatedAt: page.updatedAt.toISOString(), userId: page.userId, user: Users.pack(page.user || page.userId, me), // { detail: true } すると無限ループするので注意 - content: page.content, - variables: page.variables, + text: page.text, title: page.title, name: page.name, summary: page.summary, hideTitleWhenPinned: page.hideTitleWhenPinned, alignCenter: page.alignCenter, font: page.font, - script: page.script, eyeCatchingImageId: page.eyeCatchingImageId, eyeCatchingImage: page.eyeCatchingImageId ? await DriveFiles.pack(page.eyeCatchingImageId) : null, attachedFiles: DriveFiles.packMany((await Promise.all(attachedFiles)).filter((x): x is DriveFile => x != null)), diff --git a/packages/backend/src/models/schema/page.ts b/packages/backend/src/models/schema/page.ts index 55ba3ce7f..658361bf5 100644 --- a/packages/backend/src/models/schema/page.ts +++ b/packages/backend/src/models/schema/page.ts @@ -29,12 +29,8 @@ export const packedPageSchema = { type: 'string', optional: false, nullable: true, }, - content: { - type: 'array', - optional: false, nullable: false, - }, - variables: { - type: 'array', + text: { + type: 'string', optional: false, nullable: false, }, userId: { diff --git a/packages/backend/src/server/api/endpoints/pages/create.ts b/packages/backend/src/server/api/endpoints/pages/create.ts index 2257cd736..8eafe556c 100644 --- a/packages/backend/src/server/api/endpoints/pages/create.ts +++ b/packages/backend/src/server/api/endpoints/pages/create.ts @@ -43,19 +43,13 @@ export const paramDef = { title: { type: 'string' }, name: { type: 'string', minLength: 1 }, summary: { type: 'string', nullable: true }, - content: { type: 'array', items: { - type: 'object', additionalProperties: true, - } }, - variables: { type: 'array', items: { - type: 'object', additionalProperties: true, - } }, - script: { type: 'string' }, + text: { type: 'string', minLength: 1 }, eyeCatchingImageId: { type: 'string', format: 'misskey:id', nullable: true }, font: { type: 'string', enum: ['serif', 'sans-serif'], default: 'sans-serif' }, alignCenter: { type: 'boolean', default: false }, hideTitleWhenPinned: { type: 'boolean', default: false }, }, - required: ['title', 'name', 'content', 'variables', 'script'], + required: ['title', 'name', 'text'], } as const; // eslint-disable-next-line import/no-default-export @@ -88,9 +82,7 @@ export default define(meta, paramDef, async (ps, user) => { title: ps.title, name: ps.name, summary: ps.summary, - content: ps.content, - variables: ps.variables, - script: ps.script, + text: ps.text, eyeCatchingImageId: eyeCatchingImage ? eyeCatchingImage.id : null, userId: user.id, visibility: 'public', diff --git a/packages/backend/src/server/api/endpoints/pages/update.ts b/packages/backend/src/server/api/endpoints/pages/update.ts index 9fa6a7fc5..319af3b88 100644 --- a/packages/backend/src/server/api/endpoints/pages/update.ts +++ b/packages/backend/src/server/api/endpoints/pages/update.ts @@ -49,19 +49,13 @@ export const paramDef = { title: { type: 'string' }, name: { type: 'string', minLength: 1 }, summary: { type: 'string', nullable: true }, - content: { type: 'array', items: { - type: 'object', additionalProperties: true, - } }, - variables: { type: 'array', items: { - type: 'object', additionalProperties: true, - } }, - script: { type: 'string' }, + text: { type: 'string', minLength: 1 }, eyeCatchingImageId: { type: 'string', format: 'misskey:id', nullable: true }, font: { type: 'string', enum: ['serif', 'sans-serif'] }, alignCenter: { type: 'boolean' }, hideTitleWhenPinned: { type: 'boolean' }, }, - required: ['pageId', 'title', 'name', 'content', 'variables', 'script'], + required: ['pageId', 'title', 'name', 'text'], } as const; // eslint-disable-next-line import/no-default-export @@ -101,9 +95,7 @@ export default define(meta, paramDef, async (ps, user) => { title: ps.title, name: ps.name === undefined ? page.name : ps.name, summary: ps.name === undefined ? page.summary : ps.summary, - content: ps.content, - variables: ps.variables, - script: ps.script, + text: ps.text, alignCenter: ps.alignCenter === undefined ? page.alignCenter : ps.alignCenter, hideTitleWhenPinned: ps.hideTitleWhenPinned === undefined ? page.hideTitleWhenPinned : ps.hideTitleWhenPinned, font: ps.font === undefined ? page.font : ps.font,