File size: 1,786 Bytes
c6db453 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | // 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(); |