refactor
This commit is contained in:
parent
428fcacc18
commit
42a9ed9b44
23
monitarr/monitarr/include/actions.hpp
Normal file
23
monitarr/monitarr/include/actions.hpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef LIBMONITARR_INCLUDE_ACTIONS_HPP_
|
||||||
|
#define LIBMONITARR_INCLUDE_ACTIONS_HPP_
|
||||||
|
|
||||||
|
#include "utils/config.hpp"
|
||||||
|
|
||||||
|
namespace monitarr {
|
||||||
|
struct server_cfg;
|
||||||
|
class data_db;
|
||||||
|
|
||||||
|
[[nodiscard]] auto create_client(const server_cfg &server) -> httplib::Client;
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_download(std::uint64_t record_id,
|
||||||
|
const server_cfg &server)
|
||||||
|
-> std::optional<nlohmann::json>;
|
||||||
|
|
||||||
|
[[nodiscard]] auto list_queue(const server_cfg &server) -> int;
|
||||||
|
|
||||||
|
void remove_stalled(std::string_view download_id, std::string_view title,
|
||||||
|
std::uint64_t episode_id, std::uint64_t movie_id,
|
||||||
|
const server_cfg &server, data_db *state_db = nullptr);
|
||||||
|
} // namespace monitarr
|
||||||
|
|
||||||
|
#endif // LIBMONITARR_INCLUDE_ACTIONS_HPP_
|
13
monitarr/monitarr/include/block_cmd.hpp
Normal file
13
monitarr/monitarr/include/block_cmd.hpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef LIBMONITARR_INCLUDE_BLOCK_CMD_HPP_
|
||||||
|
#define LIBMONITARR_INCLUDE_BLOCK_CMD_HPP_
|
||||||
|
|
||||||
|
#include "utils/config.hpp"
|
||||||
|
|
||||||
|
namespace monitarr {
|
||||||
|
struct app_config;
|
||||||
|
|
||||||
|
[[nodiscard]] auto block_cmd(int argc, char **argv, const app_config &cfg)
|
||||||
|
-> int;
|
||||||
|
} // namespace monitarr
|
||||||
|
|
||||||
|
#endif // LIBMONITARR_INCLUDE_BLOCK_CMD_HPP_
|
12
monitarr/monitarr/include/config_cmd.hpp
Normal file
12
monitarr/monitarr/include/config_cmd.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef LIBMONITARR_INCLUDE_CONFIG_CMD_HPP_
|
||||||
|
#define LIBMONITARR_INCLUDE_CONFIG_CMD_HPP_
|
||||||
|
|
||||||
|
#include "utils/config.hpp"
|
||||||
|
|
||||||
|
namespace monitarr {
|
||||||
|
struct app_config;
|
||||||
|
|
||||||
|
[[nodiscard]] auto config_cmd(const app_config &cfg) -> int;
|
||||||
|
} // namespace monitarr
|
||||||
|
|
||||||
|
#endif // LIBMONITARR_INCLUDE_CONFIG_CMD_HPP_
|
13
monitarr/monitarr/include/list_cmd.hpp
Normal file
13
monitarr/monitarr/include/list_cmd.hpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef LIBMONITARR_INCLUDE_LIST_CMD_HPP_
|
||||||
|
#define LIBMONITARR_INCLUDE_LIST_CMD_HPP_
|
||||||
|
|
||||||
|
#include "utils/config.hpp"
|
||||||
|
|
||||||
|
namespace monitarr {
|
||||||
|
struct app_config;
|
||||||
|
|
||||||
|
[[nodiscard]] auto list_cmd(int argc, char **argv, const app_config &cfg)
|
||||||
|
-> int;
|
||||||
|
} // namespace monitarr
|
||||||
|
|
||||||
|
#endif // LIBMONITARR_INCLUDE_LIST_CMD_HPP_
|
13
monitarr/monitarr/include/show_cmd.hpp
Normal file
13
monitarr/monitarr/include/show_cmd.hpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef LIBMONITARR_INCLUDE_SHOW_CMD_HPP_
|
||||||
|
#define LIBMONITARR_INCLUDE_SHOW_CMD_HPP_
|
||||||
|
|
||||||
|
#include "utils/config.hpp"
|
||||||
|
|
||||||
|
namespace monitarr {
|
||||||
|
struct app_config;
|
||||||
|
|
||||||
|
[[nodiscard]] auto show_cmd(int argc, char **argv, const app_config &cfg)
|
||||||
|
-> int;
|
||||||
|
} // namespace monitarr
|
||||||
|
|
||||||
|
#endif // LIBMONITARR_INCLUDE_SHOW_CMD_HPP_
|
@ -6,162 +6,24 @@
|
|||||||
|
|
||||||
#include "initialize.hpp"
|
#include "initialize.hpp"
|
||||||
|
|
||||||
|
#include "actions.hpp"
|
||||||
#include "args.hpp"
|
#include "args.hpp"
|
||||||
|
#include "block_cmd.hpp"
|
||||||
|
#include "config_cmd.hpp"
|
||||||
#include "data_db.hpp"
|
#include "data_db.hpp"
|
||||||
|
#include "list_cmd.hpp"
|
||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
|
#include "show_cmd.hpp"
|
||||||
#include "utils/common.hpp"
|
#include "utils/common.hpp"
|
||||||
#include "utils/config.hpp"
|
#include "utils/config.hpp"
|
||||||
#include "utils/file.hpp"
|
#include "utils/file.hpp"
|
||||||
#include "utils/path.hpp"
|
#include "utils/path.hpp"
|
||||||
|
#include "utils/string.hpp"
|
||||||
#include "utils/time.hpp"
|
#include "utils/time.hpp"
|
||||||
#include "utils/unix.hpp"
|
#include "utils/unix.hpp"
|
||||||
#include "utils/windows.hpp"
|
#include "utils/windows.hpp"
|
||||||
|
|
||||||
namespace monitarr {
|
namespace monitarr {
|
||||||
[[nodiscard]] static auto create_client(const server_cfg &server)
|
|
||||||
-> httplib::Client {
|
|
||||||
httplib::Client cli{server.url};
|
|
||||||
cli.set_default_headers({
|
|
||||||
{"X-Api-Key", server.api_key},
|
|
||||||
});
|
|
||||||
|
|
||||||
return cli;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void remove_stalled(std::string_view download_id, std::string_view title,
|
|
||||||
std::uint64_t episode_id, std::uint64_t movie_id,
|
|
||||||
const server_cfg &server,
|
|
||||||
data_db *state_db = nullptr) {
|
|
||||||
MONITARR_USES_FUNCTION_NAME();
|
|
||||||
|
|
||||||
fmt::println("remove and block {}|{}|{}|{}", server.id, server.url, title,
|
|
||||||
download_id);
|
|
||||||
|
|
||||||
if (state_db != nullptr) {
|
|
||||||
state_db->remove(download_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto cli = create_client(server);
|
|
||||||
auto response = cli.Delete(
|
|
||||||
fmt::format("/api/{}/queue/{}?blocklist=true&skipRedownload=false",
|
|
||||||
server.api_version,
|
|
||||||
utils::string::split(download_id, '/', false).at(1U)));
|
|
||||||
if (response->status != httplib::StatusCode::OK_200) {
|
|
||||||
utils::error::handle_error(
|
|
||||||
function_name, fmt::format("failed to delete download|{}|{}|{}",
|
|
||||||
server.id, server.url, response->status));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (utils::string::contains("radarr", server.id)) {
|
|
||||||
nlohmann::json data({
|
|
||||||
{"name", "MoviesSearch"},
|
|
||||||
{"movieIds", {movie_id}},
|
|
||||||
});
|
|
||||||
|
|
||||||
response = cli.Post(fmt::format("/api/{}/command", server.api_version),
|
|
||||||
data.dump(), "application/json");
|
|
||||||
if (response->status != httplib::StatusCode::Created_201) {
|
|
||||||
utils::error::handle_error(function_name,
|
|
||||||
fmt::format("failed to search|{}|{}|{}|{}|{}",
|
|
||||||
server.id, server.url, title,
|
|
||||||
movie_id, response->status));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not utils::string::contains("sonarr", server.id)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nlohmann::json data({
|
|
||||||
{"name", "EpisodeSearch"},
|
|
||||||
{"episodeIds", {episode_id}},
|
|
||||||
});
|
|
||||||
|
|
||||||
response = cli.Post(fmt::format("/api/{}/command", server.api_version),
|
|
||||||
data.dump(), "application/json");
|
|
||||||
if (response->status != httplib::StatusCode::Created_201) {
|
|
||||||
utils::error::handle_error(function_name,
|
|
||||||
fmt::format("failed to search|{}|{}|{}|{}|{}",
|
|
||||||
server.id, server.url, title,
|
|
||||||
episode_id, response->status));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void display_queue(const server_cfg &server) {
|
|
||||||
MONITARR_USES_FUNCTION_NAME();
|
|
||||||
|
|
||||||
auto cli = create_client(server);
|
|
||||||
|
|
||||||
std::uint16_t page{0U};
|
|
||||||
while (++page != 0U) {
|
|
||||||
httplib::Params params;
|
|
||||||
params.emplace("page", std::to_string(page));
|
|
||||||
params.emplace("pageSize", "100");
|
|
||||||
|
|
||||||
auto response =
|
|
||||||
cli.Get(fmt::format("/api/{}/queue", server.api_version), params, {});
|
|
||||||
if (response->status != httplib::StatusCode::OK_200) {
|
|
||||||
utils::error::handle_error(
|
|
||||||
function_name, fmt::format("check server request failed|{}|{}|{}",
|
|
||||||
server.id, server.url, response->status));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto json_data = nlohmann::json::parse(response->body);
|
|
||||||
if (json_data.at("page").get<std::uint32_t>() != page) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &record : json_data.at("records")) {
|
|
||||||
fmt::println("{}", record.dump(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] static auto get_download(std::uint64_t record_id,
|
|
||||||
const server_cfg &server)
|
|
||||||
-> std::optional<nlohmann::json> {
|
|
||||||
MONITARR_USES_FUNCTION_NAME();
|
|
||||||
|
|
||||||
auto cli = create_client(server);
|
|
||||||
|
|
||||||
std::uint16_t page{0U};
|
|
||||||
while (++page != 0U) {
|
|
||||||
httplib::Params params;
|
|
||||||
params.emplace("page", std::to_string(page));
|
|
||||||
params.emplace("pageSize", "100");
|
|
||||||
|
|
||||||
auto response =
|
|
||||||
cli.Get(fmt::format("/api/{}/queue", server.api_version), params, {});
|
|
||||||
if (response->status != httplib::StatusCode::OK_200) {
|
|
||||||
utils::error::handle_error(
|
|
||||||
function_name, fmt::format("check server request failed|{}|{}|{}",
|
|
||||||
server.id, server.url, response->status));
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto json_data = nlohmann::json::parse(response->body);
|
|
||||||
if (json_data.at("page").get<std::uint32_t>() != page) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto iter = std::ranges::find_if(
|
|
||||||
json_data.at("records"),
|
|
||||||
[&record_id](const nlohmann::json &record) -> bool {
|
|
||||||
return record_id == record.at("id").get<std::uint64_t>();
|
|
||||||
});
|
|
||||||
if (iter == json_data.at("records").end()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *iter;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void check_server(const server_cfg &server, data_db &state_db) {
|
static void check_server(const server_cfg &server, data_db &state_db) {
|
||||||
MONITARR_USES_FUNCTION_NAME();
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
@ -299,53 +161,24 @@ auto main(int argc, char **argv) -> int {
|
|||||||
try {
|
try {
|
||||||
std::string cfg_file;
|
std::string cfg_file;
|
||||||
auto cfg{load_config(cfg_file)};
|
auto cfg{load_config(cfg_file)};
|
||||||
if (has_arg("-d", argc, argv)) {
|
if (has_arg("-b", argc, argv)) {
|
||||||
fmt::println("{}", nlohmann::json(cfg).dump(2));
|
ret = block_cmd(argc, argv, cfg);
|
||||||
|
} else if (has_arg("-c", argc, argv)) {
|
||||||
|
ret = config_cmd(cfg);
|
||||||
} else if (has_arg("-h", argc, argv)) {
|
} else if (has_arg("-h", argc, argv)) {
|
||||||
fmt::println("usage:");
|
fmt::println("usage:");
|
||||||
fmt::println("monitarr -d");
|
fmt::println("monitarr -b -i <index> -id <record id>");
|
||||||
|
fmt::println("\tblocklist and search record id at configuration index");
|
||||||
|
fmt::println("monitarr -c");
|
||||||
fmt::println("\tdisplay configuration");
|
fmt::println("\tdisplay configuration");
|
||||||
fmt::println("monitarr -l -i <index>");
|
fmt::println("monitarr -l -i <index>");
|
||||||
fmt::println("\tdisplay server queue at configuration index");
|
fmt::println("\tdisplay server queue at configuration index");
|
||||||
fmt::println("monitarr -b -i <index> -id <record id>");
|
|
||||||
fmt::println("\tblocklist and search record id at configuration index");
|
|
||||||
fmt::println("monitarr -s -i <index> -id <record id>");
|
fmt::println("monitarr -s -i <index> -id <record id>");
|
||||||
fmt::println("\tshow record id details at configuration index");
|
fmt::println("\tshow record id details at configuration index");
|
||||||
} else if (has_arg("-l", argc, argv)) {
|
} else if (has_arg("-l", argc, argv)) {
|
||||||
auto idx = get_arg("-i", argc, argv);
|
ret = list_cmd(argc, argv, cfg);
|
||||||
if (idx.has_value()) {
|
|
||||||
auto &server = cfg.server_list.at(utils::string::to_uint64(*idx));
|
|
||||||
fmt::println("queue|{}|{}", server.id, server.url);
|
|
||||||
display_queue(server);
|
|
||||||
}
|
|
||||||
} else if (has_arg("-b", argc, argv)) {
|
|
||||||
auto idx = get_arg("-i", argc, argv);
|
|
||||||
if (idx.has_value()) {
|
|
||||||
auto &server = cfg.server_list.at(utils::string::to_uint64(*idx));
|
|
||||||
auto record_id = get_arg("-id", argc, argv);
|
|
||||||
if (record_id.has_value()) {
|
|
||||||
auto entry =
|
|
||||||
get_download(utils::string::to_uint64(*record_id), server);
|
|
||||||
if (entry.has_value()) {
|
|
||||||
remove_stalled(fmt::format("{}/{}", server.id, *record_id),
|
|
||||||
entry->at("title").get<std::string>(), 0U,
|
|
||||||
entry->at("movieId").get<std::uint64_t>(), server);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (has_arg("-s", argc, argv)) {
|
} else if (has_arg("-s", argc, argv)) {
|
||||||
auto idx = get_arg("-i", argc, argv);
|
ret = show_cmd(argc, argv, cfg);
|
||||||
if (idx.has_value()) {
|
|
||||||
auto &server = cfg.server_list.at(utils::string::to_uint64(*idx));
|
|
||||||
auto record_id = get_arg("-id", argc, argv);
|
|
||||||
if (record_id.has_value()) {
|
|
||||||
auto entry =
|
|
||||||
get_download(utils::string::to_uint64(*record_id), server);
|
|
||||||
if (entry.has_value()) {
|
|
||||||
fmt::println("{}", entry->dump(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (const std::exception &ex) {
|
} catch (const std::exception &ex) {
|
||||||
utils::error::handle_exception(function_name, ex);
|
utils::error::handle_exception(function_name, ex);
|
||||||
@ -368,7 +201,9 @@ auto main(int argc, char **argv) -> int {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::signal(SIGINT, quit_handler);
|
std::signal(SIGINT, quit_handler);
|
||||||
|
#if !defined(_WIN32)
|
||||||
std::signal(SIGQUIT, quit_handler);
|
std::signal(SIGQUIT, quit_handler);
|
||||||
|
#endif // !defined(_WIN32)
|
||||||
std::signal(SIGTERM, quit_handler);
|
std::signal(SIGTERM, quit_handler);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
151
monitarr/monitarr/src/actions.cpp
Normal file
151
monitarr/monitarr/src/actions.cpp
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
#include "actions.hpp"
|
||||||
|
|
||||||
|
#include "data_db.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
#include "utils/error.hpp"
|
||||||
|
#include "utils/string.hpp"
|
||||||
|
|
||||||
|
namespace monitarr {
|
||||||
|
auto create_client(const server_cfg &server) -> httplib::Client {
|
||||||
|
httplib::Client cli{server.url};
|
||||||
|
cli.set_default_headers({
|
||||||
|
{"X-Api-Key", server.api_key},
|
||||||
|
});
|
||||||
|
|
||||||
|
return cli;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto get_download(std::uint64_t record_id, const server_cfg &server)
|
||||||
|
-> std::optional<nlohmann::json> {
|
||||||
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
|
auto cli = create_client(server);
|
||||||
|
|
||||||
|
std::uint16_t page{0U};
|
||||||
|
while (++page != 0U) {
|
||||||
|
httplib::Params params;
|
||||||
|
params.emplace("page", std::to_string(page));
|
||||||
|
params.emplace("pageSize", "100");
|
||||||
|
|
||||||
|
auto response =
|
||||||
|
cli.Get(fmt::format("/api/{}/queue", server.api_version), params, {});
|
||||||
|
if (response->status != httplib::StatusCode::OK_200) {
|
||||||
|
utils::error::handle_error(
|
||||||
|
function_name, fmt::format("check server request failed|{}|{}|{}",
|
||||||
|
server.id, server.url, response->status));
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto json_data = nlohmann::json::parse(response->body);
|
||||||
|
if (json_data.at("page").get<std::uint32_t>() != page) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto iter = std::ranges::find_if(
|
||||||
|
json_data.at("records"),
|
||||||
|
[&record_id](const nlohmann::json &record) -> bool {
|
||||||
|
return record_id == record.at("id").get<std::uint64_t>();
|
||||||
|
});
|
||||||
|
if (iter == json_data.at("records").end()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *iter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto list_queue(const server_cfg &server) -> int {
|
||||||
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
|
auto cli = create_client(server);
|
||||||
|
|
||||||
|
std::uint16_t page{0U};
|
||||||
|
while (++page != 0U) {
|
||||||
|
httplib::Params params;
|
||||||
|
params.emplace("page", std::to_string(page));
|
||||||
|
params.emplace("pageSize", "100");
|
||||||
|
|
||||||
|
auto response =
|
||||||
|
cli.Get(fmt::format("/api/{}/queue", server.api_version), params, {});
|
||||||
|
if (response->status != httplib::StatusCode::OK_200) {
|
||||||
|
utils::error::handle_error(
|
||||||
|
function_name, fmt::format("check server request failed|{}|{}|{}",
|
||||||
|
server.id, server.url, response->status));
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto json_data = nlohmann::json::parse(response->body);
|
||||||
|
if (json_data.at("page").get<std::uint32_t>() != page) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
utils::error::handle_info(
|
||||||
|
function_name, fmt::format("{}", json_data.at("records").dump(2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove_stalled(std::string_view download_id, std::string_view title,
|
||||||
|
std::uint64_t episode_id, std::uint64_t movie_id,
|
||||||
|
const server_cfg &server, data_db *state_db) {
|
||||||
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
|
fmt::println("remove and block {}|{}|{}|{}", server.id, server.url, title,
|
||||||
|
download_id);
|
||||||
|
|
||||||
|
if (state_db != nullptr) {
|
||||||
|
state_db->remove(download_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto cli = create_client(server);
|
||||||
|
auto response = cli.Delete(
|
||||||
|
fmt::format("/api/{}/queue/{}?blocklist=true&skipRedownload=false",
|
||||||
|
server.api_version,
|
||||||
|
utils::string::split(download_id, '/', false).at(1U)));
|
||||||
|
if (response->status != httplib::StatusCode::OK_200) {
|
||||||
|
utils::error::handle_error(
|
||||||
|
function_name, fmt::format("failed to delete download|{}|{}|{}",
|
||||||
|
server.id, server.url, response->status));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (utils::string::contains("radarr", server.id)) {
|
||||||
|
nlohmann::json data({
|
||||||
|
{"name", "MoviesSearch"},
|
||||||
|
{"movieIds", {movie_id}},
|
||||||
|
});
|
||||||
|
|
||||||
|
response = cli.Post(fmt::format("/api/{}/command", server.api_version),
|
||||||
|
data.dump(), "application/json");
|
||||||
|
if (response->status != httplib::StatusCode::Created_201) {
|
||||||
|
utils::error::handle_error(function_name,
|
||||||
|
fmt::format("failed to search|{}|{}|{}|{}|{}",
|
||||||
|
server.id, server.url, title,
|
||||||
|
movie_id, response->status));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not utils::string::contains("sonarr", server.id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json data({
|
||||||
|
{"name", "EpisodeSearch"},
|
||||||
|
{"episodeIds", {episode_id}},
|
||||||
|
});
|
||||||
|
|
||||||
|
response = cli.Post(fmt::format("/api/{}/command", server.api_version),
|
||||||
|
data.dump(), "application/json");
|
||||||
|
if (response->status != httplib::StatusCode::Created_201) {
|
||||||
|
utils::error::handle_error(function_name,
|
||||||
|
fmt::format("failed to search|{}|{}|{}|{}|{}",
|
||||||
|
server.id, server.url, title,
|
||||||
|
episode_id, response->status));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace monitarr
|
38
monitarr/monitarr/src/block_cmd.cpp
Normal file
38
monitarr/monitarr/src/block_cmd.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include "block_cmd.hpp"
|
||||||
|
|
||||||
|
#include "actions.hpp"
|
||||||
|
#include "args.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
#include "utils/error.hpp"
|
||||||
|
#include "utils/string.hpp"
|
||||||
|
|
||||||
|
namespace monitarr {
|
||||||
|
auto block_cmd(int argc, char **argv, const app_config &cfg) -> int {
|
||||||
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
|
auto idx = get_arg("-i", argc, argv);
|
||||||
|
if (not idx.has_value()) {
|
||||||
|
utils::error::handle_error(function_name, "'-i <index>' is required");
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &server = cfg.server_list.at(utils::string::to_uint64(*idx));
|
||||||
|
auto record_id = get_arg("-id", argc, argv);
|
||||||
|
if (not record_id.has_value()) {
|
||||||
|
utils::error::handle_error(function_name, "'-id <record id>' is required");
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto entry = get_download(utils::string::to_uint64(*record_id), server);
|
||||||
|
if (not entry.has_value()) {
|
||||||
|
utils::error::handle_error(function_name,
|
||||||
|
fmt::format("record {} not found", *record_id));
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_stalled(fmt::format("{}/{}", server.id, *record_id),
|
||||||
|
entry->at("title").get<std::string>(), 0U,
|
||||||
|
entry->at("movieId").get<std::uint64_t>(), server);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} // namespace monitarr
|
15
monitarr/monitarr/src/config_cmd.cpp
Normal file
15
monitarr/monitarr/src/config_cmd.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "list_cmd.hpp"
|
||||||
|
|
||||||
|
#include "args.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
#include "utils/error.hpp"
|
||||||
|
|
||||||
|
namespace monitarr {
|
||||||
|
auto config_cmd(const app_config &cfg) -> int {
|
||||||
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
|
utils::error::handle_info(function_name,
|
||||||
|
fmt::format("{}", nlohmann::json(cfg).dump(2)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} // namespace monitarr
|
25
monitarr/monitarr/src/list_cmd.cpp
Normal file
25
monitarr/monitarr/src/list_cmd.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "list_cmd.hpp"
|
||||||
|
|
||||||
|
#include "actions.hpp"
|
||||||
|
#include "args.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
#include "utils/error.hpp"
|
||||||
|
#include "utils/string.hpp"
|
||||||
|
|
||||||
|
namespace monitarr {
|
||||||
|
auto list_cmd(int argc, char **argv, const app_config &cfg) -> int {
|
||||||
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
|
auto idx = get_arg("-i", argc, argv);
|
||||||
|
if (not idx.has_value()) {
|
||||||
|
utils::error::handle_error(function_name, "'-i <index>' is required");
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &server = cfg.server_list.at(utils::string::to_uint64(*idx));
|
||||||
|
|
||||||
|
utils::error::handle_info(
|
||||||
|
function_name, fmt::format("list queue|{}|{}", server.id, server.url));
|
||||||
|
return list_queue(server);
|
||||||
|
}
|
||||||
|
} // namespace monitarr
|
35
monitarr/monitarr/src/show_cmd.cpp
Normal file
35
monitarr/monitarr/src/show_cmd.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include "show_cmd.hpp"
|
||||||
|
|
||||||
|
#include "actions.hpp"
|
||||||
|
#include "args.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
#include "utils/error.hpp"
|
||||||
|
#include "utils/string.hpp"
|
||||||
|
|
||||||
|
namespace monitarr {
|
||||||
|
auto show_cmd(int argc, char **argv, const app_config &cfg) -> int {
|
||||||
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
|
auto idx = get_arg("-i", argc, argv);
|
||||||
|
if (not idx.has_value()) {
|
||||||
|
utils::error::handle_error(function_name, "'-i <index>' is required");
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &server = cfg.server_list.at(utils::string::to_uint64(*idx));
|
||||||
|
auto record_id = get_arg("-id", argc, argv);
|
||||||
|
if (not record_id.has_value()) {
|
||||||
|
utils::error::handle_error(function_name, "'-id <record id>' is required");
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto entry = get_download(utils::string::to_uint64(*record_id), server);
|
||||||
|
if (not entry.has_value()) {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
utils::error::handle_info(function_name,
|
||||||
|
fmt::format("", nlohmann::json(*entry).dump(2)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} // namespace monitarr
|
@ -38,6 +38,12 @@ TEST(utils_error, check_default_exception_handler) {
|
|||||||
|
|
||||||
TEST(utils_error, can_override_exception_handler) {
|
TEST(utils_error, can_override_exception_handler) {
|
||||||
struct my_exc_handler final : public utils::error::i_exception_handler {
|
struct my_exc_handler final : public utils::error::i_exception_handler {
|
||||||
|
#if defined(PROJECT_ENABLE_V2_ERRORS)
|
||||||
|
MOCK_METHOD(void, handle_debug,
|
||||||
|
(std::string_view function_name, std::string_view msg),
|
||||||
|
(const, override));
|
||||||
|
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
|
||||||
|
|
||||||
MOCK_METHOD(void, handle_error,
|
MOCK_METHOD(void, handle_error,
|
||||||
(std::string_view function_name, std::string_view msg),
|
(std::string_view function_name, std::string_view msg),
|
||||||
(const, override));
|
(const, override));
|
||||||
@ -48,11 +54,30 @@ TEST(utils_error, can_override_exception_handler) {
|
|||||||
MOCK_METHOD(void, handle_exception,
|
MOCK_METHOD(void, handle_exception,
|
||||||
(std::string_view function_name, const std::exception &ex),
|
(std::string_view function_name, const std::exception &ex),
|
||||||
(const, override));
|
(const, override));
|
||||||
|
|
||||||
|
#if defined(PROJECT_ENABLE_V2_ERRORS)
|
||||||
|
MOCK_METHOD(void, handle_info,
|
||||||
|
(std::string_view function_name, std::string_view msg),
|
||||||
|
(const, override));
|
||||||
|
|
||||||
|
MOCK_METHOD(void, handle_trace,
|
||||||
|
(std::string_view function_name, std::string_view msg),
|
||||||
|
(const, override));
|
||||||
|
|
||||||
|
MOCK_METHOD(void, handle_warn,
|
||||||
|
(std::string_view function_name, std::string_view msg),
|
||||||
|
(const, override));
|
||||||
|
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
|
||||||
};
|
};
|
||||||
|
|
||||||
my_exc_handler handler{};
|
my_exc_handler handler{};
|
||||||
utils::error::set_exception_handler(&handler);
|
utils::error::set_exception_handler(&handler);
|
||||||
|
|
||||||
|
#if defined(PROJECT_ENABLE_V2_ERRORS)
|
||||||
|
EXPECT_CALL(handler, handle_debug("test_func", "debug")).WillOnce(Return());
|
||||||
|
utils::error::handle_debug("test_func", "debug");
|
||||||
|
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
|
||||||
|
|
||||||
EXPECT_CALL(handler, handle_error("test_func", "error")).WillOnce(Return());
|
EXPECT_CALL(handler, handle_error("test_func", "error")).WillOnce(Return());
|
||||||
utils::error::handle_error("test_func", "error");
|
utils::error::handle_error("test_func", "error");
|
||||||
|
|
||||||
@ -68,6 +93,17 @@ TEST(utils_error, can_override_exception_handler) {
|
|||||||
});
|
});
|
||||||
utils::error::handle_exception("test_func_ex", ex);
|
utils::error::handle_exception("test_func_ex", ex);
|
||||||
|
|
||||||
|
#if defined(PROJECT_ENABLE_V2_ERRORS)
|
||||||
|
EXPECT_CALL(handler, handle_info("test_func", "info")).WillOnce(Return());
|
||||||
|
utils::error::handle_info("test_func", "info");
|
||||||
|
|
||||||
|
EXPECT_CALL(handler, handle_trace("test_func", "trace")).WillOnce(Return());
|
||||||
|
utils::error::handle_trace("test_func", "trace");
|
||||||
|
|
||||||
|
EXPECT_CALL(handler, handle_warn("test_func", "warn")).WillOnce(Return());
|
||||||
|
utils::error::handle_warn("test_func", "warn");
|
||||||
|
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
|
||||||
|
|
||||||
utils::error::set_exception_handler(&utils::error::default_exception_handler);
|
utils::error::set_exception_handler(&utils::error::default_exception_handler);
|
||||||
}
|
}
|
||||||
} // namespace monitarr
|
} // namespace monitarr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user