mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 22:55:24 +00:00
feat: finish the ai plugin (B18)
This commit is contained in:
1 parent
6b4d1432ab
commit
21937a6b02
193 files changed
+23429
-4244
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
createCurrentHostRepository,
|
||||
createCurrentHostResolutionRepository,
|
||||
createCurrentRbacAccessRepository,
|
||||
createCurrentRecentActivityRepository,
|
||||
createCurrentSshCredentialUsageRepository,
|
||||
createCurrentSyncTombstoneRepository,
|
||||
} from "../database/repositories/factory.js";
|
||||
import { pluginEvents, TOPICS } from "../plugins/events.js";
|
||||
import { sshLogger } from "../utils/logger.js";
|
||||
import { emitInternalEvent } from "./internal-events.js";
|
||||
|
||||
export interface DeletedHost {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a host the user owns, with everything that hangs off it. Shared by
|
||||
* the host editor's delete route and ctx.hosts.delete, so a plugin deleting a
|
||||
* host leaves exactly what a person deleting it would. Null when the host
|
||||
* does not exist or is not the user's.
|
||||
*/
|
||||
export async function deleteOwnedHost(
|
||||
userId: string,
|
||||
hostId: number,
|
||||
): Promise<DeletedHost | null> {
|
||||
const host =
|
||||
await createCurrentHostResolutionRepository().findHostByIdForUser(
|
||||
hostId,
|
||||
userId,
|
||||
);
|
||||
if (!host) return null;
|
||||
|
||||
// file manager recent/pinned/shortcuts, transfer_recent, command history
|
||||
// and session recordings cascade on the host's refHost() foreign key, as
|
||||
// the file-manager, ssh-terminal and session-recording plugins' adopted
|
||||
// tables.
|
||||
await createCurrentSshCredentialUsageRepository().deleteByHostId(hostId);
|
||||
await createCurrentRecentActivityRepository().deleteByHostId(hostId);
|
||||
await createCurrentRbacAccessRepository().deleteHostAccessForHost(hostId);
|
||||
await createCurrentHostRepository().deleteForUser(userId, hostId);
|
||||
|
||||
if (host.syncId) {
|
||||
await createCurrentSyncTombstoneRepository().record(
|
||||
userId,
|
||||
"hosts",
|
||||
host.syncId,
|
||||
);
|
||||
}
|
||||
|
||||
const name = host.name ?? host.ip;
|
||||
emitInternalEvent("host_deleted", userId, hostId, { name });
|
||||
|
||||
try {
|
||||
pluginEvents.emit(TOPICS.hostDeleted, { hostId, userId });
|
||||
} catch (err) {
|
||||
sshLogger.warn("Failed to publish host deletion event", {
|
||||
operation: "host_delete",
|
||||
hostId,
|
||||
error: err instanceof Error ? err.message : String(err),
|
||||
});
|
||||
}
|
||||
|
||||
return { id: hostId, name };
|
||||
}
|
||||
Reference in new issue
Block a user