Review feedback
This commit is contained in:
parent
28b759bf7d
commit
12f8c9f12d
@ -212,10 +212,7 @@ bool CrossPointWebServer::isEpubFile(const String& filename) const {
|
||||
return lower.endsWith(".epub");
|
||||
}
|
||||
|
||||
void CrossPointWebServer::handleFileList() const {
|
||||
// server->setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
server->send(200, "text/html", FilesPageHtml);
|
||||
}
|
||||
void CrossPointWebServer::handleFileList() const { server->send(200, "text/html", FilesPageHtml); }
|
||||
|
||||
void CrossPointWebServer::handleFileListData() const {
|
||||
// Get current path from query string (default to root)
|
||||
@ -235,15 +232,21 @@ void CrossPointWebServer::handleFileListData() const {
|
||||
server->setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
server->send(200, "application/json", "");
|
||||
server->sendContent("[");
|
||||
char output[300];
|
||||
char output[512];
|
||||
constexpr size_t outputSize = sizeof(output);
|
||||
bool seenFirst = false;
|
||||
scanFiles(currentPath.c_str(), [this, output, seenFirst](const FileInfo& info) mutable {
|
||||
scanFiles(currentPath.c_str(), [this, &output, seenFirst](const FileInfo& info) mutable {
|
||||
JsonDocument doc;
|
||||
doc["name"] = info.name;
|
||||
doc["size"] = info.size;
|
||||
doc["isDirectory"] = info.isDirectory;
|
||||
doc["isEpub"] = info.isEpub;
|
||||
serializeJson(doc, output, sizeof(output));
|
||||
const size_t written = serializeJson(doc, output, outputSize);
|
||||
if (written >= outputSize) {
|
||||
// JSON output truncated; skip this entry to avoid sending malformed JSON
|
||||
Serial.printf("[%lu] [WEB] Skipping file entry with oversized JSON for name: %s\n", millis(), info.name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (seenFirst) {
|
||||
server->sendContent(",");
|
||||
@ -253,6 +256,7 @@ void CrossPointWebServer::handleFileListData() const {
|
||||
server->sendContent(output);
|
||||
});
|
||||
server->sendContent("]");
|
||||
// End of streamed response, empty chunk to signal client
|
||||
server->sendContent("");
|
||||
Serial.printf("[%lu] [WEB] Served file listing page for path: %s\n", millis(), currentPath.c_str());
|
||||
}
|
||||
|
||||
@ -612,7 +612,7 @@
|
||||
breadcrumbContent += '<a href="/files">🏠</a>';
|
||||
const pathSegments = currentPath.split('/');
|
||||
pathSegments.slice(1, pathSegments.length - 1).forEach(function(segment, index) {
|
||||
breadcrumbContent += '<span class="sep">/</span><a href="/files?path=' + encodeURIComponent(pathSegments.slice(0, index + 1).join('/')) + '">' + escapeHtml(segment) + '</a>';
|
||||
breadcrumbContent += '<span class="sep">/</span><a href="/files?path=' + encodeURIComponent(pathSegments.slice(0, index + 2).join('/')) + '">' + escapeHtml(segment) + '</a>';
|
||||
});
|
||||
breadcrumbContent += '<span class="sep">/</span>';
|
||||
breadcrumbContent += '<span class="current">' + escapeHtml(pathSegments[pathSegments.length - 1]) + '</span>';
|
||||
@ -621,7 +621,11 @@
|
||||
|
||||
let files = [];
|
||||
try {
|
||||
files = await fetch('/api/files?path=' + encodeURIComponent(currentPath)).then(response => response.json());
|
||||
const response = await fetch('/api/files?path=' + encodeURIComponent(currentPath));
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to load files: ' + response.status + ' ' + response.statusText);
|
||||
}
|
||||
files = await response.json();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
fileTable.innerHTML = '<div class="no-files">An error occurred while loading the files</div>';
|
||||
|
||||
@ -108,6 +108,9 @@
|
||||
async function fetchStatus() {
|
||||
try {
|
||||
const response = await fetch('/api/status');
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch status: ' + response.status + ' ' + response.statusText);
|
||||
}
|
||||
const data = await response.json();
|
||||
document.getElementById('version').textContent = data.version || 'N/A';
|
||||
document.getElementById('ip-address').textContent = data.ip || 'N/A';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user