mirror of
https://github.com/meshtastic/firmware.git
synced 2025-05-01 11:42:45 +00:00
Merge branch 'dev-https' into master
This commit is contained in:
commit
84beae1001
@ -298,6 +298,86 @@ void middlewareSpeedUp160(HTTPRequest *req, HTTPResponse *res, std::function<voi
|
|||||||
}
|
}
|
||||||
timeSpeedUp = millis();
|
timeSpeedUp = millis();
|
||||||
}
|
}
|
||||||
|
void handleStaticBrowse(HTTPRequest *req, HTTPResponse *res)
|
||||||
|
{
|
||||||
|
// Get access to the parameters
|
||||||
|
ResourceParameters *params = req->getParams();
|
||||||
|
std::string paramValDelete;
|
||||||
|
|
||||||
|
// Set a default content type
|
||||||
|
res->setHeader("Content-Type", "text/html");
|
||||||
|
|
||||||
|
if (params->getQueryParameter("delete", paramValDelete)) {
|
||||||
|
std::string pathDelete = "/" + paramValDelete;
|
||||||
|
if (SPIFFS.remove(pathDelete.c_str())) {
|
||||||
|
Serial.println(pathDelete.c_str());
|
||||||
|
res->println("<html><head><meta http-equiv=\"refresh\" content=\"3;url=/static\" /><title>File "
|
||||||
|
"deleted!</title></head><body><h1>File deleted!</h1>");
|
||||||
|
res->println("<meta http-equiv=\"refresh\" content=\"2;url=/static\" />\n");
|
||||||
|
res->println("</body></html>");
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Serial.println(pathDelete.c_str());
|
||||||
|
res->println("<html><head><meta http-equiv=\"refresh\" content=\"3;url=/static\" /><title>Error deleteing "
|
||||||
|
"file!</title></head><body><h1>Error deleteing file!</h1>");
|
||||||
|
res->println("Error deleteing file!<br>");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res->println("<h2>Upload new file</h2>");
|
||||||
|
res->println("<p><b>*** This interface is experimental ***</b></p>");
|
||||||
|
res->println("<p>This form allows you to upload files. Keep your filenames very short and files small. Big filenames and big "
|
||||||
|
"files are a known problem.</p>");
|
||||||
|
res->println("<form method=\"POST\" action=\"/upload\" enctype=\"multipart/form-data\">");
|
||||||
|
res->println("file: <input type=\"file\" name=\"file\"><br>");
|
||||||
|
res->println("<input type=\"submit\" value=\"Upload\">");
|
||||||
|
res->println("</form>");
|
||||||
|
|
||||||
|
res->println("<h2>All Files</h2>");
|
||||||
|
|
||||||
|
File root = SPIFFS.open("/");
|
||||||
|
if (root.isDirectory()) {
|
||||||
|
res->println("<script type=\"text/javascript\">function confirm_delete() {return confirm('Are you sure?');}</script>");
|
||||||
|
|
||||||
|
res->println("<table>");
|
||||||
|
File file = root.openNextFile();
|
||||||
|
while (file) {
|
||||||
|
String filePath = String(file.name());
|
||||||
|
if (filePath.indexOf("/static") == 0) {
|
||||||
|
res->println("<tr>");
|
||||||
|
res->println("<td>");
|
||||||
|
|
||||||
|
if (String(file.name()).substring(1).endsWith(".gz")) {
|
||||||
|
String modifiedFile = String(file.name()).substring(1);
|
||||||
|
modifiedFile.remove((modifiedFile.length() - 3), 3);
|
||||||
|
res->print("<a href=\"" + modifiedFile + "\">" + String(file.name()).substring(1) + "</a>");
|
||||||
|
} else {
|
||||||
|
res->print("<a href=\"" + String(file.name()).substring(1) + "\">" + String(file.name()).substring(1) +
|
||||||
|
"</a>");
|
||||||
|
}
|
||||||
|
res->println("</td>");
|
||||||
|
res->println("<td>");
|
||||||
|
res->print(String(file.size()));
|
||||||
|
res->println("</td>");
|
||||||
|
res->println("<td>");
|
||||||
|
res->print("<a href=\"/static?delete=" + String(file.name()).substring(1) +
|
||||||
|
"\" onclick=\"return confirm_delete()\">X</a>");
|
||||||
|
res->println("</td>");
|
||||||
|
}
|
||||||
|
|
||||||
|
file = root.openNextFile();
|
||||||
|
}
|
||||||
|
res->println("</table>");
|
||||||
|
|
||||||
|
res->print("<br>");
|
||||||
|
res->print("Total : " + String(SPIFFS.totalBytes()) + " Bytes<br>");
|
||||||
|
res->print("Used : " + String(SPIFFS.usedBytes()) + " Bytes<br>");
|
||||||
|
res->print("Free : " + String(SPIFFS.totalBytes() - SPIFFS.usedBytes()) + " Bytes<br>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void handleStaticPost(HTTPRequest *req, HTTPResponse *res)
|
void handleStaticPost(HTTPRequest *req, HTTPResponse *res)
|
||||||
{
|
{
|
||||||
@ -831,7 +911,6 @@ void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res)
|
|||||||
*/
|
*/
|
||||||
void handleRoot(HTTPRequest *req, HTTPResponse *res)
|
void handleRoot(HTTPRequest *req, HTTPResponse *res)
|
||||||
{
|
{
|
||||||
|
|
||||||
res->setHeader("Content-Type", "text/html");
|
res->setHeader("Content-Type", "text/html");
|
||||||
|
|
||||||
randomSeed(millis());
|
randomSeed(millis());
|
||||||
@ -873,6 +952,7 @@ void handleRoot(HTTPRequest *req, HTTPResponse *res)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Read the file from SPIFFS and write it to the HTTP response body
|
// Read the file from SPIFFS and write it to the HTTP response body
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
do {
|
do {
|
||||||
@ -891,6 +971,7 @@ void handleFavicon(HTTPRequest *req, HTTPResponse *res)
|
|||||||
res->write(FAVICON_DATA, FAVICON_LENGTH);
|
res->write(FAVICON_DATA, FAVICON_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void replaceAll(std::string &str, const std::string &from, const std::string &to)
|
void replaceAll(std::string &str, const std::string &from, const std::string &to)
|
||||||
{
|
{
|
||||||
if (from.empty())
|
if (from.empty())
|
||||||
@ -901,3 +982,4 @@ void replaceAll(std::string &str, const std::string &from, const std::string &to
|
|||||||
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
|
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user