diff --git a/Frontend/assets/scripts/tools/json.js b/Frontend/assets/scripts/tools/json.js index 1ce3473..04e2c55 100644 --- a/Frontend/assets/scripts/tools/json.js +++ b/Frontend/assets/scripts/tools/json.js @@ -20,33 +20,44 @@ function formatAndValidateJson(errorElement) { input.innerText = data; processInfo.innerText = ""; hljs.highlightElement(input); + + const end = new Date(); + processInfo.innerHTML = "Validation and formatting time: " + (end.getMilliseconds() - start.getMilliseconds()) + "ms"; }) .catch((error) => { processInfo.innerHTML = "" + error + ""; console.error('Error:', error); }); - - const end = new Date(); - processInfo.innerHTML = "Validation and formatting time: " + (end.getMilliseconds() - start.getMilliseconds()) + "ms"; } function minimizeJson(errorElement) { const input = document.querySelector('#jsonBlock'); 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); - input.innerHTML = JSON.stringify(obj); + fetch(address, { + 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 = ""; hljs.highlightElement(input); const end = new Date(); - processInfo.innerHTML = "Validation and formatting time: " - + (end.getMilliseconds() - start.getMilliseconds()) + "ms"; - } catch (error) { + processInfo.innerHTML = "Validation and formatting time: " + (end.getMilliseconds() - start.getMilliseconds()) + "ms"; + }) + .catch((error) => { processInfo.innerHTML = "" + error + ""; - console.error("Error: ", error) - } + console.error('Error:', error); + }); } \ No newline at end of file