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

Method HandlePUT_nodes_uid_data

Modules/RESTAPI/src/mitkDataStorageController.cpp:1674–1780  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1672}
1673
1674void DataStorageController::HandlePUT_nodes_uid_data(const httplib::Request& req, httplib::Response& res)
1675{
1676 if (!m_Bridge.HasDataStorage())
1677 {
1678 this->SendErrorResponse(res, 503, ErrorResponse::DataStorageNotAvailable(req.path));
1679 return;
1680 }
1681
1682 const std::string uid = req.path_params.at("uid");
1683 if (!ValidateUid(uid))
1684 {
1685 this->SendErrorResponse(res, 400, ErrorResponse::InvalidRequest("Invalid UID format", req.path));
1686 return;
1687 }
1688
1689 // Check if node exists
1690 const auto nodeJson = m_Bridge.GetNode(uid);
1691 if (!nodeJson.has_value())
1692 {
1693 this->SendErrorResponse(res, 404, ErrorResponse::NodeNotFound(uid, req.path));
1694 return;
1695 }
1696
1697 // Get Content-Type header
1698 const std::string contentType = req.has_header(HEADER_CONTENT_TYPE)
1699 ? req.get_header_value(HEADER_CONTENT_TYPE)
1700 : "";
1701
1702 // Validate Content-Type
1703 const bool isFileReference = (contentType.find(MIME_APPLICATION_JSON) != std::string::npos);
1704 const bool isDirectTransfer = (contentType.find(MIME_APPLICATION_OCTET_STREAM) != std::string::npos);
1705
1706 if (!isFileReference && !isDirectTransfer)
1707 {
1708 this->SendErrorResponse(res, 415, ErrorResponse::UnsupportedFormat(
1709 "Unsupported Content-Type. Use 'application/json' for file-reference mode or "
1710 "'application/octet-stream' for direct transfer mode.", req.path));
1711 return;
1712 }
1713
1714 // Resolve data file path
1715 auto pathResult = this->ResolveDataPath(req, contentType);
1716 if (!pathResult.success)
1717 {
1718 this->SendErrorResponse(res, pathResult.errorStatus, pathResult.errorResponse);
1719 return;
1720 }
1721
1722 // Helper for cleanup
1723 auto cleanupTempFile = [&]() {
1724 if (pathResult.isTemporary && !pathResult.filePath.empty())
1725 {
1726 try { fs::remove(pathResult.filePath); }
1727 catch (const std::exception&) { /* ignore */ }
1728 }
1729 };
1730
1731 // Load data from file

Callers 13

PutDataNodeNotFoundMethod · 0.80
PutDataEmptyBodyMethod · 0.80
PutDataInvalidJsonMethod · 0.80
PutDataFileNotFoundMethod · 0.80
PutImageDataDirectMethod · 0.80
BuildEndpointRegistryMethod · 0.80

Calls 13

SendErrorResponseMethod · 0.95
ResolveDataPathMethod · 0.95
LoadDataFromFileMethod · 0.95
SendJsonResponseMethod · 0.95
ValidateUidFunction · 0.85
atMethod · 0.80
SetNodeDataMethod · 0.80
HasDataStorageMethod · 0.45
GetNodeMethod · 0.45
findMethod · 0.45
emptyMethod · 0.45
valueMethod · 0.45

Tested by 12

PutDataNodeNotFoundMethod · 0.64
PutDataEmptyBodyMethod · 0.64
PutDataInvalidJsonMethod · 0.64
PutDataFileNotFoundMethod · 0.64
PutImageDataDirectMethod · 0.64
BuildEndpointRegistryMethod · 0.64