From d6b22860a94859a91a57cabcd5ff8f3f92e8057a Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 1 Dec 2022 01:13:50 +0800 Subject: [PATCH] perf: refine setup data and logic of post publish (halo-dev/console#739) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement /milestone 2.0 #### What this PR does / why we need it: 更新系统初始化数据的资源,主要为了适配 https://github.com/halo-dev/console/pull/730 的修改。 #### Special notes for your reviewer: 测试方式: 1. 准备全新的环境。 2. 启动之后初始化,检查初始数据是否正常。 #### Does this PR introduce a user-facing change? ```release-note None ``` --- src/views/system/Setup.vue | 26 +++++++++++++++++---- src/views/system/setup-data/menu-items.json | 17 ++++++++------ src/views/system/setup-data/post.json | 2 +- src/views/system/setup-data/singlePage.json | 2 +- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/views/system/Setup.vue b/src/views/system/Setup.vue index 19ae8730d..49291d137 100644 --- a/src/views/system/Setup.vue +++ b/src/views/system/Setup.vue @@ -48,12 +48,30 @@ const handleSubmit = async () => { await apiClient.extension.tag.createcontentHaloRunV1alpha1Tag({ tag: tag as Tag, }); - await apiClient.post.draftPost({ postRequest: post as PostRequest }); + const { data: postData } = await apiClient.post.draftPost({ + postRequest: post as PostRequest, + }); + + try { + await apiClient.post.publishPost({ name: postData.metadata.name }); + } catch (e) { + console.error("Publish post failed", e); + } // Create singlePage - await apiClient.singlePage.draftSinglePage({ - singlePageRequest: singlePage as SinglePageRequest, - }); + const { data: singlePageData } = await apiClient.singlePage.draftSinglePage( + { + singlePageRequest: singlePage as SinglePageRequest, + } + ); + + try { + await apiClient.singlePage.publishSinglePage({ + name: singlePageData.metadata.name, + }); + } catch (e) { + console.error("Publish single page failed", e); + } // Create menu and menu items const menuItemPromises = menuItems.map((item) => { diff --git a/src/views/system/setup-data/menu-items.json b/src/views/system/setup-data/menu-items.json index 82746f7bf..603f19dbd 100644 --- a/src/views/system/setup-data/menu-items.json +++ b/src/views/system/setup-data/menu-items.json @@ -14,10 +14,11 @@ "spec": { "children": [], "priority": 1, - "categoryRef": { - "version": "content.halo.run/v1alpha1", + "targetRef": { + "group": "content.halo.run", + "version": "v1alpha1", "kind": "Post", - "name": "76514a40-6ef1-4ed9-b58a-e26945bde3ca" + "name": "5152aea5-c2e8-4717-8bba-2263d46e19d5" } }, "apiVersion": "v1alpha1", @@ -30,8 +31,9 @@ "href": "", "children": [], "priority": 2, - "tagRef": { - "version": "content.halo.run/v1alpha1", + "targetRef": { + "group": "content.halo.run", + "version": "v1alpha1", "kind": "Tag", "name": "c33ceabb-d8f1-4711-8991-bb8f5c92ad7c" } @@ -46,8 +48,9 @@ "href": "", "children": [], "priority": 3, - "singlePageRef": { - "version": "content.halo.run/v1alpha1", + "targetRef": { + "group": "content.halo.run", + "version": "v1alpha1", "kind": "SinglePage", "name": "373a5f79-f44f-441a-9df1-85a4f553ece8" } diff --git a/src/views/system/setup-data/post.json b/src/views/system/setup-data/post.json index 233b7e3da..4d829cc79 100644 --- a/src/views/system/setup-data/post.json +++ b/src/views/system/setup-data/post.json @@ -6,7 +6,7 @@ "template": "", "cover": "", "deleted": false, - "publish": true, + "publish": false, "publishTime": "", "pinned": false, "allowComment": true, diff --git a/src/views/system/setup-data/singlePage.json b/src/views/system/setup-data/singlePage.json index 66190aec8..3c605d8eb 100644 --- a/src/views/system/setup-data/singlePage.json +++ b/src/views/system/setup-data/singlePage.json @@ -6,7 +6,7 @@ "template": "", "cover": "", "deleted": false, - "publish": true, + "publish": false, "publishTime": "", "pinned": false, "allowComment": true,