Changed minimize function to backend endpoint.
This commit is contained in:
@@ -20,33 +20,44 @@ function formatAndValidateJson(errorElement) {
|
|||||||
input.innerText = data;
|
input.innerText = data;
|
||||||
processInfo.innerText = "";
|
processInfo.innerText = "";
|
||||||
hljs.highlightElement(input);
|
hljs.highlightElement(input);
|
||||||
|
|
||||||
|
const end = new Date();
|
||||||
|
processInfo.innerHTML = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
|
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
const end = new Date();
|
|
||||||
processInfo.innerHTML = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function minimizeJson(errorElement) {
|
function minimizeJson(errorElement) {
|
||||||
const input = document.querySelector('#jsonBlock');
|
const input = document.querySelector('#jsonBlock');
|
||||||
const processInfo = document.getElementById(errorElement);
|
const processInfo = document.getElementById(errorElement);
|
||||||
|
|
||||||
try {
|
const start = new Date();
|
||||||
const start = new Date();
|
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/minimize"
|
||||||
|
|
||||||
const obj = JSON.parse(input.textContent);
|
fetch(address, {
|
||||||
input.innerHTML = JSON.stringify(obj);
|
method: 'POST',
|
||||||
|
body: input.textContent
|
||||||
|
})
|
||||||
|
.then(async (response) => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw Error(await response.text());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.text();
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
input.innerText = data;
|
||||||
processInfo.innerText = "";
|
processInfo.innerText = "";
|
||||||
hljs.highlightElement(input);
|
hljs.highlightElement(input);
|
||||||
|
|
||||||
const end = new Date();
|
const end = new Date();
|
||||||
processInfo.innerHTML = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>"
|
processInfo.innerHTML = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
|
||||||
+ (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
|
})
|
||||||
} catch (error) {
|
.catch((error) => {
|
||||||
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
|
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
|
||||||
console.error("Error: ", error)
|
console.error('Error:', error);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user