diff --git a/common/global.d.ts b/common/global.d.ts index dda897d0..19cd30ae 100644 --- a/common/global.d.ts +++ b/common/global.d.ts @@ -206,7 +206,7 @@ export interface IQuickStartPackages { size: string; hardware: string; remark: string; - targetLink: string; + targetLink?: string; author: string; setupInfo?: IJsonData; } diff --git a/daemon/src/entity/instance/instance.ts b/daemon/src/entity/instance/instance.ts index db71f1fe..44050203 100755 --- a/daemon/src/entity/instance/instance.ts +++ b/daemon/src/entity/instance/instance.ts @@ -106,7 +106,7 @@ export default class Instance extends EventEmitter { } if (cfg?.processType && cfg?.processType !== this.config.processType) { - if (this.status() != Instance.STATUS_STOP) + if (this.status() !== Instance.STATUS_STOP && this.status() !== Instance.STATUS_BUSY) throw new Error($t("TXT_CODE_instanceConf.cantModifyProcessType")); configureEntityParams(this.config, cfg, "processType", String); this.forceExec(new FunctionDispatcher()); diff --git a/daemon/src/routers/Instance_router.ts b/daemon/src/routers/Instance_router.ts index d5e54450..6d28caa0 100755 --- a/daemon/src/routers/Instance_router.ts +++ b/daemon/src/routers/Instance_router.ts @@ -482,7 +482,7 @@ routerApp.on("instance/outputlog", async (ctx, data) => { return protocol.response(ctx, text); } protocol.responseError(ctx, new Error($t("TXT_CODE_Instance_router.terminalLogNotExist")), { - notPrintErr: true + disablePrint: true }); } catch (err: any) { protocol.responseError(ctx, err); diff --git a/daemon/src/routers/auth_router.ts b/daemon/src/routers/auth_router.ts index b5fcfe27..caa7b25b 100755 --- a/daemon/src/routers/auth_router.ts +++ b/daemon/src/routers/auth_router.ts @@ -33,7 +33,9 @@ routerApp.use(async (event, ctx, _, next) => { event: event }) ); - return protocol.error(ctx, "error", IGNORE); + return protocol.error(ctx, "error", IGNORE, { + disablePrint: true + }); }); // authentication controller diff --git a/daemon/src/routers/stream_router.ts b/daemon/src/routers/stream_router.ts index 6428a264..9047b9d5 100755 --- a/daemon/src/routers/stream_router.ts +++ b/daemon/src/routers/stream_router.ts @@ -24,7 +24,9 @@ routerApp.use(async (event, ctx, data, next) => { ) { return await next(); } - return protocol.error(ctx, "error", IGNORE); + return protocol.error(ctx, "error", IGNORE, { + disablePrint: true + }); } return await next(); }); @@ -48,7 +50,7 @@ routerApp.on("stream/auth", (ctx, data) => { protocol.response(ctx, true); } catch (error: any) { protocol.responseError(ctx, error, { - notPrintErr: true + disablePrint: true }); } }); diff --git a/daemon/src/service/async_task_service/quick_install.ts b/daemon/src/service/async_task_service/quick_install.ts index bee06d24..2e1d166c 100644 --- a/daemon/src/service/async_task_service/quick_install.ts +++ b/daemon/src/service/async_task_service/quick_install.ts @@ -27,20 +27,21 @@ export class QuickInstallTask extends AsyncTask { constructor( public instanceName: string, - public targetLink: string, + public targetLink?: string, public buildParams?: Partial, curInstance?: Instance ) { super(); const config = new InstanceConfig(); config.nickname = instanceName; - config.cwd = ""; config.stopCommand = "^c"; - config.type = Instance.TYPE_MINECRAFT_JAVA; if (!curInstance) { + config.cwd = ""; this.instance = InstanceSubsystem.createInstance(config); } else { this.instance = curInstance; + config.cwd = this.instance.config.cwd; + this.instance.config = config; } this.taskId = `${QuickInstallTask.TYPE}-${this.instance.instanceUuid}-${v4()}`; this.type = QuickInstallTask.TYPE; @@ -49,6 +50,7 @@ export class QuickInstallTask extends AsyncTask { private download(): Promise { return new Promise(async (resolve, reject) => { try { + if (!this.targetLink) reject(new Error("No targetLink!")); this.zipPath = path.normalize(path.join(this.instance.config.cwd, this.TMP_ZIP_NAME)); const writeStream = fs.createWriteStream(this.zipPath); const response = await axios({ @@ -75,13 +77,15 @@ export class QuickInstallTask extends AsyncTask { async onStarted() { const fileManager = getFileManager(this.instance.instanceUuid); try { - let result = await this.download(); - result = await fileManager.unzip(this.TMP_ZIP_NAME, ".", "UTF-8"); - if (!result) throw new Error($t("TXT_CODE_quick_install.unzipError")); + if (this.targetLink) { + let result = await this.download(); + result = await fileManager.unzip(this.TMP_ZIP_NAME, ".", "UTF-8"); + if (!result) throw new Error($t("TXT_CODE_quick_install.unzipError")); + } let config: Partial; - if (this.buildParams?.startCommand) { - config = this.buildParams; + if (this.buildParams?.startCommand || !fs.existsSync(this.ZIP_CONFIG_JSON)) { + config = this.buildParams || {}; } else { config = JSON.parse(await fileManager.readFile(this.ZIP_CONFIG_JSON)); } @@ -135,11 +139,11 @@ export class QuickInstallTask extends AsyncTask { } export function createQuickInstallTask( - targetLink: string, - instanceName: string, + targetLink?: string, + instanceName?: string, buildParams?: any ) { - if (!targetLink || !instanceName) throw new Error("targetLink or instanceName is null!"); + if (!instanceName) throw new Error("Instance name is empty!"); const task = new QuickInstallTask(instanceName, targetLink, buildParams); TaskCenter.addTask(task); return task; diff --git a/daemon/src/service/protocol.ts b/daemon/src/service/protocol.ts index 37429c3e..27ee6c5a 100755 --- a/daemon/src/service/protocol.ts +++ b/daemon/src/service/protocol.ts @@ -18,7 +18,7 @@ export interface IPacket { } export interface IResponseErrorConfig { - notPrintErr: boolean; + disablePrint: boolean; } // global socket storage @@ -50,9 +50,8 @@ export function responseError( else errinfo = err; const packet = new Packet(ctx.uuid, STATUS_ERR, ctx.event, errinfo); // Ignore - if (err.toString().includes(IGNORE) && ctx.event) return ctx.socket.emit(ctx.event, packet); - - if (!config?.notPrintErr) + if (String(err).includes(IGNORE) && ctx.event) return ctx.socket.emit(ctx.event, packet); + if (!config?.disablePrint) logger.warn( $t("TXT_CODE_protocol.socketErr", { id: ctx.socket.id, @@ -69,19 +68,20 @@ export function msg(ctx: RouterContext, event: string, data: any) { ctx.socket.emit(event, packet); } -export function error(ctx: RouterContext, event: string, err: any) { +export function error(ctx: RouterContext, event: string, err: any, config?: IResponseErrorConfig) { const packet = new Packet(ctx.uuid, STATUS_ERR, event, err); // Ignore - if (err.toString().includes(IGNORE) && ctx.event) return ctx.socket.emit(ctx.event, packet); + if (String(err).includes(IGNORE) && ctx.event) return ctx.socket.emit(ctx.event, packet); + if (!config?.disablePrint) + logger.warn( + $t("TXT_CODE_protocol.socketErr", { + id: ctx.socket.id, + address: ctx.socket.handshake.address, + event: ctx.event + }), + err + ); - logger.warn( - $t("TXT_CODE_protocol.socketErr", { - id: ctx.socket.id, - address: ctx.socket.handshake.address, - event: ctx.event - }), - err - ); ctx.socket.emit(event, packet); } diff --git a/frontend/src/services/apis/instance.ts b/frontend/src/services/apis/instance.ts index e9e5d130..fb8e4c23 100644 --- a/frontend/src/services/apis/instance.ts +++ b/frontend/src/services/apis/instance.ts @@ -245,7 +245,7 @@ export const createAsyncTask = useDefineApi< data: { time: number; newInstanceName: string; - targetLink: string; + targetLink?: string; setupInfo?: JsonData; }; }, @@ -441,7 +441,9 @@ export const reinstallInstance = useDefineApi< uuid: string; }; data: { - targetUrl: string; + targetUrl?: string; + title: string; + description: string; }; }, boolean diff --git a/frontend/src/widgets/instance/Terminal.vue b/frontend/src/widgets/instance/Terminal.vue index 5ff92242..8c58904c 100644 --- a/frontend/src/widgets/instance/Terminal.vue +++ b/frontend/src/widgets/instance/Terminal.vue @@ -51,17 +51,10 @@ const updateCmd = computed(() => (instanceInfo.value?.config.updateCommand ? tru const instanceStatusText = computed(() => INSTANCE_STATUS[instanceInfo.value?.status ?? -1]); const quickOperations = computed(() => arrayFilter([ - { - title: t("TXT_CODE_b19ed1dd"), - icon: InteractionOutlined, - type: "danger", - click: () => reinstallDialog.value?.openDialog(), - props: {}, - condition: () => isStopped.value - }, { title: t("TXT_CODE_57245e94"), icon: PlayCircleOutlined, + noConfirm: false, type: "default", click: async () => { try { @@ -108,6 +101,7 @@ const instanceOperations = computed(() => title: t("TXT_CODE_47dcfa5"), icon: RedoOutlined, type: "default", + noConfirm: false, click: async () => { try { await restartInstance().execute({ @@ -161,6 +155,14 @@ const instanceOperations = computed(() => } }, condition: () => isStopped.value && updateCmd.value + }, + { + title: t("TXT_CODE_b19ed1dd"), + icon: InteractionOutlined, + noConfirm: true, + click: () => reinstallDialog.value?.openDialog(), + props: {}, + condition: () => isStopped.value } ]) ); @@ -228,17 +230,28 @@ onMounted(async () => { diff --git a/frontend/src/widgets/setupApp/AppPackages.vue b/frontend/src/widgets/setupApp/AppPackages.vue index 699db110..9de6df06 100644 --- a/frontend/src/widgets/setupApp/AppPackages.vue +++ b/frontend/src/widgets/setupApp/AppPackages.vue @@ -127,7 +127,7 @@ onMounted(() => {