summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/pages/update.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-11-12 02:02:25 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-11-12 02:02:25 +0900
commit0e4a111f81cceed275d9bec2695f6e401fb654d8 (patch)
tree40874799472fa07416f17b50a398ac33b7771905 /src/server/api/endpoints/pages/update.ts
parentupdate deps (diff)
downloadmisskey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.gz
misskey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.bz2
misskey-0e4a111f81cceed275d9bec2695f6e401fb654d8.zip
refactoring
Resolve #7779
Diffstat (limited to 'src/server/api/endpoints/pages/update.ts')
-rw-r--r--src/server/api/endpoints/pages/update.ts141
1 files changed, 0 insertions, 141 deletions
diff --git a/src/server/api/endpoints/pages/update.ts b/src/server/api/endpoints/pages/update.ts
deleted file mode 100644
index b3a7f26963..0000000000
--- a/src/server/api/endpoints/pages/update.ts
+++ /dev/null
@@ -1,141 +0,0 @@
-import $ from 'cafy';
-import * as ms from 'ms';
-import define from '../../define';
-import { ApiError } from '../../error';
-import { Pages, DriveFiles } from '@/models/index';
-import { ID } from '@/misc/cafy-id';
-import { Not } from 'typeorm';
-
-export const meta = {
- tags: ['pages'],
-
- requireCredential: true as const,
-
- kind: 'write:pages',
-
- limit: {
- duration: ms('1hour'),
- max: 300
- },
-
- params: {
- pageId: {
- validator: $.type(ID),
- },
-
- title: {
- validator: $.str,
- },
-
- name: {
- validator: $.str.min(1),
- },
-
- summary: {
- validator: $.optional.nullable.str,
- },
-
- content: {
- validator: $.arr($.obj())
- },
-
- variables: {
- validator: $.arr($.obj())
- },
-
- script: {
- validator: $.str,
- },
-
- eyeCatchingImageId: {
- validator: $.optional.nullable.type(ID),
- },
-
- font: {
- validator: $.optional.str.or(['serif', 'sans-serif']),
- },
-
- alignCenter: {
- validator: $.optional.bool,
- },
-
- hideTitleWhenPinned: {
- validator: $.optional.bool,
- },
- },
-
- errors: {
- noSuchPage: {
- message: 'No such page.',
- code: 'NO_SUCH_PAGE',
- id: '21149b9e-3616-4778-9592-c4ce89f5a864'
- },
-
- accessDenied: {
- message: 'Access denied.',
- code: 'ACCESS_DENIED',
- id: '3c15cd52-3b4b-4274-967d-6456fc4f792b'
- },
-
- noSuchFile: {
- message: 'No such file.',
- code: 'NO_SUCH_FILE',
- id: 'cfc23c7c-3887-490e-af30-0ed576703c82'
- },
- nameAlreadyExists: {
- message: 'Specified name already exists.',
- code: 'NAME_ALREADY_EXISTS',
- id: '2298a392-d4a1-44c5-9ebb-ac1aeaa5a9ab'
- }
- }
-};
-
-export default define(meta, async (ps, user) => {
- const page = await Pages.findOne(ps.pageId);
- if (page == null) {
- throw new ApiError(meta.errors.noSuchPage);
- }
- if (page.userId !== user.id) {
- throw new ApiError(meta.errors.accessDenied);
- }
-
- let eyeCatchingImage = null;
- if (ps.eyeCatchingImageId != null) {
- eyeCatchingImage = await DriveFiles.findOne({
- id: ps.eyeCatchingImageId,
- userId: user.id
- });
-
- if (eyeCatchingImage == null) {
- throw new ApiError(meta.errors.noSuchFile);
- }
- }
-
- await Pages.find({
- id: Not(ps.pageId),
- userId: user.id,
- name: ps.name
- }).then(result => {
- if (result.length > 0) {
- throw new ApiError(meta.errors.nameAlreadyExists);
- }
- });
-
- await Pages.update(page.id, {
- updatedAt: new Date(),
- 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,
- alignCenter: ps.alignCenter === undefined ? page.alignCenter : ps.alignCenter,
- hideTitleWhenPinned: ps.hideTitleWhenPinned === undefined ? page.hideTitleWhenPinned : ps.hideTitleWhenPinned,
- font: ps.font === undefined ? page.font : ps.font,
- eyeCatchingImageId: ps.eyeCatchingImageId === null
- ? null
- : ps.eyeCatchingImageId === undefined
- ? page.eyeCatchingImageId
- : eyeCatchingImage!.id,
- });
-});