Claude: File chunking system

This commit is contained in:
Niklas Jensen
2026-01-05 20:33:16 +01:00
committed by Rune Harlyk
parent 725d62747d
commit f440fa3973
8 changed files with 1472 additions and 19 deletions
@@ -41,6 +41,22 @@ DEFINE_MESSAGE_TRAITS(ServoPWMData, servo_pwm)
DEFINE_MESSAGE_TRAITS(ServoStateData, servo_state)
DEFINE_MESSAGE_TRAITS(CorrelationRequest, correlation_request)
DEFINE_MESSAGE_TRAITS(CorrelationResponse, correlation_response)
DEFINE_MESSAGE_TRAITS(FSDeleteRequest, fs_delete_request)
DEFINE_MESSAGE_TRAITS(FSDeleteResponse, fs_delete_response)
DEFINE_MESSAGE_TRAITS(FSMkdirRequest, fs_mkdir_request)
DEFINE_MESSAGE_TRAITS(FSMkdirResponse, fs_mkdir_response)
DEFINE_MESSAGE_TRAITS(FSListRequest, fs_list_request)
DEFINE_MESSAGE_TRAITS(FSListResponse, fs_list_response)
DEFINE_MESSAGE_TRAITS(FSDownloadStartRequest, fs_download_start_request)
DEFINE_MESSAGE_TRAITS(FSDownloadStartResponse, fs_download_start_response)
DEFINE_MESSAGE_TRAITS(FSDownloadChunkRequest, fs_download_chunk_request)
DEFINE_MESSAGE_TRAITS(FSDownloadChunkResponse, fs_download_chunk_response)
DEFINE_MESSAGE_TRAITS(FSUploadStartRequest, fs_upload_start_request)
DEFINE_MESSAGE_TRAITS(FSUploadStartResponse, fs_upload_start_response)
DEFINE_MESSAGE_TRAITS(FSUploadChunkRequest, fs_upload_chunk_request)
DEFINE_MESSAGE_TRAITS(FSUploadChunkResponse, fs_upload_chunk_response)
DEFINE_MESSAGE_TRAITS(FSCancelTransferRequest, fs_cancel_transfer_request)
DEFINE_MESSAGE_TRAITS(FSCancelTransferResponse, fs_cancel_transfer_response)
#undef DEFINE_MESSAGE_TRAITS
+62
View File
@@ -0,0 +1,62 @@
#pragma once
#include <LittleFS.h>
#include <platform_shared/message.pb.h>
#include <map>
#include <string>
#define FS_MAX_CHUNK_SIZE 1024
#define FS_TRANSFER_TIMEOUT 30000 // 30 seconds
namespace FileSystemWS {
struct TransferState {
std::string path;
File file;
uint32_t fileSize;
uint32_t chunkSize;
uint32_t totalChunks;
uint32_t chunksProcessed;
uint32_t lastActivityTime;
bool isUpload;
};
class FileSystemHandler {
public:
FileSystemHandler();
// Delete file/directory
socket_message_FSDeleteResponse handleDelete(const socket_message_FSDeleteRequest& req);
// Create directory
socket_message_FSMkdirResponse handleMkdir(const socket_message_FSMkdirRequest& req);
// List directory
socket_message_FSListResponse handleList(const socket_message_FSListRequest& req);
// Download operations (ESP -> Client)
socket_message_FSDownloadStartResponse handleDownloadStart(const socket_message_FSDownloadStartRequest& req);
socket_message_FSDownloadChunkResponse handleDownloadChunk(const socket_message_FSDownloadChunkRequest& req);
// Upload operations (Client -> ESP)
socket_message_FSUploadStartResponse handleUploadStart(const socket_message_FSUploadStartRequest& req);
socket_message_FSUploadChunkResponse handleUploadChunk(const socket_message_FSUploadChunkRequest& req);
// Cancel transfer
socket_message_FSCancelTransferResponse handleCancelTransfer(const socket_message_FSCancelTransferRequest& req);
// Cleanup expired transfers
void cleanupExpiredTransfers();
private:
std::map<std::string, TransferState> transfers_;
uint32_t transferIdCounter_;
std::string generateTransferId();
void listDirectory(const std::string& path, socket_message_FSListResponse& response);
bool deleteRecursive(const std::string& path);
};
extern FileSystemHandler fsHandler;
} // namespace FileSystemWS