From f3628c4f9c86c4cb9189868fa374ef0e5c31aa39 Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Fri, 12 Jul 2024 12:04:09 +0700 Subject: [PATCH] added wifi qr code --- openrouter/src/settings/wifi/qr.cpp | 2 -- openrouter/src/types.hpp | 2 +- openrouter/src/web/css/settings.css | 1 + openrouter/src/web/index.html | 9 ++++++--- openrouter/src/web/js/routes.js | 1 + openrouter/src/web/js/settings/wifi.js | 22 ++++++++++++++++++++++ 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/openrouter/src/settings/wifi/qr.cpp b/openrouter/src/settings/wifi/qr.cpp index 816f832..c111a72 100644 --- a/openrouter/src/settings/wifi/qr.cpp +++ b/openrouter/src/settings/wifi/qr.cpp @@ -53,8 +53,6 @@ void get_wifi_qr(const httplib::Request &request, httplib::Response &response) { std::stringstream toqrstring; toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";"; - std::cout << toqrstring.str() << std::endl; - qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(toqrstring.str().c_str(), qrcodegen::QrCode::Ecc::MEDIUM); std::string responsedata = toSvgString(qr0, 4); response.set_content(responsedata, SVG_TYPE); diff --git a/openrouter/src/types.hpp b/openrouter/src/types.hpp index fcf477f..c2f1856 100644 --- a/openrouter/src/types.hpp +++ b/openrouter/src/types.hpp @@ -7,6 +7,6 @@ #define STRING403 R"({"status":"403"})" #define JSON_TYPE "application/json" #define PLAIN_TEXT_TYPE "text/plain" -#define SVG_TYPE "image/svg" +#define SVG_TYPE "image/svg+xml" #endif // TYPES_H \ No newline at end of file diff --git a/openrouter/src/web/css/settings.css b/openrouter/src/web/css/settings.css index 6a7328c..82add74 100644 --- a/openrouter/src/web/css/settings.css +++ b/openrouter/src/web/css/settings.css @@ -210,6 +210,7 @@ tbody>tr>th { width: 0; height: 0; overflow: hidden; + transition: 0.3s; } #wifiqrimg.active { diff --git a/openrouter/src/web/index.html b/openrouter/src/web/index.html index 4b9e679..27fd8d8 100644 --- a/openrouter/src/web/index.html +++ b/openrouter/src/web/index.html @@ -153,10 +153,13 @@ -
- +
+ +
+ +
+
- qr to connect
diff --git a/openrouter/src/web/js/routes.js b/openrouter/src/web/js/routes.js index a800213..d0fcf34 100644 --- a/openrouter/src/web/js/routes.js +++ b/openrouter/src/web/js/routes.js @@ -33,6 +33,7 @@ const routes = { wifi_name_set: () => [host, prefix, 'settings', 'wifi', 'name', 'set'].join('/'), wifi_password_get: () => [host, prefix, 'settings', 'wifi', 'password', 'get'].join('/'), wifi_password_set: () => [host, prefix, 'settings', 'wifi', 'password', 'set'].join('/'), + wifi_qr_get: () => [host, prefix, 'settings', 'wifi', 'qr', 'get' ].join('/'), reboot: () => [host, prefix, 'reboot'].join('/'), syslog: () => [host, prefix, 'syslog'].join('/'), diff --git a/openrouter/src/web/js/settings/wifi.js b/openrouter/src/web/js/settings/wifi.js index bbb394e..6ffd31b 100644 --- a/openrouter/src/web/js/settings/wifi.js +++ b/openrouter/src/web/js/settings/wifi.js @@ -142,3 +142,25 @@ shownewpasswordbutton.addEventListener('click', () => { } newwifipassword.type = "password" }) + +const get_wifi_qr_code = () => { + fetch(routes.wifi_qr_get(), { + method: 'POST', + body: `{"token":"${localStorage.getItem('token')}"}` + }).then(data => data.text()).then(svgdata => { + wifiqrimg.innerHTML = svgdata + }).catch((error) => { + notification(`Ошибка на сервере: ${error}`, "error") + }) +} + +wifiqr.addEventListener('click', () => { + if (wifiqr.checked) { + get_wifi_qr_code() + wifiqrimg.innerHTML = + wifiqrimg.classList.add('active') + return + } + wifiqrimg.classList.remove('active') + wifiqrimg.innerHTML = "" +})