mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
Fix gravity output to apply the ${OVER} sequence (#2725)
This commit is contained in:
@@ -38,6 +38,7 @@ function eventsource() {
|
||||
return reader.read().then(({ done, value }) => {
|
||||
// When no more data needs to be consumed, close the stream
|
||||
if (done) {
|
||||
ta.append("Done.");
|
||||
controller.close();
|
||||
alInfo.hide();
|
||||
$("#gravityBtn").prop("disabled", false);
|
||||
@@ -47,9 +48,8 @@ function eventsource() {
|
||||
// Enqueue the next data chunk into our target stream
|
||||
controller.enqueue(value);
|
||||
var string = new TextDecoder().decode(value);
|
||||
// Remove ${OVER} from the string
|
||||
string = string.replaceAll("\r[K", "\n");
|
||||
ta.append(string);
|
||||
parseLines(ta, string);
|
||||
|
||||
if (string.indexOf("Pi-hole blocking is") !== -1) {
|
||||
alSuccess.show();
|
||||
}
|
||||
@@ -84,3 +84,24 @@ $(function () {
|
||||
eventsource();
|
||||
}
|
||||
});
|
||||
|
||||
function parseLines(ta, str) {
|
||||
// str can contain multiple lines.
|
||||
// We want to split the text before an "OVER" escape sequence to allow overwriting previous line when needed
|
||||
|
||||
// Splitting the text on "\r"
|
||||
var lines = str.split(/(?=\r)/g);
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (lines[i][0] === "\r") {
|
||||
// This line starts with the "OVER" sequence. Replace them with "\n" before print
|
||||
lines[i] = lines[i].replaceAll("\r[K", "\n").replaceAll("\r", "\n");
|
||||
|
||||
// Last line from the textarea will be overwritten, so we remove it
|
||||
ta.text(ta.text().substring(0, ta.text().lastIndexOf("\n")));
|
||||
}
|
||||
|
||||
// Append the new text to the end of the output
|
||||
ta.append(lines[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user