Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

feat: prompt to upgrade plugin when installing existing plugin #871

Merged
merged 2 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>