mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 22:25:24 +00:00
feat: move snippets, keybinding actions and macros out of core into plugins
This commit is contained in:
1 parent
d9bba10612
commit
e0c30a4e6f
262 files changed
+9091
-10744
No files matched your search
@@ -22,7 +22,10 @@ import {
|
||||
import { ADMIN_KEYS } from "./settings.js";
|
||||
import { commandHistory } from "./tables.js";
|
||||
import { createTerminalSocket } from "./terminal-socket.js";
|
||||
import { validateAdminSettings } from "./settings-validation.js";
|
||||
import {
|
||||
validateAdminSettings,
|
||||
validateUserSettings,
|
||||
} from "./settings-validation.js";
|
||||
|
||||
function toInfo(session: TerminalSession): LiveSessionInfo {
|
||||
return {
|
||||
@@ -57,6 +60,7 @@ function optionalService<T extends object>(
|
||||
export async function activate(ctx: PluginContext) {
|
||||
const log = createTerminalLogger(ctx.log);
|
||||
ctx.settings.onValidate("admin", validateAdminSettings);
|
||||
ctx.settings.onValidate("user", validateUserSettings);
|
||||
|
||||
const table = await ctx.db.define(commandHistory);
|
||||
const history = createHistoryRepository(ctx.db, table);
|
||||
|
||||
@@ -30,3 +30,38 @@ export function validateAdminSettings(
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
const MAX_MACROS = 100;
|
||||
const MAX_MACROS_BYTES = 512 * 1024;
|
||||
|
||||
/** Save-time checks for the user settings: macros stay bounded. */
|
||||
export function validateUserSettings(
|
||||
values: Record<string, unknown>,
|
||||
): Record<string, string> {
|
||||
const errors: Record<string, string> = {};
|
||||
if (values.macros === undefined || values.macros === null) return errors;
|
||||
let macros = values.macros;
|
||||
if (typeof macros === "string") {
|
||||
try {
|
||||
macros = JSON.parse(macros);
|
||||
} catch {
|
||||
macros = null;
|
||||
}
|
||||
}
|
||||
const valid =
|
||||
Array.isArray(macros) &&
|
||||
macros.length <= MAX_MACROS &&
|
||||
JSON.stringify(macros).length <= MAX_MACROS_BYTES &&
|
||||
macros.every(
|
||||
(macro) =>
|
||||
!!macro &&
|
||||
typeof macro === "object" &&
|
||||
typeof (macro as { id?: unknown }).id === "string" &&
|
||||
typeof (macro as { name?: unknown }).name === "string" &&
|
||||
Array.isArray((macro as { steps?: unknown }).steps),
|
||||
);
|
||||
if (!valid) {
|
||||
errors.macros = `Macros must be a list of at most ${MAX_MACROS} valid macros`;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
Reference in new issue
Block a user