Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make recovery page an embedded file #649

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ PRIV_REQUIRES
"spiffs"
"vfs"
"esp_driver_i2c"

EMBED_FILES "http_server/recovery_page.html"
)

idf_build_set_property(COMPILE_OPTIONS "-DLV_CONF_INCLUDE_SIMPLE=1" APPEND)
Expand Down
7 changes: 5 additions & 2 deletions main/http_server/http_server.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "http_server.h"
#include "recovery_page.h"
#include "theme_api.h" // Add theme API include
#include "cJSON.h"
#include "esp_chip_info.h"
Expand Down Expand Up @@ -257,7 +256,11 @@ static esp_err_t rest_recovery_handler(httpd_req_t * req)
return httpd_resp_send_err(req, HTTPD_401_UNAUTHORIZED, "Unauthorized");
}

httpd_resp_send(req, recovery_page, HTTPD_RESP_USE_STRLEN);
extern const unsigned char recovery_page_start[] asm("_binary_recovery_page_html_start");
extern const unsigned char recovery_page_end[] asm("_binary_recovery_page_html_end");
const size_t recovery_page_size = (recovery_page_end - recovery_page_start);
httpd_resp_send_chunk(req, (const char*)recovery_page_start, recovery_page_size);
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}

Expand Down
79 changes: 0 additions & 79 deletions main/http_server/recovery_page.h

This file was deleted.

74 changes: 74 additions & 0 deletions main/http_server/recovery_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<html>
<style>
body {
background-color: #000;
color: #00ff00;
font-family: courier new;
}
</style>
<head>
<title>AxeOS Recovery</title>
</head>
<body>
<pre>
____ _____
/\ / __ \ / ____|
/ \ __ _____| | | | (___
/ /\ \ \ \/ / _ \ | | |\___ \
/ ____ \ > < __/ |__| |____) |
/_/___ \_\/_/\_\___|\____/|_____/
| __ \
| |__) |___ ___ _____ _____ _ __ _ _
| _ // _ \/ __/ _ \ \ / / _ \ '__| | | |
| | \ \ __/ (_| (_) \ V / __/ | | |_| |
|_| \_\___|\___\___/ \_/ \___|_| \__, |
__/ |
|___/
</pre>
<p>Please upload www.bin to recover AxeOS</p>
<p>After clicking upload, please wait 60 seconds<br>
DO NOT restart the device until response is received</p>
<input type="file" id="wwwfile" name="wwwfile"><br>
<button id="upload">Upload</button>
<small id="status"></small>
<br><button id="restart">Restart</button>
<br><br>Response:<br>
<small id="response"></small>
<script>
document.getElementById('upload').addEventListener('click', handleUpload);
statusMsg = document.getElementById('status');
responseMsg = document.getElementById('response');
function handleUpload() {
const fileInput = document.getElementById('wwwfile');
const file = fileInput.files[0];
const uploadUrl = '/api/system/OTAWWW';
const upload_xhr = new XMLHttpRequest();
upload_xhr.open('POST', uploadUrl, true);
upload_xhr.setRequestHeader('Content-Type', 'application/octet-stream');
upload_xhr.onload = function() {
const responseBody = upload_xhr.responseText;
if (upload_xhr.status === 200) {
statusMsg.innerHTML = 'Upload successful!';
} else {
statusMsg.innerHTML='Error uploading!';
}
responseMsg.innerHTML = responseBody;
};
statusMsg.innerHTML = 'uploading...';
upload_xhr.send(file);
}
document.getElementById('restart').addEventListener('click', handleRestart);
function handleRestart() {
const restartUrl = '/api/system/restart';
const restart_xhr = new XMLHttpRequest();
restart_xhr.open('POST', restartUrl, true);
restart_xhr.setRequestHeader('Content-Type', '');
restart_xhr.onload = function() {
const responseBody = restart_xhr.responseText;
responseMsg.innerHTML = responseBody;
};
restart_xhr.send(null);
}
</script>
</body>
</html>
Loading