diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 7d6b158..78bb48e 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -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 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(); + 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())}; } catch (const nlohmann::json::exception &e) { m_log->warn("asset identification cant be generated {}", uriResolverResponse.dump()); } - return AssetIdent; + return {}; }; std::string diff --git a/src/AyonCppApi/AyonCppApi.h b/src/AyonCppApi/AyonCppApi.h index 81cf694..79c8d3a 100644 --- a/src/AyonCppApi/AyonCppApi.h +++ b/src/AyonCppApi/AyonCppApi.h @@ -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 getAssetIdent(const nlohmann::json &uriResolverResponse); /**