From 6660db7a81ed598114e90b8c3c23742d01ff9b3b Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Fri, 10 May 2019 19:52:46 +0200 Subject: [PATCH] log: read logs stream --- src/components/log.vue | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/log.vue b/src/components/log.vue index 96dfc2d..96b95a1 100644 --- a/src/components/log.vue +++ b/src/components/log.vue @@ -78,8 +78,24 @@ export default { } let res = await fetch(apiurl(path)); if (res.status == 200) { - let data = await res.text(); - this.items.push(this.formatter.ansi_to_html(data)); + const reader = res.body.getReader(); + + let items = this.items; + let formatter = this.formatter; + + for (;;) { + let { done, value } = await reader.read(); + if (done) { + return; + } + + let data = String.fromCharCode.apply(null, value); + + let lines = data.split("\n"); + lines.forEach(line => { + items.push(formatter.ansi_to_html(line)); + }); + } } } },