generated from fahricansecer/boilerplate-be
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
const axios = require('axios');
|
|
const http = require('http');
|
|
|
|
async function test() {
|
|
console.log('Sending POST /generate...');
|
|
const res = await axios.post('http://localhost:17493/generate', {
|
|
profile_id: 'b8d26247-c8bc-4c06-9364-5b09d11de4bf',
|
|
text: 'Hello world again',
|
|
language: 'en',
|
|
engine: 'kokoro'
|
|
});
|
|
const genId = res.data.id;
|
|
console.log('Generation ID:', genId);
|
|
|
|
console.log('Polling status...');
|
|
return new Promise((resolve, reject) => {
|
|
http.get(`http://localhost:17493/generate/${genId}/status`, (response) => {
|
|
response.on('data', (chunk) => {
|
|
const lines = chunk.toString().split('\n');
|
|
for (const line of lines) {
|
|
if (line.startsWith('data: ')) {
|
|
const data = JSON.parse(line.substring(6));
|
|
console.log('Status update:', data);
|
|
if (data.status === 'completed') {
|
|
console.log('Finished!');
|
|
resolve(data);
|
|
} else if (data.status === 'failed') {
|
|
console.log('Failed:', data.error);
|
|
reject(new Error(data.error));
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}
|
|
test().catch(console.error);
|