?
This commit is contained in:
parent
e2d12044fd
commit
9c89eeb22f
@ -28,6 +28,8 @@ async function readResponse(response) {
|
|||||||
try {
|
try {
|
||||||
function read() {
|
function read() {
|
||||||
let finishedResponse = '';
|
let finishedResponse = '';
|
||||||
|
let JSONResponse = new Array();
|
||||||
|
let cleanResponse = new Array();
|
||||||
// Recursive function to read the stream
|
// Recursive function to read the stream
|
||||||
reader.read().then(( chunk ) => {
|
reader.read().then(( chunk ) => {
|
||||||
console.log(`Done: ${JSON.stringify(chunk.done)}`);
|
console.log(`Done: ${JSON.stringify(chunk.done)}`);
|
||||||
@ -37,8 +39,20 @@ async function readResponse(response) {
|
|||||||
finishedResponse += text;
|
finishedResponse += text;
|
||||||
}
|
}
|
||||||
if (chunk.done) {
|
if (chunk.done) {
|
||||||
const responseJSON = JSON.parse(finishedResponse);
|
const lines = finishedResponse.split('\n');
|
||||||
console.log(responseJSON);
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
const line = lines[i];
|
||||||
|
if (line.length > 0) {
|
||||||
|
const JSONline = JSON.parse(line);
|
||||||
|
JSONResponse.push(JSONline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i = 0; i < JSONResponse.length; i++) {
|
||||||
|
const JSONline = JSONResponse[i];
|
||||||
|
if (JSONline.text) {
|
||||||
|
cleanResponse.push(JSONline.response);
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
read();
|
read();
|
||||||
|
Loading…
Reference in New Issue
Block a user