Basic functionality of remote npm

This commit is contained in:
Cooldude2606 committed 2025-04-29 01:40:22 +01:00
1 parent 47c5e0fabd
commit ff35b5c378
13 files changed
+496

No files matched your search

+31
View File
@@ -392,6 +392,9 @@ export default class Host extends lib.Link {
this.handle(lib.InstancePullSaveRequest, this.handleInstancePullSaveRequest.bind(this));
this.handle(lib.InstancePushSaveRequest, this.handleInstancePushSaveRequest.bind(this));
this.handle(lib.InstanceDeleteInternalRequest, this.handleInstanceDeleteInternalRequest.bind(this));
this.handle(lib.RemoteUpdateRequest, this.handleRemoteUpdateRequest.bind(this));
this.handle(lib.PluginUpdateRequest, this.handlePluginUpdateRequest.bind(this));
this.handle(lib.PluginInstallRequest, this.handlePluginInstallRequest.bind(this));
}
async loadPlugins() {
@@ -1043,6 +1046,34 @@ export default class Host extends lib.Link {
await fs.remove(instanceInfo.path);
}
async handleRemoteUpdateRequest(request: lib.RemoteUpdateRequest) {
if (!this.config.get("host.allow_remote_updates")) {
throw new lib.RequestError("Remote updates are disabled on this machine");
}
return lib.updatePackage("@clusterio/host");
}
async handlePluginUpdateRequest(request: lib.PluginUpdateRequest) {
if (!this.config.get("host.allow_plugin_updates")) {
throw new lib.RequestError("Plugin updates are disabled on this machine");
}
if (!this.pluginInfos.some(plugin => plugin.npmPackage === request.pluginPackage)) {
throw new lib.RequestError(`Plugin ${request.pluginPackage} is not installed on this machine`);
}
return lib.updatePackage(request.pluginPackage);
}
async handlePluginInstallRequest(request: lib.PluginInstallRequest) {
if (!this.config.get("host.allow_plugin_install")) {
throw new lib.RequestError("Plugin installs are disabled on this machine");
}
const npmRequest = await fetch(`https://www.npmjs.com/package/${encodeURI(request.pluginPackage)}`);
if (!npmRequest.ok) {
throw new lib.RequestError(`Unknown plugin: ${request.pluginPackage}`);
}
return lib.installPackage(request.pluginPackage);
}
sendHostUpdate() {
this.send(
new lib.HostInfoUpdateEvent(