From 04f1b48b006373ac82ae23a947dcb048d56cf63f Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Thu, 28 Mar 2024 14:01:22 +0100 Subject: add "fieldnames" query param for GetProjectFiles/GetProjectChunkInfos (#29) - Improvement: It is now possible to control which fields to include in `/prj/{project}/oplog/{log}/chunkinfos` request by adding a comma delimited list of filed names for `fieldnames` parameter - Default fields are: `id`, `rawhash` and `rawsize` (translates to `?fieldnames=id,rawhash,rawsize`) - Use `?fieldnames=*` to get all the fields - Improvement: It is now possible to control which fields to include in `/prj/{project}/oplog/{log}/files` request by adding a comma delimited list of filed names for `fieldnames` parameter - Default fields are: `id`, `clientpath` and `serverpath` (translates to `?fieldnames=id,clientpath,serverpath`), `filter=client` only applies if `fieldnames` is not given as a parameter - Use `?fieldnames=*` to get all the fields --- src/zenserver/projectstore/httpprojectstore.cpp | 48 +++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'src/zenserver/projectstore/httpprojectstore.cpp') diff --git a/src/zenserver/projectstore/httpprojectstore.cpp b/src/zenserver/projectstore/httpprojectstore.cpp index e8a748c4c..f2bf5b353 100644 --- a/src/zenserver/projectstore/httpprojectstore.cpp +++ b/src/zenserver/projectstore/httpprojectstore.cpp @@ -621,10 +621,31 @@ HttpProjectService::HandleFilesRequest(HttpRouterRequest& Req) HttpServerRequest::QueryParams Params = HttpReq.GetQueryParams(); - const bool FilterClient = Params.GetValue("filter"sv) == "client"sv; + std::unordered_set WantedFieldNames; + if (auto FieldFilter = HttpServerRequest::Decode(Params.GetValue("fieldnames")); !FieldFilter.empty()) + { + if (FieldFilter != "*") // Get all - empty FieldFilter equal getting all fields + { + ForEachStrTok(FieldFilter, ',', [&](std::string_view FieldName) { + WantedFieldNames.insert(std::string(FieldName)); + return true; + }); + } + } + else + { + const bool FilterClient = Params.GetValue("filter"sv) == "client"sv; + WantedFieldNames.insert("id"); + WantedFieldNames.insert("clientpath"); + if (!FilterClient) + { + WantedFieldNames.insert("serverpath"); + } + } CbObject ResponsePayload; - std::pair Result = m_ProjectStore->GetProjectFiles(ProjectId, OplogId, FilterClient, ResponsePayload); + std::pair Result = + m_ProjectStore->GetProjectFiles(ProjectId, OplogId, WantedFieldNames, ResponsePayload); if (Result.first == HttpResponseCode::OK) { if (HttpReq.AcceptContentType() == HttpContentType::kCompressedBinary) @@ -666,8 +687,29 @@ HttpProjectService::HandleChunkInfosRequest(HttpRouterRequest& Req) const auto& ProjectId = Req.GetCapture(1); const auto& OplogId = Req.GetCapture(2); + HttpServerRequest::QueryParams Params = HttpReq.GetQueryParams(); + + std::unordered_set WantedFieldNames; + if (auto FieldFilter = HttpServerRequest::Decode(Params.GetValue("fieldnames")); !FieldFilter.empty()) + { + if (FieldFilter != "*") // Get all - empty FieldFilter equal getting all fields + { + ForEachStrTok(FieldFilter, ',', [&](std::string_view FieldName) { + WantedFieldNames.insert(std::string(FieldName)); + return true; + }); + } + } + else + { + WantedFieldNames.insert("id"); + WantedFieldNames.insert("rawhash"); + WantedFieldNames.insert("rawsize"); + } + CbObject ResponsePayload; - std::pair Result = m_ProjectStore->GetProjectChunkInfos(ProjectId, OplogId, ResponsePayload); + std::pair Result = + m_ProjectStore->GetProjectChunkInfos(ProjectId, OplogId, WantedFieldNames, ResponsePayload); if (Result.first == HttpResponseCode::OK) { if (HttpReq.AcceptContentType() == HttpContentType::kCompressedBinary) -- cgit v1.2.3