Skip to content

Commit

Permalink
feat: prompt to upgrade plugin when installing existing plugin (halo-…
Browse files Browse the repository at this point in the history
…dev/console#871)

#### What type of PR is this?

/kind feature

#### What this PR does / why we need it:

安装已存在插件时,支持提示和升级插件。

#### Which issue(s) this PR fixes:

Fixes halo-dev#3164

#### Screenshots:

<img width="1411" alt="image" src="https://user-images.githubusercontent.com/21301288/220118697-12fbd7a7-57e6-47bb-a03b-b9c280571687.png">

#### Special notes for your reviewer:

测试方式:

1. Halo 需要切换到 halo-dev#3350 分支。
2. 在插件为 deployment 模式下启动 Halo。
3. 安装任意一个插件,然后继续上传安装相同插件。
4. 观察是否提示升级此插件。

#### Does this PR introduce a user-facing change?

```release-note
Console 端安装已存在插件时,支持提示并升级插件。
```
  • Loading branch information
ruibaby authored Feb 21, 2023
1 parent 28f631f commit ce604e6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/components/upload/UppyUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const props = withDefaults(
const emit = defineEmits<{
(event: "uploaded", response: SuccessResponse): void;
(event: "error", file, response): void;
}>();
const uppy = computed(() => {
Expand Down Expand Up @@ -72,6 +73,10 @@ uppy.value.on("upload-success", (_, response: SuccessResponse) => {
emit("uploaded", response);
});
uppy.value.on("upload-error", (file, _, response) => {
emit("error", file, response);
});
onUnmounted(() => {
uppy.value.close({ reason: "unmount" });
});
Expand Down
40 changes: 38 additions & 2 deletions src/modules/system/plugins/components/PluginUploadModal.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script lang="ts" setup>
import { VModal, Dialog } from "@halo-dev/components";
import { VModal, Dialog, Toast } from "@halo-dev/components";
import UppyUpload from "@/components/upload/UppyUpload.vue";
import { apiClient } from "@/utils/api-client";
import type { Plugin } from "@halo-dev/api-client";
import { computed, ref, watch } from "vue";
import type { SuccessResponse } from "@uppy/core";
import type { SuccessResponse, ErrorResponse } from "@uppy/core";
import type { UppyFile } from "@uppy/utils";
const props = withDefaults(
defineProps<{
Expand Down Expand Up @@ -76,6 +77,40 @@ const onUploaded = async (response: SuccessResponse) => {
});
};
interface PluginInstallationErrorResponse {
detail: string;
instance: string;
pluginName: string;
requestId: string;
status: number;
timestamp: string;
title: string;
type: string;
}
const PLUGIN_ALREADY_EXISTS_TYPE =
"https://halo.run/probs/plugin-alreay-exists";
const onError = (file: UppyFile<unknown>, response: ErrorResponse) => {
const body = response.body as PluginInstallationErrorResponse;
if (body.type === PLUGIN_ALREADY_EXISTS_TYPE) {
Dialog.info({
title: "插件已存在",
description: "当前安装的插件已存在,是否升级?",
onConfirm: async () => {
await apiClient.plugin.upgradePlugin({
name: body.pluginName,
file: file.data as File,
});
Toast.success("升级成功");
window.location.reload();
},
});
}
};
watch(
() => props.visible,
(newValue) => {
Expand Down Expand Up @@ -106,6 +141,7 @@ watch(
:endpoint="endpoint"
auto-proceed
@uploaded="onUploaded"
@error="onError"
/>
</VModal>
</template>

0 comments on commit ce604e6

Please sign in to comment.