forked from mirror/MCSM-Daemon
Optimize: var name unified
This commit is contained in:
parent
524a7820e0
commit
e8de2af8c8
@ -300,13 +300,13 @@ routerApp.on("instance/asynchronous", (ctx, data) => {
|
||||
// Terminate the execution of complex asynchronous tasks
|
||||
routerApp.on("instance/stop_asynchronous", (ctx, data) => {
|
||||
const instanceUuid = data.instanceUuid;
|
||||
const { uid } = data.parameter;
|
||||
const { taskId } = data.parameter;
|
||||
const instance = InstanceSubsystem.getInstance(instanceUuid);
|
||||
|
||||
// Multi-instance async task
|
||||
if (uid && typeof uid === "string") {
|
||||
const task = TaskCenter.getTask(uid);
|
||||
if (!task) throw new Error(`Async Task ID: ${uid} does not exist`);
|
||||
if (taskId && typeof taskId === "string") {
|
||||
const task = TaskCenter.getTask(taskId);
|
||||
if (!task) throw new Error(`Async Task ID: ${taskId} does not exist`);
|
||||
task.stop();
|
||||
return;
|
||||
}
|
||||
@ -327,7 +327,7 @@ routerApp.on("instance/stop_asynchronous", (ctx, data) => {
|
||||
|
||||
// Query async task status
|
||||
routerApp.on("instance/query_asynchronous", (ctx, data) => {
|
||||
const taskId = String(data.taskId);
|
||||
const taskId = String(data.parameter.taskId);
|
||||
const task = TaskCenter.getTask(taskId);
|
||||
protocol.response(ctx, {
|
||||
taskId,
|
||||
|
@ -5,7 +5,8 @@ export interface IAsyncTaskJSON {
|
||||
}
|
||||
|
||||
export interface IAsyncTask extends EventEmitter {
|
||||
uid: string;
|
||||
// The taskId must be complex enough to prevent other users from accessing the information
|
||||
taskId: string;
|
||||
start(): Promise<boolean | void>;
|
||||
stop(): Promise<boolean | void>;
|
||||
status(): number;
|
||||
@ -22,16 +23,16 @@ export class TaskCenter {
|
||||
}
|
||||
|
||||
public static onTaskStopped(t: IAsyncTask) {
|
||||
console.log("Task:", t.uid, "Stopped");
|
||||
console.log("Task:", t.taskId, "Stopped");
|
||||
}
|
||||
|
||||
public static onTaskFailure(t: IAsyncTask) {
|
||||
console.log("Task:", t.uid, "Failed");
|
||||
console.log("Task:", t.taskId, "Failed");
|
||||
}
|
||||
|
||||
public static getTask(uid: string) {
|
||||
public static getTask(taskId: string) {
|
||||
for (const iterator of TaskCenter.tasks) {
|
||||
if (iterator.uid === uid) return iterator;
|
||||
if (iterator.taskId === taskId) return iterator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import { IAsyncTask, IAsyncTaskJSON, TaskCenter } from "./index";
|
||||
|
||||
export class QuickInstallTask extends EventEmitter implements IAsyncTask {
|
||||
private _status = 0; // 0=stop 1=running -1=error 2=downloading
|
||||
public uid: string;
|
||||
public taskId: string;
|
||||
private instance: Instance;
|
||||
private readonly TMP_ZIP_NAME = "tmp.zip";
|
||||
private zipPath = "";
|
||||
@ -27,7 +27,7 @@ export class QuickInstallTask extends EventEmitter implements IAsyncTask {
|
||||
config.stopCommand = "stop";
|
||||
config.type = Instance.TYPE_MINECRAFT_JAVA;
|
||||
this.instance = InstanceSubsystem.createInstance(config);
|
||||
this.uid = `QuickInstallTask-${this.instance.instanceUuid}-${v4()}`;
|
||||
this.taskId = `QuickInstallTask-${this.instance.instanceUuid}-${v4()}`;
|
||||
}
|
||||
|
||||
private download() {
|
||||
@ -82,7 +82,7 @@ export class QuickInstallTask extends EventEmitter implements IAsyncTask {
|
||||
toObject(): IAsyncTaskJSON {
|
||||
return JSON.parse(
|
||||
JSON.stringify({
|
||||
taskId: this.uid,
|
||||
taskId: this.taskId,
|
||||
status: this.status(),
|
||||
instanceUuid: this.instance.instanceUuid,
|
||||
instanceStatus: this.instance.status(),
|
||||
|
Loading…
Reference in New Issue
Block a user