Password promt
This commit is contained in:
120
frontend/src/services/taskService.js
Normal file
120
frontend/src/services/taskService.js
Normal file
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* Service for interacting with the Task Management API.
|
||||
*/
|
||||
|
||||
const API_BASE = '/api/tasks';
|
||||
|
||||
/**
|
||||
* Fetch a list of tasks with pagination and optional status filter.
|
||||
* @param {number} limit - Maximum number of tasks to return.
|
||||
* @param {number} offset - Number of tasks to skip.
|
||||
* @param {string|null} status - Filter by task status (optional).
|
||||
* @returns {Promise<Array>} List of tasks.
|
||||
*/
|
||||
export async function getTasks(limit = 10, offset = 0, status = null) {
|
||||
const params = new URLSearchParams({
|
||||
limit: limit.toString(),
|
||||
offset: offset.toString()
|
||||
});
|
||||
if (status) {
|
||||
params.append('status', status);
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE}?${params.toString()}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch tasks: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch details for a specific task.
|
||||
* @param {string} taskId - The ID of the task.
|
||||
* @returns {Promise<Object>} Task details.
|
||||
*/
|
||||
export async function getTask(taskId) {
|
||||
const response = await fetch(`${API_BASE}/${taskId}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch task ${taskId}: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch logs for a specific task.
|
||||
* @param {string} taskId - The ID of the task.
|
||||
* @returns {Promise<Array>} List of log entries.
|
||||
*/
|
||||
export async function getTaskLogs(taskId) {
|
||||
// Currently, logs are included in the task object, but we might have a separate endpoint later.
|
||||
// For now, we fetch the task and return its logs.
|
||||
// Or if we implement T017 (GET /api/tasks/{task_id}/logs), we would use that.
|
||||
// The current backend implementation in tasks.py does NOT have a separate /logs endpoint yet.
|
||||
// T017 is in Phase 3.
|
||||
// So for now, we'll fetch the task.
|
||||
const task = await getTask(taskId);
|
||||
return task.logs || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resume a task that is awaiting input (e.g., passwords).
|
||||
* @param {string} taskId - The ID of the task.
|
||||
* @param {Object} passwords - Map of database names to passwords.
|
||||
* @returns {Promise<Object>} Updated task object.
|
||||
*/
|
||||
export async function resumeTask(taskId, passwords) {
|
||||
const response = await fetch(`${API_BASE}/${taskId}/resume`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ passwords })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(errorData.detail || `Failed to resume task: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a task that is awaiting mapping.
|
||||
* @param {string} taskId - The ID of the task.
|
||||
* @param {Object} resolutionParams - Resolution parameters.
|
||||
* @returns {Promise<Object>} Updated task object.
|
||||
*/
|
||||
export async function resolveTask(taskId, resolutionParams) {
|
||||
const response = await fetch(`${API_BASE}/${taskId}/resolve`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ resolution_params: resolutionParams })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(errorData.detail || `Failed to resolve task: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear tasks based on status.
|
||||
* @param {string|null} status - Filter by task status (optional).
|
||||
*/
|
||||
export async function clearTasks(status = null) {
|
||||
const params = new URLSearchParams();
|
||||
if (status) {
|
||||
params.append('status', status);
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE}?${params.toString()}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to clear tasks: ${response.statusText}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user