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