Requests: Add persistent data requests

This commit is contained in:
tt2468 2021-08-26 20:32:00 -07:00
parent 8e539d6cdb
commit ea713ea808
3 changed files with 48 additions and 0 deletions

View File

@ -20,6 +20,8 @@ const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
{"SetCurrentProfile", &RequestHandler::SetCurrentProfile},
{"GetProfileParameter", &RequestHandler::GetProfileParameter},
{"SetProfileParameter", &RequestHandler::SetProfileParameter},
{"GetProfilePersistentData", &RequestHandler::GetProfilePersistentData},
{"SetProfilePersistentData", &RequestHandler::SetProfilePersistentData},
{"GetVideoSettings", &RequestHandler::GetVideoSettings},
{"SetVideoSettings", &RequestHandler::SetVideoSettings},
{"GetStreamServiceSettings", &RequestHandler::GetStreamServiceSettings},

View File

@ -35,6 +35,8 @@ class RequestHandler {
RequestResult SetCurrentProfile(const Request&);
RequestResult GetProfileParameter(const Request&);
RequestResult SetProfileParameter(const Request&);
RequestResult GetProfilePersistentData(const Request&);
RequestResult SetProfilePersistentData(const Request&);
RequestResult GetVideoSettings(const Request&);
RequestResult SetVideoSettings(const Request&);
RequestResult GetStreamServiceSettings(const Request&);

View File

@ -124,6 +124,50 @@ RequestResult RequestHandler::SetProfileParameter(const Request& request)
return RequestResult::Success();
}
RequestResult RequestHandler::GetProfilePersistentData(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
if (!request.ValidateString("slotName", statusCode, comment))
return RequestResult::Error(statusCode, comment);
std::string slotName = request.RequestData["slotName"];
std::string persistentDataPath = Utils::Obs::StringHelper::GetCurrentProfilePath();
persistentDataPath += "/obsWebSocketPersistentData.json";
json responseData;
json persistentData;
if (!(Utils::Json::GetJsonFileContent(persistentDataPath, persistentData) && persistentData.contains(slotName)))
responseData["slotData"] = nullptr;
else
responseData["slotData"] = persistentData[slotName];
return RequestResult::Success(responseData);
}
RequestResult RequestHandler::SetProfilePersistentData(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
if (!(request.ValidateString("slotName", statusCode, comment) && request.ValidateBasic("slotName", statusCode, comment)))
return RequestResult::Error(statusCode, comment);
std::string slotName = request.RequestData["slotName"];
json slotData = request.RequestData["slotData"];
std::string persistentDataPath = Utils::Obs::StringHelper::GetCurrentProfilePath();
persistentDataPath += "/obsWebSocketPersistentData.json";
json persistentData = json::object();
Utils::Json::GetJsonFileContent(persistentDataPath, persistentData);
persistentData[slotName] = slotData;
if (!Utils::Json::SetJsonFileContent(persistentDataPath, persistentData))
return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Unable to write persistent data. No permissions?");
return RequestResult::Success();
}
RequestResult RequestHandler::GetVideoSettings(const Request& request)
{
struct obs_video_info ovi;