Skip to content

Commit

Permalink
requesthandler: Use new global realm path in persistent data requests
Browse files Browse the repository at this point in the history
The `MigratePersistentData()` function handles migrating persistent
data on module load, and will fail if the data cannot be migrated.
  • Loading branch information
tt2468 committed Apr 23, 2024
1 parent af31f1a commit e2b8a06
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/requesthandler/RequestHandler_Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>

#include "RequestHandler.h"

#define GLOBAL_PERSISTENT_DATA_FILE_NAME "persistent_data.json"

/**
* Gets the value of a "slot" from the selected persistent data realm.
*
Expand All @@ -47,11 +49,11 @@ RequestResult RequestHandler::GetPersistentData(const Request &request)
std::string realm = request.RequestData["realm"];
std::string slotName = request.RequestData["slotName"];

std::string persistentDataPath = Utils::Obs::StringHelper::GetCurrentProfilePath();
std::string persistentDataPath;
if (realm == "OBS_WEBSOCKET_DATA_REALM_GLOBAL")
persistentDataPath += "/../../../obsWebSocketPersistentData.json";
persistentDataPath = Utils::Obs::StringHelper::GetModuleConfigPath(GLOBAL_PERSISTENT_DATA_FILE_NAME);
else if (realm == "OBS_WEBSOCKET_DATA_REALM_PROFILE")
persistentDataPath += "/obsWebSocketPersistentData.json";
persistentDataPath = Utils::Obs::StringHelper::GetCurrentProfilePath() + "/obsWebSocketPersistentData.json";
else
return RequestResult::Error(RequestStatus::ResourceNotFound,
"You have specified an invalid persistent data realm.");
Expand Down Expand Up @@ -92,16 +94,16 @@ RequestResult RequestHandler::SetPersistentData(const Request &request)
std::string slotName = request.RequestData["slotName"];
json slotValue = request.RequestData["slotValue"];

std::string persistentDataPath = Utils::Obs::StringHelper::GetCurrentProfilePath();
std::string persistentDataPath;
if (realm == "OBS_WEBSOCKET_DATA_REALM_GLOBAL")
persistentDataPath += "/../../../obsWebSocketPersistentData.json";
persistentDataPath = Utils::Obs::StringHelper::GetModuleConfigPath(GLOBAL_PERSISTENT_DATA_FILE_NAME);
else if (realm == "OBS_WEBSOCKET_DATA_REALM_PROFILE")
persistentDataPath += "/obsWebSocketPersistentData.json";
persistentDataPath = Utils::Obs::StringHelper::GetCurrentProfilePath() + "/obsWebSocketPersistentData.json";
else
return RequestResult::Error(RequestStatus::ResourceNotFound,
"You have specified an invalid persistent data realm.");

json persistentData = json::object();
json persistentData;
Utils::Json::GetJsonFileContent(persistentDataPath, persistentData);
persistentData[slotName] = slotValue;
if (!Utils::Json::SetJsonFileContent(persistentDataPath, persistentData))
Expand Down

0 comments on commit e2b8a06

Please sign in to comment.