diff options
Diffstat (limited to 'src/zenserver/projectstore/projectstore.cpp')
| -rw-r--r-- | src/zenserver/projectstore/projectstore.cpp | 97 |
1 files changed, 84 insertions, 13 deletions
diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp index 3d8004be3..f01134fa5 100644 --- a/src/zenserver/projectstore/projectstore.cpp +++ b/src/zenserver/projectstore/projectstore.cpp @@ -2501,7 +2501,10 @@ ProjectStore::GetProjectsList() } std::pair<HttpResponseCode, std::string> -ProjectStore::GetProjectFiles(const std::string_view ProjectId, const std::string_view OplogId, bool FilterClient, CbObject& OutPayload) +ProjectStore::GetProjectFiles(const std::string_view ProjectId, + const std::string_view OplogId, + const std::unordered_set<std::string>& WantedFieldNames, + CbObject& OutPayload) { ZEN_TRACE_CPU("Store::GetProjectFiles"); @@ -2521,17 +2524,53 @@ ProjectStore::GetProjectFiles(const std::string_view ProjectId, const std::strin } Project->TouchOplog(OplogId); + const bool WantsAllFields = WantedFieldNames.empty(); + + const bool WantsIdField = WantsAllFields || WantedFieldNames.contains("id"); + const bool WantsClientPathField = WantsAllFields || WantedFieldNames.contains("clientpath"); + const bool WantsServerPathField = WantsAllFields || WantedFieldNames.contains("serverpath"); + const bool WantsRawSizeField = WantsAllFields || WantedFieldNames.contains("rawsize"); + const bool WantsSizeField = WantsAllFields || WantedFieldNames.contains("size"); + CbObjectWriter Response; Response.BeginArray("files"sv); FoundLog->IterateFileMap([&](const Oid& Id, const std::string_view& ServerPath, const std::string_view& ClientPath) { Response.BeginObject(); - Response << "id"sv << Id; - Response << "clientpath"sv << ClientPath; - if (!FilterClient && !ServerPath.empty()) + if (WantsIdField) + { + Response << "id"sv << Id; + } + if (WantsClientPathField) + { + Response << "clientpath"sv << ClientPath; + } + if (WantsServerPathField && !ServerPath.empty()) { Response << "serverpath"sv << ServerPath; } + if (WantsRawSizeField || WantsSizeField) + { + IoBuffer Chunk = FoundLog->FindChunk(Id); + if (WantsSizeField) + { + Response << "size"sv << Chunk.GetSize(); + } + if (WantsRawSizeField) + { + if (Chunk.GetContentType() == ZenContentType::kCompressedBinary) + { + IoHash _; + uint64_t RawSize = 0; + (void)CompressedBuffer::FromCompressed(SharedBuffer(Chunk), _, RawSize); + Response << "rawsize"sv << RawSize; + } + else + { + Response << "rawsize"sv << Chunk.GetSize(); + } + } + } Response.EndObject(); }); @@ -2541,7 +2580,10 @@ ProjectStore::GetProjectFiles(const std::string_view ProjectId, const std::strin } std::pair<HttpResponseCode, std::string> -ProjectStore::GetProjectChunkInfos(const std::string_view ProjectId, const std::string_view OplogId, CbObject& OutPayload) +ProjectStore::GetProjectChunkInfos(const std::string_view ProjectId, + const std::string_view OplogId, + const std::unordered_set<std::string>& WantedFieldNames, + CbObject& OutPayload) { ZEN_TRACE_CPU("ProjectStore::GetProjectChunkInfos"); @@ -2564,25 +2606,54 @@ ProjectStore::GetProjectChunkInfos(const std::string_view ProjectId, const std:: std::vector<std::pair<Oid, IoHash>> ChunkInfos; FoundLog->IterateChunkMap([&ChunkInfos](const Oid& Id, const IoHash& Hash) { ChunkInfos.push_back({Id, Hash}); }); + const bool WantsAllFields = WantedFieldNames.empty(); + + const bool WantsIdField = WantsAllFields || WantedFieldNames.contains("id"); + const bool WantsRawHashField = WantsAllFields || WantedFieldNames.contains("rawhash"); + const bool WantsRawSizeField = WantsAllFields || WantedFieldNames.contains("rawsize"); + const bool WantsSizeField = WantsAllFields || WantedFieldNames.contains("size"); + CbObjectWriter Response; Response.BeginArray("chunkinfos"sv); for (const auto& ChunkInfo : ChunkInfos) { - if (IoBuffer Chunk = FoundLog->FindChunk(ChunkInfo.first)) + Response.BeginObject(); + if (WantsIdField) { - Response.BeginObject(); Response << "id"sv << ChunkInfo.first; + } + if (WantsRawHashField) + { Response << "rawhash"sv << ChunkInfo.second; - uint64_t RawSize = Chunk.GetSize(); - if (Chunk.GetContentType() == ZenContentType::kCompressedBinary) + } + + if (WantsRawSizeField || WantsSizeField) + { + if (IoBuffer Chunk = FoundLog->FindChunk(ChunkInfo.first)) { - IoHash _; - (void)CompressedBuffer::FromCompressed(SharedBuffer(Chunk), _, RawSize); + uint64_t Size = Chunk.GetSize(); + if (WantsSizeField) + { + Response << "size"sv << Size; + } + if (WantsRawSizeField) + { + if (Chunk.GetContentType() == ZenContentType::kCompressedBinary) + { + IoHash _; + uint64_t RawSize = 0; + (void)CompressedBuffer::FromCompressed(SharedBuffer(Chunk), _, RawSize); + Response << "rawsize"sv << RawSize; + } + else + { + Response << "rawsize"sv << Size; + } + } } - Response << "rawsize"sv << RawSize; - Response.EndObject(); } + Response.EndObject(); } Response.EndArray(); |