Fix: IQuickStart types

This commit is contained in:
Lazy 2024-04-23 22:22:49 +08:00
parent edc22a6ae3
commit 445e2d2273
5 changed files with 28 additions and 12 deletions

11
common/global.d.ts vendored
View File

@ -198,7 +198,7 @@ export interface ILayoutCard {
disableDelete?: boolean;
}
export interface IQuickStartTemplate {
export interface IQuickStartPackages {
language: string;
description: string;
title: string;
@ -210,3 +210,12 @@ export interface IQuickStartTemplate {
author: string;
setupInfo?: IJsonData;
}
export interface IQuickStartTemplate {
remark: string;
languages: {
label: string;
value: string;
}[];
packages: IQuickStartPackages[];
}

View File

@ -3,7 +3,7 @@ import Instance from "../../instance/instance";
import InstanceCommand from "../base/command";
import fs from "fs-extra";
import { QuickInstallTask } from "../../../service/async_task_service/quick_install";
import { IQuickStartTemplate } from "common/global";
import { IQuickStartPackages } from "common/global";
export default class GeneralInstallCommand extends InstanceCommand {
private process?: QuickInstallTask;
@ -18,7 +18,7 @@ export default class GeneralInstallCommand extends InstanceCommand {
instance.status(Instance.STATUS_STOP);
}
async exec(instance: Instance, params?: IQuickStartTemplate) {
async exec(instance: Instance, params?: IQuickStartPackages) {
if (instance.status() !== Instance.STATUS_STOP)
return instance.failure(new Error($t("TXT_CODE_general_update.statusErr_notStop")));
if (instance.asynchronousTask)
@ -26,8 +26,12 @@ export default class GeneralInstallCommand extends InstanceCommand {
if (!params) throw new Error("GeneralInstallCommand: No params");
try {
instance.setLock(true);
instance.status(Instance.STATUS_BUSY);
instance.println($t("安装"), $t("正在清空实例现有文件,请耐心等待..."));
if (instance.config.cwd.length > 1) fs.removeSync(instance.config.cwd);
if (instance.config.cwd.length > 1) {
fs.removeSync(instance.config.cwd);
fs.mkdirsSync(instance.config.cwd);
}
instance.println($t("安装"), $t("删除完成!"));
this.process = new QuickInstallTask(
instance.config.nickname,

View File

@ -6,7 +6,8 @@ import type {
IJsonData,
IMapData,
IGlobalInstanceDockerConfig,
IQuickStartTemplate
IQuickStartTemplate,
IQuickStartPackages
} from "../../../common/global";
import type { INSTANCE_STATUS_CODE } from "./const";
@ -193,6 +194,7 @@ export interface NewInstanceForm {
}
export type QuickStartTemplate = IQuickStartTemplate;
export type QuickStartPackages = IQuickStartPackages;
export interface LabelValueOption {
label: string;

View File

@ -1,12 +1,11 @@
<script setup lang="ts">
import { ref, onMounted, reactive, computed } from "vue";
import { getCurrentLang, t } from "@/lang/i18n";
import type { LayoutCard } from "@/types/index";
import type { LayoutCard, QuickStartPackages } from "@/types";
import { DownloadOutlined } from "@ant-design/icons-vue";
import { quickInstallListAddr, createAsyncTask, queryAsyncTask } from "@/services/apis/instance";
import { reportErrorMsg } from "@/tools/validator";
import Loading from "@/components/Loading.vue";
import type { QuickStartTemplate } from "@/types";
import { useAppToolsStore } from "@/stores/useAppToolsStore";
import { useLayoutCardTools } from "@/hooks/useCardTools";
@ -47,7 +46,7 @@ const appList = computed(() => {
size: `${v.size}MB`
};
});
return list as unknown as QuickStartTemplate[];
return list as unknown as QuickStartPackages[];
}
// Check
if (!presetList.value?.packages || !presetList.value?.languages) {
@ -95,7 +94,7 @@ const searchForm = reactive({
const { state: newTaskInfo, execute: executeCreateAsyncTask } = createAsyncTask();
const handleSelectTemplate = async (item: QuickStartTemplate) => {
const handleSelectTemplate = async (item: QuickStartPackages) => {
try {
const instanceName = await openInputDialog(t("TXT_CODE_c237192c"));
await executeCreateAsyncTask({

View File

@ -482,13 +482,15 @@ router.post(
const presetUrl = systemConfig?.quickInstallAddr;
if (!presetUrl) throw new Error("Preset Addr is empty!");
const { data: presetConfig } = await axios<IQuickStartTemplate[]>({
const { data: presetConfig } = await axios<IQuickStartTemplate>({
url: presetUrl,
method: "GET"
});
if (!(presetConfig instanceof Array)) throw new Error("Preset Config is not array!");
const targetPresetConfig = presetConfig.find((v) => v.targetLink === targetUrl);
const packages = presetConfig.packages;
if (!(packages instanceof Array)) throw new Error("Preset Config is not array!");
const targetPresetConfig = packages.find((v) => v.targetLink === targetUrl);
if (!targetPresetConfig) throw new Error("Preset Config is not found!");
const remoteService = RemoteServiceSubsystem.getInstance(daemonId);