Merge pull request 'feat(scripts): כפתור "הרץ" מ-UI לסקריפטי read-only (קטגוריה B #4)' (#283) from worktree-scripts-run-ui into main
This commit was merged in pull request #283.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { apiRequest } from "./client";
|
||||
|
||||
// ── Scripts catalog ───────────────────────────────────────────────
|
||||
@@ -11,8 +12,32 @@ export type ScriptsCatalog = {
|
||||
bytes: number;
|
||||
last_modified: number;
|
||||
gitea_url: string;
|
||||
// #4 — basenames the UI may offer a "הרץ" button for (read-only allowlist,
|
||||
// enforced host-side). Optional so an older backend (pre-deploy) degrades to
|
||||
// "מקור"-only with no run buttons.
|
||||
runnable_scripts?: string[];
|
||||
};
|
||||
|
||||
export function fetchScriptsCatalog(signal?: AbortSignal) {
|
||||
return apiRequest<ScriptsCatalog>("/api/scripts/catalog", { signal });
|
||||
}
|
||||
|
||||
// ── Run a read-only script (#4) ───────────────────────────────────
|
||||
// Proxies to the court-fetch host bridge; only allowlisted read-only scripts
|
||||
// run, with a fixed safe argv. Exit code + captured output are relayed verbatim.
|
||||
export type ScriptRunResult = {
|
||||
ok: boolean;
|
||||
exit_code: number;
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
};
|
||||
|
||||
export function useRunScript() {
|
||||
return useMutation({
|
||||
mutationFn: (name: string) =>
|
||||
apiRequest<ScriptRunResult>(
|
||||
`/api/scripts/${encodeURIComponent(name)}/run`,
|
||||
{ method: "POST" },
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user