From 263fc50dc218deceee29bfa21a2bd9a276f28a3a Mon Sep 17 00:00:00 2001 From: XPoet Date: Thu, 28 Dec 2023 15:57:29 +0800 Subject: [PATCH 1/3] chore: delete redundant files --- .../github-authorize/github-authorize.styl | 0 .../github-authorize/github-authorize.vue | 22 ------------------- 2 files changed, 22 deletions(-) delete mode 100644 src/views/github-authorize/github-authorize.styl delete mode 100644 src/views/github-authorize/github-authorize.vue diff --git a/src/views/github-authorize/github-authorize.styl b/src/views/github-authorize/github-authorize.styl deleted file mode 100644 index e69de29b..00000000 diff --git a/src/views/github-authorize/github-authorize.vue b/src/views/github-authorize/github-authorize.vue deleted file mode 100644 index 8a7216cf..00000000 --- a/src/views/github-authorize/github-authorize.vue +++ /dev/null @@ -1,22 +0,0 @@ - - - - - From dfc6a3d59ef21dfbaedf9225141a10042e333674 Mon Sep 17 00:00:00 2001 From: XPoet Date: Thu, 28 Dec 2023 22:46:41 +0800 Subject: [PATCH 2/3] feat: save the deployment status to the cloud --- src/common/api/branch.ts | 10 +-- src/common/constant/init.ts | 4 ++ .../cloud-settings-bar/cloud-settings-bar.vue | 20 +++--- .../image-hosting-deploy.vue | 18 +++-- .../main-container/main-container.util.ts | 69 +++++++++++++++++++ src/views/main-container/main-container.vue | 27 +++++++- 6 files changed, 122 insertions(+), 26 deletions(-) create mode 100644 src/views/main-container/main-container.util.ts diff --git a/src/common/api/branch.ts b/src/common/api/branch.ts index e1b48839..ddc79d42 100644 --- a/src/common/api/branch.ts +++ b/src/common/api/branch.ts @@ -2,6 +2,7 @@ import { UserConfigInfoModel } from '@/common/model' import request from '@/utils/request' import axios from '@/utils/request/axios' import { GH_PAGES } from '@/common/constant' +import i18n from '@/plugins/vue/i18n' /** * 获取分支信息 @@ -58,18 +59,13 @@ export const getBranchInfoList = ( * 将当前分支 checkout 到 gh-pages 分支 * 部署到 GitHub Pages,完成图片资源托管,获取访问能力 * @param userConfigInfo - * @param $t * @param cb */ -export const checkoutGhPagesBranch = async ( - userConfigInfo: UserConfigInfoModel, - $t: any, - cb?: any -) => { +export const checkoutGhPagesBranch = async (userConfigInfo: UserConfigInfoModel, cb?: any) => { const { owner, selectedRepo: repo, selectedBranch } = userConfigInfo const initLoading = ElLoading.service({ - text: $t('settings.image_hosting_deploy.deploying') + text: i18n.global.t('settings.image_hosting_deploy.deploying') }) const cbHandler = (evt: boolean = false) => { diff --git a/src/common/constant/init.ts b/src/common/constant/init.ts index 32ff9570..ea374592 100644 --- a/src/common/constant/init.ts +++ b/src/common/constant/init.ts @@ -9,3 +9,7 @@ export const PICX_DEL_IMG_DESC = 'Delete image via PicX (https://github.com/XPoe export const PICX_INIT_SETTINGS_MSG = 'Init settings via PicX (https://github.com/XPoet/picx)' export const PICX_UPDATE_SETTINGS_MSG = 'Update settings via PicX (https://github.com/XPoet/picx)' export const PICX_INIT_REPO_MSG = 'Init repo via PicX (https://github.com/XPoet/picx)' + +export const PICX_INIT_DEPLOY_MSG = 'Init deploy status via PicX (https://github.com/XPoet/picx)' +export const PICX_UPDATE_DEPLOY_MSG = + 'Update deploy status via PicX (https://github.com/XPoet/picx)' diff --git a/src/components/cloud-settings-bar/cloud-settings-bar.vue b/src/components/cloud-settings-bar/cloud-settings-bar.vue index 8b88f5e7..d9c5ee99 100644 --- a/src/components/cloud-settings-bar/cloud-settings-bar.vue +++ b/src/components/cloud-settings-bar/cloud-settings-bar.vue @@ -98,15 +98,17 @@ const onOK = () => { watch( () => userSettings, (settings) => { - // 本地设置发生变化时,判断和云端设置是否相等 - if (deepObjectEqual(settings, cloudSettings.value!)) { - // 相等情况 - selectedAction.value = CloudSettingsActions.equal - saveDisabled.value = true - } else { - // 不相等情况 - selectedAction.value = CloudSettingsActions.update - saveDisabled.value = false + if (cloudSettings.value) { + // 本地设置发生变化时,判断和云端设置是否相等 + if (deepObjectEqual(settings, cloudSettings.value)) { + // 相等情况 + selectedAction.value = CloudSettingsActions.equal + saveDisabled.value = true + } else { + // 不相等情况 + selectedAction.value = CloudSettingsActions.update + saveDisabled.value = false + } } }, { diff --git a/src/components/image-hosting-deploy/image-hosting-deploy.vue b/src/components/image-hosting-deploy/image-hosting-deploy.vue index b7315f0a..f8bd86a5 100644 --- a/src/components/image-hosting-deploy/image-hosting-deploy.vue +++ b/src/components/image-hosting-deploy/image-hosting-deploy.vue @@ -50,15 +50,15 @@ diff --git a/src/views/main-container/main-container.util.ts b/src/views/main-container/main-container.util.ts new file mode 100644 index 00000000..207c9e50 --- /dev/null +++ b/src/views/main-container/main-container.util.ts @@ -0,0 +1,69 @@ +import { computed } from 'vue' +import request from '@/utils/request' +import { PICX_INIT_DEPLOY_MSG, PICX_UPDATE_DEPLOY_MSG } from '@/common/constant' +import { store } from '@/stores' + +const userSettings = computed(() => store.getters.getUserSettings).value +const userConfigInfo = computed(() => store.getters.getUserConfigInfo).value + +const filename = '.deploy' + +/** + * 获取云端仓库存储的部署状态信息 + */ +export const getCloudDeployInfo = async () => { + const { owner, selectedRepo: repo, selectedBranch: branch } = userConfigInfo + const res = await request({ + url: `/repos/${owner}/${repo}/contents/${filename}`, + method: 'GET', + noShowErrorMsg: true, + cache: { + maxAge: 0 + }, + params: { + branch, + timestamp: Date.now() + } + }) + + return Promise.resolve(res) +} + +/** + * 保存部署状态信息到云端仓库 + */ +export const saveCloudDeployInfo = async () => { + const { owner, selectedRepo: repo, selectedBranch: branch } = userConfigInfo + + const res = await getCloudDeployInfo() + + const data: any = { + message: res ? PICX_UPDATE_DEPLOY_MSG : PICX_INIT_DEPLOY_MSG, + content: window.btoa(JSON.stringify(userSettings.deploy)) + } + + if (res) { + data.sha = res.sha + } else { + data.branch = branch + } + + const res2 = await request({ + url: `/repos/${owner}/${repo}/contents/${filename}`, + method: 'PUT', + data, + noShowErrorMsg: true + }) + + return Promise.resolve(res2) +} + +/** + * 设置云端仓库的部署状态到本地 + * @param content + */ +export const setCloudDeployInfo = (content: string) => { + store.dispatch('SET_USER_SETTINGS', { + deploy: JSON.parse(window.atob(content)) + }) +} diff --git a/src/views/main-container/main-container.vue b/src/views/main-container/main-container.vue index 4577e83e..afd4abee 100644 --- a/src/views/main-container/main-container.vue +++ b/src/views/main-container/main-container.vue @@ -19,14 +19,35 @@ diff --git a/src/stores/modules/user-settings/index.ts b/src/stores/modules/user-settings/index.ts index b65c6539..c4d301a5 100644 --- a/src/stores/modules/user-settings/index.ts +++ b/src/stores/modules/user-settings/index.ts @@ -16,7 +16,7 @@ import UserSettingsStateTypes, { ImgLinkRuleActionsEnum } from '@/stores/modules/user-settings/types' import { LS_PICX_SETTINGS } from '@/common/constant' -import { DeployServerEnum } from '@/components/image-hosting-deploy/image-hosting-deploy.model' +import { DeployServerEnum } from '@/components/deploy-bar/deploy-bar.model' import { imgLinkRuleVerification } from '@/stores/modules/user-settings/utils' const initSettings: UserSettingsModel = { diff --git a/src/views/my-settings/my-settings.vue b/src/views/my-settings/my-settings.vue index 4fc7c005..9327ccb2 100644 --- a/src/views/my-settings/my-settings.vue +++ b/src/views/my-settings/my-settings.vue @@ -99,6 +99,7 @@ :key="item.name + '-' + item.id" :label="item.name" :value="item.name" + :disabled="isDeployGitHubPages(item.name)" class="image-link-type-rule-option" > {{ item.name }} @@ -149,7 +150,7 @@ - + @@ -178,7 +179,7 @@