|
|
|
@ -1,11 +1,10 @@
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import { useDialog, VModal } from "@halo-dev/components";
|
|
|
|
|
import VueFilePond from "vue-filepond";
|
|
|
|
|
import "filepond/dist/filepond.min.css";
|
|
|
|
|
import FilePondUpload from "@/components/upload/FilePondUpload.vue";
|
|
|
|
|
import { apiClient } from "@halo-dev/admin-shared";
|
|
|
|
|
import type { Plugin } from "@halo-dev/api-client";
|
|
|
|
|
|
|
|
|
|
const FilePond = VueFilePond();
|
|
|
|
|
import { computed, ref } from "vue";
|
|
|
|
|
import type { AxiosResponse } from "axios";
|
|
|
|
|
|
|
|
|
|
withDefaults(
|
|
|
|
|
defineProps<{
|
|
|
|
@ -22,52 +21,51 @@ const emit = defineEmits<{
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const dialog = useDialog();
|
|
|
|
|
const FilePondUploadRef = ref();
|
|
|
|
|
|
|
|
|
|
const handleVisibleChange = (visible: boolean) => {
|
|
|
|
|
emit("update:visible", visible);
|
|
|
|
|
if (!visible) {
|
|
|
|
|
emit("close");
|
|
|
|
|
FilePondUploadRef.value.handleRemoveFiles();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const server = {
|
|
|
|
|
process: (fieldName, file, metadata, load) => {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append(fieldName, file, file.name);
|
|
|
|
|
|
|
|
|
|
apiClient.plugin.installPlugin(file).then((response) => {
|
|
|
|
|
load(response);
|
|
|
|
|
|
|
|
|
|
const plugin: Plugin = response.data as unknown as Plugin;
|
|
|
|
|
|
|
|
|
|
handleVisibleChange(false);
|
|
|
|
|
|
|
|
|
|
dialog.success({
|
|
|
|
|
title: "上传成功",
|
|
|
|
|
description: "是否启动当前安装的插件?",
|
|
|
|
|
onConfirm: async () => {
|
|
|
|
|
try {
|
|
|
|
|
const { data: pluginToUpdate } =
|
|
|
|
|
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin({
|
|
|
|
|
name: plugin.metadata.name,
|
|
|
|
|
});
|
|
|
|
|
pluginToUpdate.spec.enabled = true;
|
|
|
|
|
const uploadHandler = computed(() => {
|
|
|
|
|
return (file, config) =>
|
|
|
|
|
apiClient.plugin.installPlugin(
|
|
|
|
|
{
|
|
|
|
|
file: file,
|
|
|
|
|
},
|
|
|
|
|
config
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
|
|
|
|
|
name: pluginToUpdate.metadata.name,
|
|
|
|
|
plugin: pluginToUpdate,
|
|
|
|
|
});
|
|
|
|
|
const onUploaded = async (response: AxiosResponse) => {
|
|
|
|
|
const plugin = response.data as Plugin;
|
|
|
|
|
handleVisibleChange(false);
|
|
|
|
|
dialog.success({
|
|
|
|
|
title: "上传成功",
|
|
|
|
|
description: "是否启动当前安装的插件?",
|
|
|
|
|
onConfirm: async () => {
|
|
|
|
|
try {
|
|
|
|
|
const { data: pluginToUpdate } =
|
|
|
|
|
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin({
|
|
|
|
|
name: plugin.metadata.name,
|
|
|
|
|
});
|
|
|
|
|
pluginToUpdate.spec.enabled = true;
|
|
|
|
|
|
|
|
|
|
window.location.reload();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
|
|
|
|
|
name: pluginToUpdate.metadata.name,
|
|
|
|
|
plugin: pluginToUpdate,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
},
|
|
|
|
|
window.location.reload();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<template>
|
|
|
|
@ -77,12 +75,12 @@ const server = {
|
|
|
|
|
title="安装插件"
|
|
|
|
|
@update:visible="handleVisibleChange"
|
|
|
|
|
>
|
|
|
|
|
<file-pond
|
|
|
|
|
ref="pond"
|
|
|
|
|
<FilePondUpload
|
|
|
|
|
ref="FilePondUploadRef"
|
|
|
|
|
:allow-multiple="false"
|
|
|
|
|
:server="server"
|
|
|
|
|
label-idle="Drop JAR file here..."
|
|
|
|
|
name="file"
|
|
|
|
|
:handler="uploadHandler"
|
|
|
|
|
label-idle="点击选择文件或者拖拽文件到此处"
|
|
|
|
|
@uploaded="onUploaded"
|
|
|
|
|
/>
|
|
|
|
|
</VModal>
|
|
|
|
|
</template>
|
|
|
|
|