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

Method ResolveDataPath

Modules/RESTAPI/src/mitkDataStorageController.cpp:721–877  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

719}
720
721DataStorageController::ResolveDataPathResult DataStorageController::ResolveDataPath(
722 const httplib::Request& req, const std::string& contentType)
723{
724 ResolveDataPathResult result;
725 result.success = false;
726 result.isTemporary = false;
727 result.errorStatus = 0;
728
729 const bool isFileReference = (contentType.find(MIME_APPLICATION_JSON) != std::string::npos);
730 const bool isDirectTransfer = (contentType.find(MIME_APPLICATION_OCTET_STREAM) != std::string::npos);
731
732 if (isFileReference)
733 {
734 // Parse JSON body to get file path
735 nlohmann::json body;
736 try
737 {
738 body = nlohmann::json::parse(req.body);
739 }
740 catch (const nlohmann::json::parse_error& e)
741 {
742 result.errorStatus = 400;
743 result.errorResponse = ErrorResponse::InvalidRequest(
744 "Invalid JSON: " + std::string(e.what()), req.path);
745 return result;
746 }
747
748 // Validate transfer mode if specified
749 if (body.contains(JSON_KEY_TRANSFER) && body[JSON_KEY_TRANSFER].contains(JSON_KEY_MODE))
750 {
751 const std::string specifiedMode = body[JSON_KEY_TRANSFER][JSON_KEY_MODE].get<std::string>();
752 if (specifiedMode != TRANSFER_MODE_DIRECT && specifiedMode != TRANSFER_MODE_FILE_REFERENCE)
753 {
754 result.errorStatus = 406;
755 result.errorResponse = ErrorResponse::TransferModeNotAvailable(
756 specifiedMode, {TRANSFER_MODE_FILE_REFERENCE, TRANSFER_MODE_DIRECT}, req.path);
757 return result;
758 }
759 }
760
761 if (!body.contains(JSON_KEY_TRANSFER) || !body[JSON_KEY_TRANSFER].contains(JSON_KEY_FILE_PATH))
762 {
763 result.errorStatus = 400;
764 result.errorResponse = ErrorResponse::InvalidRequest(
765 "Missing transfer.file_path in request body", req.path);
766 return result;
767 }
768
769 const fs::path filePath(body[JSON_KEY_TRANSFER][JSON_KEY_FILE_PATH].get<std::string>());
770
771 if (!fs::exists(filePath))
772 {
773 result.errorStatus = 422;
774 result.errorResponse = ErrorResponse::FileNotFound(filePath.string(), req.path);
775 return result;
776 }
777
778 // Validate file path against access restrictions

Callers 2

Calls 9

ValidateFilePathFunction · 0.85
whatMethod · 0.80
containsMethod · 0.80
closeMethod · 0.80
findMethod · 0.45
emptyMethod · 0.45
writeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected