mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 16:23:12 +09:00
Add plugin list to update modal
This commit is contained in:
13 files changed
+292
-173
No files matched your search
@@ -21,4 +21,5 @@ export * from "./messages_host";
|
||||
export * from "./messages_instance";
|
||||
export * from "./messages_mod";
|
||||
export * from "./messages_user";
|
||||
export * from "./messages_plugin";
|
||||
export * from "./version";
|
||||
@@ -19,6 +19,14 @@ export class ControllerRestartRequest {
|
||||
static permission = "core.controller.restart" as const;
|
||||
}
|
||||
|
||||
export class ControllerUpdateRequest {
|
||||
declare ["constructor"]: typeof ControllerUpdateRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = "controller" as const;
|
||||
static permission = "core.controller.update" as const;
|
||||
}
|
||||
|
||||
export class ControllerConfigGetRequest {
|
||||
declare ["constructor"]: typeof ControllerConfigGetRequest;
|
||||
static type = "request" as const;
|
||||
@@ -352,58 +360,6 @@ export class SystemInfoUpdateEvent {
|
||||
}
|
||||
}
|
||||
|
||||
export class RemoteUpdateRequest {
|
||||
declare ["constructor"]: typeof RemoteUpdateRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = ["controller", "host"] as const;
|
||||
static permission = "core.rce.remote_update";
|
||||
}
|
||||
|
||||
export class PluginUpdateRequest {
|
||||
declare ["constructor"]: typeof PluginUpdateRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = ["controller", "host"] as const;
|
||||
static permission = "core.rce.plugin_update";
|
||||
|
||||
constructor(
|
||||
public pluginPackage: string,
|
||||
) {}
|
||||
|
||||
static jsonSchema = Type.String();
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json);
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return this.pluginPackage;
|
||||
}
|
||||
}
|
||||
|
||||
export class PluginInstallRequest {
|
||||
declare ["constructor"]: typeof PluginInstallRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = ["controller", "host"] as const;
|
||||
static permission = "core.rce.plugin_install";
|
||||
|
||||
constructor(
|
||||
public pluginPackage: string,
|
||||
) {}
|
||||
|
||||
static jsonSchema = Type.String();
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json);
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return this.pluginPackage;
|
||||
}
|
||||
}
|
||||
|
||||
export class DebugDumpWsRequest {
|
||||
declare ["constructor"]: typeof DebugDumpWsRequest;
|
||||
static type = "request" as const;
|
||||
|
||||
@@ -19,6 +19,14 @@ export class HostRestartRequest {
|
||||
static permission = "core.host.restart" as const;
|
||||
}
|
||||
|
||||
export class HostUpdateRequest {
|
||||
declare ["constructor"]: typeof HostUpdateRequest;
|
||||
static type = "request" as const;
|
||||
static src = ["control", "controller"] as const;
|
||||
static dst = "host" as const;
|
||||
static permission = "core.host.update" as const;
|
||||
}
|
||||
|
||||
export class HostConfigGetRequest {
|
||||
declare ["constructor"]: typeof HostConfigGetRequest;
|
||||
static type = "request" as const;
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Type, Static } from "@sinclair/typebox";
|
||||
import { jsonArray } from "./composites";
|
||||
import { PluginNodeEnvInfo } from "../plugin";
|
||||
|
||||
/* This is similar to other plugin definitions but with lots removed */
|
||||
export class PluginDetails {
|
||||
constructor(
|
||||
public name: string,
|
||||
public title: string,
|
||||
public version: string,
|
||||
public description?: string,
|
||||
public npmPackage?: string,
|
||||
) {}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
name: Type.String(),
|
||||
title: Type.String(),
|
||||
version: Type.String(),
|
||||
description: Type.Optional(Type.String()),
|
||||
npmPackage: Type.Optional(Type.String()),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json.name, json.title, json.version, json.description, json.npmPackage);
|
||||
}
|
||||
|
||||
static fromNodeEnvInfo(pluginInfo: PluginNodeEnvInfo) {
|
||||
return new this(
|
||||
pluginInfo.name, pluginInfo.title,
|
||||
pluginInfo.version, pluginInfo.description,
|
||||
pluginInfo.npmPackage,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class PluginListRequest {
|
||||
declare ["constructor"]: typeof PluginListRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = ["controller", "host"] as const;
|
||||
static permission = "core.plugin.list";
|
||||
static Response = jsonArray(PluginDetails);
|
||||
}
|
||||
|
||||
export class PluginUpdateRequest {
|
||||
declare ["constructor"]: typeof PluginUpdateRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = ["controller", "host"] as const;
|
||||
static permission = "core.plugin.update";
|
||||
|
||||
constructor(
|
||||
public pluginPackage: string,
|
||||
) {}
|
||||
|
||||
static jsonSchema = Type.String();
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json);
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return this.pluginPackage;
|
||||
}
|
||||
}
|
||||
|
||||
export class PluginInstallRequest {
|
||||
declare ["constructor"]: typeof PluginInstallRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = ["controller", "host"] as const;
|
||||
static permission = "core.plugin.install";
|
||||
|
||||
constructor(
|
||||
public pluginPackage: string,
|
||||
) {}
|
||||
|
||||
static jsonSchema = Type.String();
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json);
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return this.pluginPackage;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import * as host from "../data/messages_host";
|
||||
import * as instance from "../data/messages_instance";
|
||||
import * as mod from "../data/messages_mod";
|
||||
import * as user from "../data/messages_user";
|
||||
import * as plugin from "../data/messages_plugin";
|
||||
import * as subscriptions from "../subscriptions";
|
||||
import type { RequestClass, EventClass } from "./link";
|
||||
|
||||
@@ -19,6 +20,7 @@ export const dataClasses: (RequestClass<unknown, unknown> | EventClass<unknown>)
|
||||
|
||||
controller.ControllerStopRequest,
|
||||
controller.ControllerRestartRequest,
|
||||
controller.ControllerUpdateRequest,
|
||||
controller.ControllerConfigGetRequest,
|
||||
controller.ControllerConfigSetFieldRequest,
|
||||
controller.ControllerConfigSetPropRequest,
|
||||
@@ -30,9 +32,6 @@ export const dataClasses: (RequestClass<unknown, unknown> | EventClass<unknown>)
|
||||
controller.LogMessageEvent,
|
||||
controller.SystemInfoRequest,
|
||||
controller.SystemInfoUpdateEvent,
|
||||
controller.RemoteUpdateRequest,
|
||||
controller.PluginUpdateRequest,
|
||||
controller.PluginInstallRequest,
|
||||
controller.DebugDumpWsRequest,
|
||||
controller.DebugWsMessageEvent,
|
||||
|
||||
@@ -40,6 +39,7 @@ export const dataClasses: (RequestClass<unknown, unknown> | EventClass<unknown>)
|
||||
|
||||
host.HostStopRequest,
|
||||
host.HostRestartRequest,
|
||||
host.HostUpdateRequest,
|
||||
host.HostConfigGetRequest,
|
||||
host.HostConfigSetFieldRequest,
|
||||
host.HostConfigSetPropRequest,
|
||||
@@ -125,4 +125,8 @@ export const dataClasses: (RequestClass<unknown, unknown> | EventClass<unknown>)
|
||||
user.UserUpdatesEvent,
|
||||
user.UserBulkImportRequest,
|
||||
user.UserBulkExportRequest,
|
||||
|
||||
plugin.PluginListRequest,
|
||||
plugin.PluginUpdateRequest,
|
||||
plugin.PluginInstallRequest,
|
||||
];
|
||||
@@ -131,6 +131,11 @@ definePermission({
|
||||
title: "Restart controller",
|
||||
description: "Restart the Node.js controller process if the system is set up for restarting.",
|
||||
});
|
||||
definePermission({
|
||||
name: "core.controller.update",
|
||||
title: "Update controller",
|
||||
description: "Remotely update the controller if the controller allows for remote updates.",
|
||||
});
|
||||
definePermission({
|
||||
name: "core.controller.get_config",
|
||||
title: "Get controller config",
|
||||
@@ -160,6 +165,11 @@ definePermission({
|
||||
title: "Restart Hosts",
|
||||
description: "Restart Node.js host processes if the system they run on are set up for restarting.",
|
||||
});
|
||||
definePermission({
|
||||
name: "core.host.update",
|
||||
title: "Update Hosts",
|
||||
description: "Remotely update a host if the host allows for remote updates.",
|
||||
});
|
||||
definePermission({
|
||||
name: "core.host.get_config",
|
||||
title: "Get host configs",
|
||||
@@ -526,19 +536,19 @@ definePermission({
|
||||
});
|
||||
|
||||
definePermission({
|
||||
name: "core.rce.remote_update",
|
||||
title: "Clusterio remote update",
|
||||
description: "Start a remote update of the clusterio packages",
|
||||
name: "core.plugin.list",
|
||||
title: "Lust plugins",
|
||||
description: "List all installed plugins on a machine.",
|
||||
});
|
||||
definePermission({
|
||||
name: "core.rce.plugin_update",
|
||||
title: "Plugin remote update",
|
||||
description: "Start a remote update of a third party plugin package",
|
||||
name: "core.plugin.update",
|
||||
title: "Update plugin",
|
||||
description: "Remotely update a plugin if the target allows remote updates of plugins.",
|
||||
});
|
||||
definePermission({
|
||||
name: "core.rce.plugin_install",
|
||||
title: "Plugin remote install",
|
||||
description: "Start a remote install of a third party plugin package",
|
||||
name: "core.plugin.install",
|
||||
title: "Install plugin",
|
||||
description: "Remotely install a plugin if the target allows remote installs of plugins.",
|
||||
});
|
||||
|
||||
definePermission({
|
||||
|
||||
@@ -2,6 +2,8 @@ import util from "util";
|
||||
import path from "path";
|
||||
import { exec } from "child_process";
|
||||
import { logger } from "./logging";
|
||||
import { RequestError } from "./errors";
|
||||
import { PluginNodeEnvInfo } from "./plugin";
|
||||
const execAsync = util.promisify(exec);
|
||||
|
||||
async function isDev() {
|
||||
@@ -24,3 +26,29 @@ export async function updatePackage(name: string) {
|
||||
export async function installPackage(name: string) {
|
||||
return logExec(`npm install --save ${name}`);
|
||||
}
|
||||
|
||||
export async function handlePluginUpdate(pluginName: string, pluginInfos: PluginNodeEnvInfo[]) {
|
||||
if (!pluginInfos.some(plugin => plugin.npmPackage === pluginName)) {
|
||||
throw new RequestError(`Plugin ${pluginName} is not installed on this machine`);
|
||||
}
|
||||
|
||||
return await updatePackage(pluginName);
|
||||
}
|
||||
|
||||
export async function handlePluginInstall(pluginName: string) {
|
||||
if (pluginName.length > 214 || /[^a-zA-z0-9\-_.+@\/]/.test(pluginName)) {
|
||||
// https://docs.npmjs.com/cli/v11/configuring-npm/package-json#name
|
||||
// https://www.npmjs.com/package/validate-npm-package-name
|
||||
throw new RequestError(`Invalid plugin name: ${pluginName}`);
|
||||
}
|
||||
|
||||
const packageName = encodeURI(pluginName);
|
||||
const npmRequest = await fetch(`https://registry.npmjs.com/${packageName}`, {
|
||||
method: "HEAD",
|
||||
});
|
||||
if (!npmRequest.ok) {
|
||||
throw new RequestError(`Unknown plugin: ${packageName}`);
|
||||
}
|
||||
|
||||
return await installPackage(packageName);
|
||||
}
|
||||
Reference in new issue
Block a user