From 2d6d9f30e1dc8e902ecaa9a9f6e2a4a6a73b6fe9 Mon Sep 17 00:00:00 2001 From: Oni-Men Date: Wed, 28 Aug 2019 08:00:05 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=9A=E3=83=BC=E3=82=B8URL=E3=81=8C?= =?UTF-8?q?=E4=BB=96=E3=81=A8=E9=87=8D=E8=A4=87=E3=81=97=E3=81=A6=E3=81=9F?= =?UTF-8?q?=E3=82=89=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92=E6=8A=95=E3=81=92?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=20(#5354)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Page]nameが重複したときの処理を追加 * page-editor側のerr.idにuuidを適用 * refactor * uuidをわけた --- locales/en-US.yml | 1 + locales/ja-JP.yml | 1 + .../views/pages/page-editor/page-editor.vue | 54 +++++++++++-------- src/server/api/endpoints/pages/create.ts | 14 +++++ src/server/api/endpoints/pages/update.ts | 16 ++++++ 5 files changed, 63 insertions(+), 23 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index 275229b79..ffe9b4a0f 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -1817,6 +1817,7 @@ pages: read-page: "Viewing the source" page-created: "Created the page!" page-updated: "Updated the page" + name-already-exists: "Specified page url already exists" are-you-sure-delete: "Do you want to delete this page?" page-deleted: "The page has been deleted" edit-this-page: "Edit this page" diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 5a1d8d707..ebc41b067 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -2015,6 +2015,7 @@ pages: read-page: "ソースを表示中" page-created: "ページを作成しました" page-updated: "ページを更新しました" + name-already-exists: "指定されたページURLは既に存在しています" are-you-sure-delete: "このページを削除しますか?" page-deleted: "ページを削除しました" edit-this-page: "このページを編集" diff --git a/src/client/app/common/views/pages/page-editor/page-editor.vue b/src/client/app/common/views/pages/page-editor/page-editor.vue index b29bbd4d3..b8db59da4 100644 --- a/src/client/app/common/views/pages/page-editor/page-editor.vue +++ b/src/client/app/common/views/pages/page-editor/page-editor.vue @@ -220,37 +220,38 @@ export default Vue.extend({ methods: { save() { + const options = { + title: this.title.trim(), + name: this.name.trim(), + summary: this.summary, + font: this.font, + hideTitleWhenPinned: this.hideTitleWhenPinned, + alignCenter: this.alignCenter, + content: this.content, + variables: this.variables, + eyeCatchingImageId: this.eyeCatchingImageId, + }; + if (this.pageId) { - this.$root.api('pages/update', { - pageId: this.pageId, - title: this.title.trim(), - name: this.name.trim(), - summary: this.summary, - font: this.font, - hideTitleWhenPinned: this.hideTitleWhenPinned, - alignCenter: this.alignCenter, - content: this.content, - variables: this.variables, - eyeCatchingImageId: this.eyeCatchingImageId, - }).then(page => { + options.pageId = this.pageId; + this.$root.api('pages/update', options) + .then(page => { this.currentName = this.name.trim(); this.$root.dialog({ type: 'success', text: this.$t('page-updated') }); + }).catch(err => { + if(err.id == '2298a392-d4a1-44c5-9ebb-ac1aeaa5a9ab'){ + this.$root.dialog({ + type: 'error', + text: this.$t('name-already-exists') + }); + } }); } else { - this.$root.api('pages/create', { - title: this.title.trim(), - name: this.name.trim(), - summary: this.summary, - font: this.font, - hideTitleWhenPinned: this.hideTitleWhenPinned, - alignCenter: this.alignCenter, - content: this.content, - variables: this.variables, - eyeCatchingImageId: this.eyeCatchingImageId, - }).then(page => { + this.$root.api('pages/create', options) + .then(page => { this.pageId = page.id; this.currentName = this.name.trim(); this.$root.dialog({ @@ -258,6 +259,13 @@ export default Vue.extend({ text: this.$t('page-created') }); this.$router.push(`/i/pages/edit/${this.pageId}`); + }).catch(err => { + if(err.id == '4650348e-301c-499a-83c9-6aa988c66bc1'){ + this.$root.dialog({ + type: 'error', + text: this.$t('name-already-exists') + }); + } }); } }, diff --git a/src/server/api/endpoints/pages/create.ts b/src/server/api/endpoints/pages/create.ts index a49a5d37b..f18c82ffd 100644 --- a/src/server/api/endpoints/pages/create.ts +++ b/src/server/api/endpoints/pages/create.ts @@ -76,6 +76,11 @@ export const meta = { code: 'NO_SUCH_FILE', id: 'b7b97489-0f66-4b12-a5ff-b21bd63f6e1c' }, + nameAlreadyExists: { + message: 'Specified name already exists.', + code: 'NAME_ALREADY_EXISTS', + id: '4650348e-301c-499a-83c9-6aa988c66bc1' + } } }; @@ -92,6 +97,15 @@ export default define(meta, async (ps, user) => { } } + await Pages.find({ + userId: user.id, + name: ps.name + }).then(result => { + if (result.length > 0) { + throw new ApiError(meta.errors.nameAlreadyExists); + } + }); + const page = await Pages.save(new Page({ id: genId(), createdAt: new Date(), diff --git a/src/server/api/endpoints/pages/update.ts b/src/server/api/endpoints/pages/update.ts index 9daf5e9ca..564beb84c 100644 --- a/src/server/api/endpoints/pages/update.ts +++ b/src/server/api/endpoints/pages/update.ts @@ -4,6 +4,7 @@ import define from '../../define'; import { ApiError } from '../../error'; import { Pages, DriveFiles } from '../../../../models'; import { ID } from '../../../../misc/cafy-id'; +import { Not } from 'typeorm'; export const meta = { desc: { @@ -85,6 +86,11 @@ export const meta = { 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' + } } }; @@ -109,6 +115,16 @@ export default define(meta, async (ps, user) => { } } + 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,