Subsonic API: do not report numeric values as strings
This commit is contained in:
@@ -46,6 +46,15 @@ ResponseFormatToMimeType(ResponseFormat format)
|
||||
|
||||
void
|
||||
Response::Node::setValue(std::string_view value)
|
||||
{
|
||||
if (!_children.empty() || !_childrenArrays.empty())
|
||||
throw LmsException {"Node already has children"};
|
||||
|
||||
_value = std::string {value};
|
||||
}
|
||||
|
||||
void
|
||||
Response::Node::setValue(long long value)
|
||||
{
|
||||
if (!_children.empty() || !_childrenArrays.empty())
|
||||
throw LmsException {"Node already has children"};
|
||||
@@ -55,6 +64,12 @@ Response::Node::setValue(std::string_view value)
|
||||
|
||||
void
|
||||
Response::Node::setAttribute(std::string_view key, std::string_view value)
|
||||
{
|
||||
_attributes[std::string {key}] = std::string {value};
|
||||
}
|
||||
|
||||
void
|
||||
Response::Node::setAttribute(std::string_view key, long long value)
|
||||
{
|
||||
_attributes[std::string {key}] = value;
|
||||
}
|
||||
@@ -62,7 +77,7 @@ Response::Node::setAttribute(std::string_view key, std::string_view value)
|
||||
void
|
||||
Response::Node::addChild(const std::string& key, Node node)
|
||||
{
|
||||
if (!_value.empty())
|
||||
if (_value.valueless_by_exception())
|
||||
throw LmsException {"Node already has a value"};
|
||||
|
||||
_children[key].emplace_back(std::move(node));
|
||||
@@ -71,7 +86,7 @@ Response::Node::addChild(const std::string& key, Node node)
|
||||
void
|
||||
Response::Node::addArrayChild(const std::string& key, Node node)
|
||||
{
|
||||
if (!_value.empty())
|
||||
if (_value.valueless_by_exception())
|
||||
throw LmsException {"Node already has a value"};
|
||||
|
||||
_childrenArrays[key].emplace_back(std::move(node));
|
||||
@@ -160,11 +175,19 @@ Response::writeXML(std::ostream& os)
|
||||
boost::property_tree::ptree res;
|
||||
|
||||
for (auto itAttribute : node._attributes)
|
||||
res.put("<xmlattr>." + itAttribute.first, itAttribute.second);
|
||||
|
||||
if (!node._value.empty())
|
||||
{
|
||||
res.put_value(node._value);
|
||||
if (std::holds_alternative<std::string>(itAttribute.second))
|
||||
res.put("<xmlattr>." + itAttribute.first, std::get<std::string>(itAttribute.second));
|
||||
else if (std::holds_alternative<long long>(itAttribute.second))
|
||||
res.put("<xmlattr>." + itAttribute.first, std::get<long long>(itAttribute.second));
|
||||
}
|
||||
|
||||
if (node._value.valueless_by_exception())
|
||||
{
|
||||
if (std::holds_alternative<std::string>(node._value))
|
||||
res.put_value(std::get<std::string>(node._value));
|
||||
else if (std::holds_alternative<long long>(node._value))
|
||||
res.put_value(std::get<long long>(node._value));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -200,11 +223,19 @@ Response::writeJSON(std::ostream& os)
|
||||
Json::Object res;
|
||||
|
||||
for (auto itAttribute : node._attributes)
|
||||
res[itAttribute.first] = Json::Value {itAttribute.second};
|
||||
|
||||
if (!node._value.empty())
|
||||
{
|
||||
res["value"] = Json::Value {node._value};
|
||||
if (std::holds_alternative<std::string>(itAttribute.second))
|
||||
res[itAttribute.first] = Json::Value {std::get<std::string>(itAttribute.second)};
|
||||
else if (std::holds_alternative<long long>(itAttribute.second))
|
||||
res[itAttribute.first] = Json::Value {std::get<long long>(itAttribute.second)};
|
||||
}
|
||||
|
||||
if (node._value.valueless_by_exception())
|
||||
{
|
||||
if (std::holds_alternative<std::string>(node._value))
|
||||
res["value"] = Json::Value {std::get<std::string>(node._value)};
|
||||
else if (std::holds_alternative<long long>(node._value))
|
||||
res["value"] = Json::Value {std::get<long long>(node._value)};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user