Add frontend support for script execution

This commit is contained in:
Sami Abuzakuk
2025-10-11 12:38:19 +02:00
parent 78b19a03a8
commit 6afc50eb81
3 changed files with 197 additions and 38 deletions

View File

@@ -20,6 +20,8 @@ export interface Log {
id: number;
script_id: number;
message: string;
error_message: string;
error_code: number;
created_at?: string;
}
export interface Script {
@@ -27,6 +29,7 @@ export interface Script {
name: string;
script_content?: string;
created_at?: string;
enabled: boolean;
}
// Fetch all scripts
@@ -39,7 +42,9 @@ export async function fetchScripts(): Promise<Script[]> {
}
// Add a new script
export async function addScript(script: Omit<Script, 'id' | 'created_at'>): Promise<Script> {
export async function addScript(
script: Omit<Script, 'id' | 'created_at' | 'enabled'>
): Promise<Script> {
const response = await fetch(`${API_URL}/script`, {
method: 'POST',
headers: {
@@ -87,13 +92,13 @@ export async function fetchLogs(scriptId: number): Promise<Log[]> {
}
// Add a new log to a specific script
export async function addLog(scriptId: number, message: string): Promise<Log> {
export async function addLog(scriptId: number, log: Log): Promise<Log> {
const response = await fetch(`${API_URL}/script/${scriptId}/log`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ message })
body: JSON.stringify(log)
});
if (!response.ok) {
throw new Error('Failed to add log');
@@ -101,6 +106,17 @@ export async function addLog(scriptId: number, message: string): Promise<Log> {
return response.json();
}
// Execute a script by ID
export async function executeScript(scriptId: number): Promise<{ message: string }> {
const response = await fetch(`${API_URL}/script/${scriptId}/execute`, {
method: 'POST'
});
if (!response.ok) {
throw new Error('Failed to execute script');
}
return response.json();
}
// Delete a log from a specific script
export async function deleteLog(scriptId: number, logId: number): Promise<void> {
const response = await fetch(`${API_URL}/script/${scriptId}/log/${logId}`, {