#ifndef UTILS_HPP #define UTILS_HPP #include #include #include #include #include #include "json.hpp" #include "crow.h" namespace utils { // Svelte genereated files const std::filesystem::path build_dir = "frontend/build/"; // Non-autogenerated assets folder const std::filesystem::path assets_dir = "assets/"; std::map parseBody(const std::string& body); std::optional getBodyName(const std::string& body); std::expected isLocalPortOpen(uint16_t portno); std::string to_id_format(const std::string& s); std::string loadFile(const std::string& path); std::filesystem::path getDataDir(); std::string urlDecode(const std::string& str); std::string currentTime(); template std::string toJsonArray(const std::vector& data){ nlohmann::json arr = nlohmann::json::array(); for (auto& c : data) { arr.push_back(nlohmann::json(c)); } return arr.dump(); } std::expected parseJson(const std::string& input); template std::expected fromJson(const std::string& input) { try { return nlohmann::json::parse(input).get(); } catch (const nlohmann::json::exception& e) { return std::unexpected(e.what()); } } std::string read_file(const std::string& path); crow::response getFile(const std::filesystem::path& file_path); } #endif