refactor
This commit is contained in:
parent
365e83e15d
commit
3c2b113fcd
@ -4,6 +4,7 @@
|
|||||||
#include "utils/config.hpp"
|
#include "utils/config.hpp"
|
||||||
|
|
||||||
namespace monitarr {
|
namespace monitarr {
|
||||||
|
struct app_config;
|
||||||
struct server_cfg;
|
struct server_cfg;
|
||||||
class data_db;
|
class data_db;
|
||||||
|
|
||||||
@ -15,6 +16,8 @@ class data_db;
|
|||||||
|
|
||||||
[[nodiscard]] auto list_queue(const server_cfg &server) -> int;
|
[[nodiscard]] auto list_queue(const server_cfg &server) -> int;
|
||||||
|
|
||||||
|
[[nodiscard]] auto load_config(std::string &cfg_file) -> app_config;
|
||||||
|
|
||||||
void remove_stalled(std::string_view download_id, std::string_view title,
|
void remove_stalled(std::string_view download_id, std::string_view title,
|
||||||
std::uint64_t episode_id, std::uint64_t movie_id,
|
std::uint64_t episode_id, std::uint64_t movie_id,
|
||||||
const server_cfg &server, data_db *state_db = nullptr);
|
const server_cfg &server, data_db *state_db = nullptr);
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
#include "data_db.hpp"
|
#include "data_db.hpp"
|
||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
|
#include "utils/common.hpp"
|
||||||
#include "utils/error.hpp"
|
#include "utils/error.hpp"
|
||||||
#include "utils/string.hpp"
|
#include "utils/string.hpp"
|
||||||
|
#include "utils/unix.hpp"
|
||||||
|
#include "utils/windows.hpp"
|
||||||
|
|
||||||
namespace monitarr {
|
namespace monitarr {
|
||||||
auto create_client(const server_cfg &server) -> httplib::Client {
|
auto create_client(const server_cfg &server) -> httplib::Client {
|
||||||
@ -88,6 +91,32 @@ auto list_queue(const server_cfg &server) -> int {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto load_config(std::string &cfg_file) -> app_config {
|
||||||
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
|
auto cfg_dir = utils::get_environment_variable("MONITARR_CFG_DIR");
|
||||||
|
if (cfg_dir.empty()) {
|
||||||
|
cfg_dir = utils::path::combine(".", {"config"});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not utils::file::directory{cfg_dir}.create_directory()) {
|
||||||
|
throw std::runtime_error(fmt::format("failed to create config dir|{}",
|
||||||
|
cfg_dir,
|
||||||
|
utils::get_last_error_code()));
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg_file = utils::path::combine(cfg_dir, {"monitarr.json"});
|
||||||
|
|
||||||
|
utils::error::handle_info(function_name,
|
||||||
|
fmt::format("loading config|{}", cfg_file));
|
||||||
|
app_config cfg{};
|
||||||
|
cfg.load(cfg_file);
|
||||||
|
if (not utils::file::file{cfg_file}.exists()) {
|
||||||
|
cfg.save(cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
void remove_stalled(std::string_view download_id, std::string_view title,
|
void remove_stalled(std::string_view download_id, std::string_view title,
|
||||||
std::uint64_t episode_id, std::uint64_t movie_id,
|
std::uint64_t episode_id, std::uint64_t movie_id,
|
||||||
const server_cfg &server, data_db *state_db) {
|
const server_cfg &server, data_db *state_db) {
|
||||||
@ -148,5 +177,4 @@ void remove_stalled(std::string_view download_id, std::string_view title,
|
|||||||
episode_id, response->status));
|
episode_id, response->status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace monitarr
|
} // namespace monitarr
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "initialize.hpp"
|
#include "initialize.hpp"
|
||||||
|
|
||||||
|
#include "actions.hpp"
|
||||||
#include "args.hpp"
|
#include "args.hpp"
|
||||||
#include "block_cmd.hpp"
|
#include "block_cmd.hpp"
|
||||||
#include "config_cmd.hpp"
|
#include "config_cmd.hpp"
|
||||||
@ -12,39 +13,7 @@
|
|||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
#include "show_cmd.hpp"
|
#include "show_cmd.hpp"
|
||||||
#include "usage_cmd.hpp"
|
#include "usage_cmd.hpp"
|
||||||
#include "utils/common.hpp"
|
|
||||||
#include "utils/file.hpp"
|
#include "utils/file.hpp"
|
||||||
#include "utils/unix.hpp"
|
|
||||||
#include "utils/windows.hpp"
|
|
||||||
|
|
||||||
namespace monitarr {
|
|
||||||
[[nodiscard]] static auto load_config(std::string &cfg_file) -> app_config {
|
|
||||||
MONITARR_USES_FUNCTION_NAME();
|
|
||||||
|
|
||||||
auto cfg_dir = utils::get_environment_variable("MONITARR_CFG_DIR");
|
|
||||||
if (cfg_dir.empty()) {
|
|
||||||
cfg_dir = utils::path::combine(".", {"config"});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not utils::file::directory{cfg_dir}.create_directory()) {
|
|
||||||
throw std::runtime_error(fmt::format("failed to create config dir|{}",
|
|
||||||
cfg_dir,
|
|
||||||
utils::get_last_error_code()));
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg_file = utils::path::combine(cfg_dir, {"monitarr.json"});
|
|
||||||
|
|
||||||
utils::error::handle_info(function_name,
|
|
||||||
fmt::format("loading config|{}", cfg_file));
|
|
||||||
app_config cfg{};
|
|
||||||
cfg.load(cfg_file);
|
|
||||||
if (not utils::file::file{cfg_file}.exists()) {
|
|
||||||
cfg.save(cfg_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg;
|
|
||||||
}
|
|
||||||
} // namespace monitarr
|
|
||||||
|
|
||||||
using namespace monitarr;
|
using namespace monitarr;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user