Claude: reduced the file and dir count (still bad code) but works

This commit is contained in:
Niklas Jensen
2026-01-05 21:21:52 +01:00
committed by Rune Harlyk
parent 957b60b132
commit 26c187a480
4 changed files with 43 additions and 12 deletions
+3 -3
View File
@@ -108,14 +108,14 @@ void FileSystemHandler::listDirectory(const std::string& path, socket_message_FS
int fileCount = 0;
int dirCount = 0;
while (file && fileCount < 50 && dirCount < 50) { // Limit to prevent overflow
while (file && fileCount < 20 && dirCount < 20) { // Limit to match protobuf max_count
if (file.isDirectory()) {
if (dirCount < 50) {
if (dirCount < 20) {
strncpy(response.directories[dirCount].name, file.name(), sizeof(response.directories[dirCount].name) - 1);
dirCount++;
}
} else {
if (fileCount < 50) {
if (fileCount < 20) {
strncpy(response.files[fileCount].name, file.name(), sizeof(response.files[fileCount].name) - 1);
response.files[fileCount].size = file.size();
fileCount++;
+10 -5
View File
@@ -45,6 +45,7 @@ APService apService;
void setupServer() {
server.config.max_uri_handlers = 50 + WWW_ASSETS_COUNT;
server.config.stack_size = 32768; // Increase from default 4KB to 32KB for large protobuf messages
server.maxUploadSize = 1000000; // 1 MB;
server.listen(80);
server.on("/api/system/reset", HTTP_POST,
@@ -239,17 +240,21 @@ void setupEventSocket() {
};
socket.on<socket_message_CorrelationRequest>([&](const socket_message_CorrelationRequest &data, int clientId) {
socket_message_CorrelationResponse res = socket_message_CorrelationResponse_init_default;
res.correlation_id = data.correlation_id;
res.status_code = 200;
// Allocate response on heap to avoid stack overflow (CorrelationResponse is very large)
auto res = new socket_message_CorrelationResponse();
*res = socket_message_CorrelationResponse_init_default;
res->correlation_id = data.correlation_id;
res->status_code = 200;
auto it = correlationHandlers.find(data.which_request);
if (it != correlationHandlers.end()) {
it->second(data, res);
socket.emit(res, clientId);
it->second(data, *res);
socket.emit(*res, clientId);
} else {
printf("WARNING: no handler for correlation request: %d\n", data.which_request);
}
delete res;
});
}