a lot of fixes

This commit is contained in:
2024-10-05 13:52:44 +03:00
parent 640337d420
commit d2afa8c9dd
32 changed files with 909 additions and 104 deletions

View File

@@ -1,19 +1,21 @@
#include "ofd.h"
#include "../settings.h"
#include "../utils/utils.h"
#include <filesystem>
#include <iostream>
#include <string>
#include <vector>
#include "../net/net.h"
#include "../settings/settings.h"
OFD::OFD() {}
OFD::OFD(std::string path) { this->module = OFDModule(path); };
std::vector<std::string> OFD::search_ofds() {
Settings s(get_path_relative_to_home(".local/share/checks_parser/settings.json"));
std::vector<std::string> result{};
std::string path = std::string(std::getenv("HOME")) + "/" + OFDS_MODULES_DIR;
std::string path = get_path_relative_to_home(s.get_setting("ods_modules_dir"));
std::filesystem::directory_entry modules_dir(path);
if (!modules_dir.exists()) {
@@ -35,45 +37,31 @@ void OFD::set_module(std::string path) { this->module = OFDModule(path); }
std::string OFD::get_check_data(std::string fn, std::string fd,
std::string fp) {
//curl 'https://ofd.beeline.ru/api/ofdcheck/checkf?fn=7281440701327430&fp=2518183888&fd=25955&format=4' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: en-US,en;q=0.9,eo;q=0.8,ru;q=0.7' \
-H 'Authorization: bearer null' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'DNT: 1' \
-H 'Referer: https://ofd.beeline.ru/check-order?fn=7281440701327430&fp=2518183888&fd=25955' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Chromium";v="127", "Not)A;Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"'
// curl 'https://ofd.beeline.ru/api/ofdcheck/checkf?fn=7281440701327430&fp=2807139546&fd=25051&format=4' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: en-US,en;q=0.9,eo;q=0.8,ru;q=0.7' \
-H 'Authorization: bearer null' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'DNT: 1' \
-H 'Referer: https://ofd.beeline.ru/check-order?fn=7281440701327430&fp=2807139546&fd=25051' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Chromium";v="127", "Not)A;Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"'
// // cpr::Response r = cpr::Get(cpr::Url{"https://httpbin.org/get"});
// std::cout << fn << " " << fd << " " << fp << std::endl;
// cpr::Response r =
// //to_utf8(module.get_url())
// cpr::Get(cpr::Url{"https://ofd.beeline.ru/api/ofdcheck/checkf"},
// cpr::Parameters{{"fn", fn}, {"fd", fd}, {"fp", fp}, {"format", "4"}});
// return r.text;
//TODO
return "";
}
std::vector<std::string> OFD::check_updates() {
Settings s(get_path_relative_to_home(".local/share/checks_parser/settings.json"));
std::string path = get_path_relative_to_home(s.get_setting("ofds_modules_dir"));
std::vector<std::string> to_download;
std::vector<std::string> stored_modules;
for (const auto& file : std::filesystem::directory_iterator(path)) {
if (!file.is_regular_file()) continue;
stored_modules.push_back(file.path().filename());
std::cout << "Detected OFD module" << file.path().filename() << std::endl;
}
Net n;
std::vector<std::string> remote_modules = n.get_all_modules(s.get_setting("ofds_modules_url"));
for (const std::string& module : remote_modules) {
if (!vector_contains_element(stored_modules, module)) {
to_download.push_back(module);
std::cout << "I need to download OFD module " << module << std::endl;
}
}
return to_download;
}

View File

@@ -18,5 +18,6 @@ public:
void set_module(std::string);
std::string get_check_data(std::string fn, std::string fd, std::string fp);
std::vector<std::string> check_updates();
};
#endif // OFD_H