From c40fc7cbfe28b3fc791b525ffeb0593724ac0cf4 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Wed, 22 Dec 2021 00:28:00 +0100 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=86=D0=B8=D1=8E=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=BD=D0=B0=20esp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.svelte | 53 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index dd3bb9b..a16f5f4 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -246,14 +246,14 @@ }); socket[ws].addEventListener("message", function (event) { let data = event.data.toString(); - if (debug) console.log("[i]", "data:", data); + //if (debug) console.log("[i]", "data:", data); if (data.includes("[log]")) { data = data.replace("[log]", ""); addCoreMsg(data); //if (debug) console.log("[i]", "log data:", data); - } else if (data.includes("[config]")) { + } else if (data.includes("[/setup.json]")) { if (debug) console.log("[i]", "config data:", data); - data = data.replace("[config]", ""); + data = data.replace("[/setup.json]", ""); data = JSON.parse(data); config.push(data); config = config; @@ -411,6 +411,53 @@ return json; }; + //post и get запросы================================================================================= + //запрос с помощью которого можно отредактировать любой файл на esp + //editRequest("192.168.88.235", "data data data data", "file.json") + + function editRequest(url, data, filename) { + if (debug) console.log("[i]", "request for edit file"); + var xmlHttp = new XMLHttpRequest(); + var formData = new FormData(); + formData.append("data", new Blob([data], { type: "text/json" }), "/" + filename); + xmlHttp.open("POST", "http://" + url + "/edit"); + xmlHttp.onload = function () { + //во время загрузки + }; + xmlHttp.send(formData); + } + + async function handleSubmit(url) { + try { + console.log(url); + let res = await fetch(url, { + mode: "no-cors", + method: "GET", + }); + if (res.ok) { + console.log("OK", res.status); + //console.log(url); + } else { + console.log("error", res.status); + //console.log(url); + } + } catch (e) { + console.log(e); + } + } + + async function getRequestJson(url) { + let res = await fetch(url, { + mode: "no-cors", + method: "GET", + }); + if (res.ok) { + configSetupJson = await res.json(); + } else { + console.log("error", res.status); + } + } + //initialisation======================================================================================= onMount(async () => { console.log("[i]", "mounted");