feat: background tasks manager and book sentence mining for CEFR tests

This commit is contained in:
2026-10-06 16:36:39 +03:00
parent 332286b641
commit c9da5bd351
11 changed files with 1377 additions and 16 deletions
+36
View File
@@ -316,5 +316,41 @@ export const api = {
if (resp.ok) return await resp.json();
throw new Error(`Failed to update handwritten status: ${resp.status}`);
}
},
// Background Tasks & Sentence Mining
tasks: {
async mineBooks(bookId = null, level = 'A1', count = 15) {
const resp = await fetch('/api/tasks/mine-books', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
book_id: bookId,
level: level,
count: count
})
});
if (resp.ok) return await resp.json();
throw new Error(`Failed to start mining task: ${resp.status}`);
},
async getActive(taskType = null) {
let url = '/api/tasks/active';
if (taskType) url += `?task_type=${encodeURIComponent(taskType)}`;
const resp = await fetch(url);
if (resp.ok) return await resp.json();
throw new Error(`Failed to get active task: ${resp.status}`);
},
async getStatus(taskId) {
const resp = await fetch(`/api/tasks/${taskId}`);
if (resp.ok) return await resp.json();
throw new Error(`Failed to get task status: ${resp.status}`);
},
async cancel(taskId) {
const resp = await fetch(`/api/tasks/${taskId}/cancel`, {
method: 'POST'
});
if (resp.ok) return await resp.json();
throw new Error(`Failed to cancel task: ${resp.status}`);
}
}
};