Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/AyonCppApi/AyonCppApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,22 +634,34 @@ AyonApi::getAssetIdent(const nlohmann::json &uriResolverResponse) {
PerfTimer("AyonApi::getAssetIdent");
m_log->info(m_log->key("AyonApi"), "AyonApi::getAssetIdent({})", uriResolverResponse.dump());

std::pair<std::string, std::string> AssetIdent;
if (uriResolverResponse.empty()) {
return AssetIdent;
return {};
}
try {
AssetIdent.first = uriResolverResponse.at("uri");
if (uriResolverResponse.at("entities").size() > 1) {
m_log->warn("Uri resolution returned more than one path: {}", uriResolverResponse.at("entities").dump());
std::string uri = uriResolverResponse.at("uri").get<std::string>();
const nlohmann::json &entities = uriResolverResponse.at("entities");
if (entities.is_array() && entities.empty()) {
return {std::move(uri), ""};
}
if (!entities.is_array() || !entities.back().is_object()) {
m_log->warn("asset identification cant be generated {}", uriResolverResponse.dump());
return {};
}
if (entities.size() > 1) {
m_log->warn("Uri resolution returned more than one path: {}", entities.dump());
}
// The server leaves filePath out when the URI names no representation.
const nlohmann::json &entity = entities.back();
const auto filePath = entity.find("filePath");
if (filePath == entity.end() || filePath->is_null()) {
return {std::move(uri), ""};
}
AssetIdent.second = rootReplace(
uriResolverResponse.at("entities").at(uriResolverResponse.at("entities").size() - 1).at("filePath"));
return {std::move(uri), rootReplace(filePath->get<std::string>())};
}
catch (const nlohmann::json::exception &e) {
m_log->warn("asset identification cant be generated {}", uriResolverResponse.dump());
}
return AssetIdent;
return {};
};

std::string
Expand Down
5 changes: 5 additions & 0 deletions src/AyonCppApi/AyonCppApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ class AyonApi {
* @param uriResolverResponse JSON representation of the response from the AYON API resolve endpoint.
* @return A pair containing the asset identifier and the machine local file location.
*/
/**
* @brief Read one entry of a resolve response.
* @return (uri, path) when resolved; (uri, "") when the server answered that it has no path;
* an empty pair when the entry cannot be read, which says nothing about whether the URI exists.
*/
std::pair<std::string, std::string> getAssetIdent(const nlohmann::json &uriResolverResponse);

/**
Expand Down
Loading