summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/pages/update.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2019-04-29 09:11:57 +0900
committerGitHub <noreply@github.com>2019-04-29 09:11:57 +0900
commit05b8111c1906c1285c9ddde758eda45b83792244 (patch)
treeda5d58c4ae18436f739eaee9e1801c6c48056be5 /src/server/api/endpoints/pages/update.ts
parentUpdate define.ts (diff)
downloadsharkey-05b8111c1906c1285c9ddde758eda45b83792244.tar.gz
sharkey-05b8111c1906c1285c9ddde758eda45b83792244.tar.bz2
sharkey-05b8111c1906c1285c9ddde758eda45b83792244.zip
Pages (#4811)
* wip * wip * wip * Update page-editor.vue * wip * wip * wip * wip * wip * wip * wip * Update page-editor.variable.core.vue * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update aiscript.ts * wip * Update package.json * wip * wip * wip * wip * wip * Update page.vue * wip * wip * wip * wip * more info * wip fn * wip * wip * wip
Diffstat (limited to 'src/server/api/endpoints/pages/update.ts')
-rw-r--r--src/server/api/endpoints/pages/update.ts123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/server/api/endpoints/pages/update.ts b/src/server/api/endpoints/pages/update.ts
new file mode 100644
index 0000000000..8ee34fc3ba
--- /dev/null
+++ b/src/server/api/endpoints/pages/update.ts
@@ -0,0 +1,123 @@
+import $ from 'cafy';
+import * as ms from 'ms';
+import define from '../../define';
+import { ApiError } from '../../error';
+import { Pages, DriveFiles } from '../../../../models';
+import { ID } from '../../../../misc/cafy-id';
+
+export const meta = {
+ desc: {
+ 'ja-JP': '指定したページの情報を更新します。',
+ },
+
+ tags: ['pages'],
+
+ requireCredential: true,
+
+ kind: 'write:pages',
+
+ limit: {
+ duration: ms('1hour'),
+ max: 300
+ },
+
+ params: {
+ pageId: {
+ validator: $.type(ID),
+ desc: {
+ 'ja-JP': '対象のページのID',
+ 'en-US': 'Target page ID.'
+ }
+ },
+
+ title: {
+ validator: $.str,
+ },
+
+ name: {
+ validator: $.optional.str,
+ },
+
+ summary: {
+ validator: $.optional.nullable.str,
+ },
+
+ content: {
+ validator: $.arr($.obj())
+ },
+
+ variables: {
+ validator: $.arr($.obj())
+ },
+
+ eyeCatchingImageId: {
+ validator: $.optional.nullable.type(ID),
+ },
+
+ font: {
+ validator: $.optional.str.or(['serif', 'sans-serif']),
+ },
+
+ alignCenter: {
+ 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'
+ },
+ }
+};
+
+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.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,
+ alignCenter: ps.alignCenter === undefined ? page.alignCenter : ps.alignCenter,
+ font: ps.font === undefined ? page.font : ps.font,
+ eyeCatchingImageId: ps.eyeCatchingImageId === null
+ ? null
+ : ps.eyeCatchingImageId === undefined
+ ? page.eyeCatchingImageId
+ : eyeCatchingImage!.id,
+ });
+});