mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Requests: Add persistent data requests
This commit is contained in:
parent
8e539d6cdb
commit
ea713ea808
@ -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},
|
||||
|
@ -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&);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user