Fixed.
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 1m33s

This commit is contained in:
Your Name 2025-05-25 19:44:10 +12:00
parent e7558be416
commit 27a2d25fb2
2 changed files with 29 additions and 11 deletions

View File

@ -169,24 +169,36 @@ std::string config::get_template_create_path()
std::string config::get_backups_path() std::string config::get_backups_path()
{ {
return mConfig["backups_path"]; nlohmann::json backups_path = mConfig["backups_path"];
if (backups_path.empty())
return "";
if (backups_path.is_string())
return backups_path;
warning << "backups_path is not a string: " << backups_path << std::endl;
return "";
} }
dropshell::tRegistryEntry::tRegistryEntry(nlohmann::json json) dropshell::tRegistryEntry::tRegistryEntry(nlohmann::json json)
{ {
valid = false;
if (json.is_object() && !json.empty()) { if (json.is_object() && !json.empty()) {
for (auto &[key, value] : json.items()) { for (auto &[key, value] : json.items()) {
if (tolower(key) == "name") { if (value.is_string() && !value.empty())
name = value; switch (switchhash(key.c_str())) {
} else if (tolower(key) == "url") { case switchhash("name"):
url = value; name = value;
} else if (tolower(key) == "token") { break;
token = value; case switchhash("url"):
url = value;
break;
case switchhash("token"):
token = value;
break;
default:
break;
}
} }
} valid = (!url.empty()&&!name.empty()); // token can be empty.
valid = true;
} else {
valid = false;
} }
} }

View File

@ -69,4 +69,10 @@ std::string get_string_from_url(const std::string& url);
// replace or append a block of text to a file, matching first and last lines if replacing. // replace or append a block of text to a file, matching first and last lines if replacing.
bool file_replace_or_add_segment(std::string filepath, std::string segment); bool file_replace_or_add_segment(std::string filepath, std::string segment);
constexpr unsigned int switchhash(const char *s, int off = 0)
{
return !s[off] ? 5381 : (switchhash(s, off + 1) * 33) ^ s[off];
}
} // namespace dropshell } // namespace dropshell