Mercurial > hg > orthanc-databases
changeset 725:b086e69efb8c sql-opti
uniformization if exporting to b64
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Mon, 11 Aug 2025 18:44:34 +0200 |
| parents | c76a214a3954 |
| children | 2811c0d5d0b1 |
| files | Framework/Plugins/DatabaseBackendAdapterV4.cpp |
| diffstat | 1 files changed, 27 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp Mon Aug 11 18:26:08 2025 +0200 +++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp Mon Aug 11 18:44:34 2025 +0200 @@ -1617,7 +1617,19 @@ if (getArguments.find("log-data-format") != getArguments.end()) { - logDataInJson = getArguments["log-data-format"] == "json"; + const std::string format = getArguments["log-data-format"]; + if (format == "json") + { + logDataInJson = true; + } + else if (format == "base64") + { + logDataInJson = false; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, "Unsupported value for log-data-format: " + format); + } } Json::Value jsonLogs; @@ -1673,11 +1685,13 @@ serializedAuditLog["ResourceType"] = level; + bool fillBase64; if (logDataInJson) { if (it->GetLogData().empty()) { serializedAuditLog["JsonLogData"] = Json::nullValue; + fillBase64 = false; // TODO - Shouldn't this be the same behavior as (*) below? } else { @@ -1685,23 +1699,25 @@ if (Orthanc::Toolbox::ReadJson(logData, it->GetLogData())) { serializedAuditLog["JsonLogData"] = logData; + fillBase64 = false; } - else // if the data is not json compatible, export it in b64 anyway + else { - std::string b64logData; - Orthanc::Toolbox::EncodeBase64(b64logData, it->GetLogData()); - serializedAuditLog["Base64LogData"] = b64logData; + // If the data is not JSON compatible, export it in base64 anyway (*) + fillBase64 = true; } } } else { - std::string b64logData; - if (!it->GetLogData().empty()) - { - Orthanc::Toolbox::EncodeBase64(b64logData, it->GetLogData()); - } - serializedAuditLog["Base64LogData"] = b64logData; + fillBase64 = true; + } + + if (fillBase64) + { + std::string b64; + Orthanc::Toolbox::EncodeBase64(b64, it->GetLogData()); + serializedAuditLog["Base64LogData"] = b64; } jsonLogs.append(serializedAuditLog);
