Depassage's picture
### 1. ABSTRACT
c6db453 verified
Raw
History Blame Contribute Delete
1.79 kB
// Mock API service for demonstration
class BatchService {
constructor() {
this.batches = [];
this.nextId = 1;
}
createBatch(type, file) {
return new Promise((resolve) => {
const newBatch = {
id: this.nextId++,
type,
status: 'PENDING',
fileName: file.name,
createdAt: new Date().toISOString()
};
this.batches.unshift(newBatch);
// Simulate async processing
setTimeout(() => {
newBatch.status = 'RUNNING';
setTimeout(() => {
newBatch.status = 'COMPLETED';
}, 2000);
}, 1000);
resolve(newBatch);
});
}
getAllBatches() {
return new Promise((resolve) => {
resolve([...this.batches]);
});
}
downloadResult(batchId) {
return new Promise((resolve) => {
// Simulate file download
const batch = this.batches.find(b => b.id === batchId);
if (batch) {
const blob = new Blob([`Processed ${batch.type} results for ${batch.fileName}`], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `processed_${batch.fileName.replace('.csv', '')}_${batchId}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
resolve();
});
}
}
// Initialize service
window.batchService = new BatchService();