feat: background tasks manager and book sentence mining for CEFR tests
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user