MCPcopy Create free account
hub / github.com/MITK/MITK / HandlePOST_nodes_uid_generic

Method HandlePOST_nodes_uid_generic

Modules/RESTAPI/src/mitkDataStorageController.cpp:1023–1192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1021}
1022
1023void DataStorageController::HandlePOST_nodes_uid_generic(const httplib::Request& req, httplib::Response& res, const std::optional<std::string>& parentUID)
1024{
1025 // Determine transfer mode from Content-Type
1026 const std::string contentType = req.has_header(HEADER_CONTENT_TYPE)
1027 ? req.get_header_value(HEADER_CONTENT_TYPE)
1028 : "";
1029
1030 const bool isJsonMode = (contentType.find(MIME_APPLICATION_JSON) != std::string::npos);
1031 const bool isDirectTransfer = (contentType.find(MIME_APPLICATION_OCTET_STREAM) != std::string::npos);
1032
1033 nlohmann::json nodeData;
1034 bool hasDataTransfer = false;
1035 std::string dataFilePath;
1036 bool deleteTempFile = false;
1037
1038 if (isJsonMode)
1039 {
1040 // JSON body mode
1041 try
1042 {
1043 if (!req.body.empty())
1044 {
1045 nodeData = nlohmann::json::parse(req.body);
1046 }
1047 }
1048 catch (const nlohmann::json::parse_error& e)
1049 {
1050 this->SendErrorResponse(res, 400, ErrorResponse::InvalidRequest(
1051 "Invalid JSON: " + std::string(e.what()), req.path));
1052 return;
1053 }
1054
1055 // Validate transfer mode if specified
1056 if (nodeData.contains(JSON_KEY_TRANSFER) && nodeData[JSON_KEY_TRANSFER].contains(JSON_KEY_MODE))
1057 {
1058 const std::string specifiedMode = nodeData[JSON_KEY_TRANSFER][JSON_KEY_MODE].get<std::string>();
1059 if (specifiedMode != TRANSFER_MODE_DIRECT && specifiedMode != TRANSFER_MODE_FILE_REFERENCE)
1060 {
1061 this->SendErrorResponse(res, 406, ErrorResponse::TransferModeNotAvailable(
1062 specifiedMode, {TRANSFER_MODE_FILE_REFERENCE, TRANSFER_MODE_DIRECT}, req.path));
1063 return;
1064 }
1065 }
1066
1067 // Check if there's a transfer section
1068 if (nodeData.contains(JSON_KEY_TRANSFER) && nodeData[JSON_KEY_TRANSFER].contains(JSON_KEY_FILE_PATH))
1069 {
1070 hasDataTransfer = true;
1071 }
1072 }
1073 else if (isDirectTransfer)
1074 {
1075 // Binary body mode: name from query parameter
1076 if (req.has_param(JSON_KEY_NAME))
1077 {
1078 nodeData[JSON_KEY_NAME] = req.get_param_value(JSON_KEY_NAME);
1079 }
1080 hasDataTransfer = true;

Callers 2

HandlePOST_nodesMethod · 0.95

Calls 15

SendErrorResponseMethod · 0.95
ResolveDataPathMethod · 0.95
LoadDataFromFileMethod · 0.95
SendJsonResponseMethod · 0.95
whatMethod · 0.80
containsMethod · 0.80
SetNodeDataMethod · 0.80
findMethod · 0.45
emptyMethod · 0.45
eraseMethod · 0.45
CreateNodeMethod · 0.45
DeleteNodeMethod · 0.45

Tested by

no test coverage detected