mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 22:25:24 +00:00
feat: move desktop, status, import, audit and branding features into plugins
This commit is contained in:
1 parent
9d93fb0893
commit
1cdbfc674c
166 files changed
+21298
-12041
No files matched your search
@@ -200,6 +200,38 @@ export async function remoteFetch(
|
||||
return response;
|
||||
}
|
||||
|
||||
export interface RemoteStreamRequest {
|
||||
method?: string;
|
||||
headers?: Record<string, string>;
|
||||
/** A string, a buffer or a Node stream. */
|
||||
body?: unknown;
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request with the link's proxy headers and certificate rules and a
|
||||
* body that may be a stream. The response body is left unread for the caller.
|
||||
*/
|
||||
export async function remoteStreamFetch(
|
||||
target: RemoteTarget,
|
||||
pathname: string,
|
||||
request: RemoteStreamRequest = {},
|
||||
) {
|
||||
const headers = { ...request.headers, ...requestHeaders(target) };
|
||||
try {
|
||||
return await undiciFetch(remoteUrl(target.serverUrl, pathname), {
|
||||
method: request.method ?? "GET",
|
||||
headers,
|
||||
body: request.body as never,
|
||||
duplex: "half",
|
||||
dispatcher: dispatcherFor(target),
|
||||
signal: request.signal,
|
||||
} as never);
|
||||
} catch (error) {
|
||||
throw describeNetworkError(error);
|
||||
}
|
||||
}
|
||||
|
||||
/** Sends a request and parses a JSON answer from Termix. */
|
||||
export async function remoteJson<T>(
|
||||
target: RemoteTarget,
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import semver from "semver";
|
||||
import type { PluginDesktopMode } from "@termix-ssh/plugin-sdk/manifest";
|
||||
import {
|
||||
resolvePluginDesktopMode,
|
||||
type PluginDesktopMode,
|
||||
} from "@termix-ssh/plugin-sdk/manifest";
|
||||
import { syncLogger } from "../../utils/logger.js";
|
||||
import { sendCoreAlert } from "../../notify/core-notify.js";
|
||||
import {
|
||||
@@ -227,7 +230,9 @@ async function mirrorOne(link: SyncLink, plugin: RemotePlugin): Promise<void> {
|
||||
}
|
||||
const { loader } = getPluginRuntime();
|
||||
let local = loader.get(plugin.id);
|
||||
const mode = local?.manifest.desktop ?? plugin.desktop ?? "mirror";
|
||||
const mode = local
|
||||
? resolvePluginDesktopMode(local.manifest)
|
||||
: (plugin.desktop ?? "mirror");
|
||||
|
||||
if (mode === "server") {
|
||||
if (local && (await isEnabledLocally(plugin.id))) {
|
||||
@@ -328,7 +333,7 @@ export async function mirrorPlugins(link: SyncLink): Promise<void> {
|
||||
// A plugin the server no longer has is switched off here. Its data stays.
|
||||
for (const local of getPluginRuntime().loader.list()) {
|
||||
if (remoteIds.has(local.id) || local.source !== "user") continue;
|
||||
if ((local.manifest.desktop ?? "mirror") !== "mirror") continue;
|
||||
if (resolvePluginDesktopMode(local.manifest) !== "mirror") continue;
|
||||
if (await isEnabledLocally(local.id)) {
|
||||
await setPluginEnabled(local.id, false).catch(() => {});
|
||||
}
|
||||
@@ -341,7 +346,7 @@ export async function mirrorPlugins(link: SyncLink): Promise<void> {
|
||||
*/
|
||||
export function isServerManaged(pluginId: string): boolean {
|
||||
const local = getPluginRuntime().loader.get(pluginId);
|
||||
const mode = local?.manifest.desktop ?? "mirror";
|
||||
const mode = local ? resolvePluginDesktopMode(local.manifest) : "mirror";
|
||||
if (mode !== "mirror") return mode === "server";
|
||||
return local?.source !== "user" || vouchedHere(local);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { syncLogger } from "../../utils/logger.js";
|
||||
import { getLocalVersion } from "../../utils/app-version.js";
|
||||
import { getEntity, listEntities } from "../../plugins/sync-registry.js";
|
||||
import { getPluginRuntime } from "../../plugins/index.js";
|
||||
import { resolvePluginDesktopMode } from "@termix-ssh/plugin-sdk/manifest";
|
||||
import {
|
||||
createCurrentSessionRepository,
|
||||
createCurrentSettingsRepository,
|
||||
@@ -447,13 +448,13 @@ router.get(
|
||||
async (req: Request, res: Response) => {
|
||||
const userId = userOf(req);
|
||||
try {
|
||||
const { hostStatusService } =
|
||||
await import("../../hosts/status/host-status-service.js");
|
||||
const { hostStatus } =
|
||||
await import("../../plugins/host-status-provider.js");
|
||||
const { PermissionManager } =
|
||||
await import("../../utils/permission-manager.js");
|
||||
const { createCurrentHostRepository } =
|
||||
await import("../../database/repositories/factory.js");
|
||||
const statuses = await hostStatusService.statusesFor(userId, null);
|
||||
const statuses = await hostStatus.statusesFor(userId, null);
|
||||
const entries = [...statuses.entries()];
|
||||
const allowed =
|
||||
await PermissionManager.getInstance().filterAccessibleHostIds(
|
||||
@@ -516,7 +517,7 @@ router.get(
|
||||
artifact: !!plugin.artifact,
|
||||
enabled: records.get(plugin.id)?.state === "enabled",
|
||||
active: plugin.state === "active",
|
||||
desktop: plugin.manifest.desktop ?? "mirror",
|
||||
desktop: resolvePluginDesktopMode(plugin.manifest),
|
||||
syncEntities: plugin.manifest.contributes?.syncEntities ?? [],
|
||||
granted: (await grants.listByPlugin(plugin.id)).map(
|
||||
(grant) => grant.capability,
|
||||
|
||||
Reference in new issue
Block a user