Remake delete for api to protobuf
This commit is contained in:
@@ -17,6 +17,17 @@ using WsFrameHandler = std::function<esp_err_t(httpd_req_t*, httpd_ws_frame_t*)>
|
||||
using WsOpenHandler = std::function<void(httpd_req_t*)>;
|
||||
using WsCloseHandler = std::function<void(int)>;
|
||||
|
||||
// Macro to register a proto endpoint that extracts a specific payload type
|
||||
// Usage: PROTO_ENDPOINT(server, "/api/files/delete", file_delete_request, FileSystem::handleDelete)
|
||||
// Handler signature: esp_err_t handleDelete(httpd_req_t* req, const api_FileDeleteRequest& payload)
|
||||
#define PROTO_ENDPOINT(server_ref, uri, payload_type, handler) \
|
||||
(server_ref).onProto(uri, HTTP_POST, [&](httpd_req_t *request, api_Request *protoReq) { \
|
||||
if (protoReq->which_payload != api_Request_##payload_type##_tag) { \
|
||||
return WebServer::sendError(request, 400, "Invalid request payload"); \
|
||||
} \
|
||||
return handler(request, protoReq->payload.payload_type); \
|
||||
})
|
||||
|
||||
struct HttpRoute {
|
||||
std::string uri;
|
||||
httpd_method_t method;
|
||||
|
||||
@@ -26,7 +26,7 @@ bool editFile(const char *filename, const char *content);
|
||||
esp_err_t getFilesProto(httpd_req_t *request);
|
||||
esp_err_t getFiles(httpd_req_t *request);
|
||||
esp_err_t getConfigFile(httpd_req_t *request);
|
||||
esp_err_t handleDelete(httpd_req_t *request, JsonVariant &json);
|
||||
esp_err_t handleDelete(httpd_req_t *request, const api_FileDeleteRequest &req);
|
||||
esp_err_t handleEdit(httpd_req_t *request, JsonVariant &json);
|
||||
esp_err_t mkdir(httpd_req_t *request, JsonVariant &json);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user