NOTE: This is for the argument system for now. This might get replaced completely with the Queue System in the future. */
| 321 | NOTE: This is for the argument system for now. This might get replaced completely with the Queue System in the future. |
| 322 | */ |
| 323 | Result ScriptUtils::runFunctions(nlohmann::json storeJson, int selection, const std::string &entry) { |
| 324 | Result ret = NONE; // No Error as of yet. |
| 325 | |
| 326 | if (!storeJson.contains("storeContent")) { Msg::waitMsg(Lang::get("SYNTAX_ERROR")); return SYNTAX_ERROR; }; |
| 327 | if ((int)storeJson["storeContent"].size() < selection) { Msg::waitMsg(Lang::get("SYNTAX_ERROR")); return SYNTAX_ERROR; }; |
| 328 | if (!storeJson["storeContent"][selection].contains(entry)) { Msg::waitMsg(Lang::get("SYNTAX_ERROR")); return SYNTAX_ERROR; }; |
| 329 | |
| 330 | nlohmann::json Script = nullptr; |
| 331 | |
| 332 | /* Detect if array or new object thing. Else return Syntax error. :P */ |
| 333 | if (storeJson["storeContent"][selection][entry].type() == nlohmann::json::value_t::array) { |
| 334 | Script = storeJson["storeContent"][selection][entry]; |
| 335 | |
| 336 | } else if (storeJson["storeContent"][selection][entry].type() == nlohmann::json::value_t::object) { |
| 337 | if (storeJson["storeContent"][selection][entry].contains("script") && storeJson["storeContent"][selection][entry]["script"].is_array()) { |
| 338 | Script = storeJson["storeContent"][selection][entry]["script"]; |
| 339 | |
| 340 | } else { |
| 341 | Msg::waitMsg(Lang::get("SYNTAX_ERROR")); |
| 342 | return SYNTAX_ERROR; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | |
| 347 | for(int i = 0; i < (int)Script.size(); i++) { |
| 348 | if (ret == NONE) { |
| 349 | std::string type = ""; |
| 350 | |
| 351 | if (Script[i].contains("type") && Script[i]["type"].is_string()) { |
| 352 | type = Script[i]["type"]; |
| 353 | |
| 354 | } else { |
| 355 | ret = SYNTAX_ERROR; |
| 356 | } |
| 357 | |
| 358 | if (type == "deleteFile") { |
| 359 | bool missing = false; |
| 360 | std::string file = ""; |
| 361 | |
| 362 | |
| 363 | if (Script[i].contains("file") && Script[i]["file"].is_string()) { |
| 364 | file = Script[i]["file"]; |
| 365 | } |
| 366 | else missing = true; |
| 367 | |
| 368 | if (!missing) ret = ScriptUtils::removeFile(file, true); |
| 369 | else ret = SYNTAX_ERROR; |
| 370 | |
| 371 | } else if (type == "downloadFile") { |
| 372 | bool missing = false; |
| 373 | std::string file = "", output = ""; |
| 374 | |
| 375 | if (Script[i].contains("file") && Script[i]["file"].is_string()) { |
| 376 | file = Script[i]["file"]; |
| 377 | } |
| 378 | else missing = true; |
| 379 | |
| 380 | if (Script[i].contains("output") && Script[i]["output"].is_string()) { |
nothing calls this directly
no test coverage detected