/
Boxapp
/
yadisk-helper
Обзор
Документация
Войти
/
Boxapp
/
yadisk-helper
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
finder.cpp
78 строк
2 KB
DebianCougar
test build 2026.02-beta
30 янв 2026, 21:25
30 янв 2026, 21:25
eb3551d
Код
Авторство
О чём код?
#include <boost/json.hpp> // NOTE compile with flag -lboost_json #include <fstream> #include <iostream> #include <sstream> #include <string> #include <vector> #include "http.hpp" using boost::json::array; using boost::json::stream_parser; using boost::json::value; using boost::system::error_code; using std::cerr; using std::endl; using std::exception; using std::getline; using std::ifstream; using std::istream; using std::istringstream; using std::ostream; using std::string; using std::vector; static value readJson( istream& is, error_code& ec ) { stream_parser p; string line; while (getline( is, line )) { p.write( line, ec ); if ( ec ) return nullptr; } p.finish( ec ); if ( ec ) return nullptr; return p.release(); } static size_t loadCount(const string &dir, const string &token) { string json = queryCount(dir, token); error_code err; istringstream reader(json); value tree = readJson(reader, err); if (err) { cerr << "[ ERROR ] " << err.what() << endl; // FIXME explicitly notify if path not found return 0; } else { value emb = tree.at("_embedded"); value filecnt = emb.at("total"); return filecnt.as_int64(); } } static vector<string> loadItems(const string &dir, size_t count, const string &token) { string json = queryItems(dir, count, token); error_code err; istringstream reader(json); value tree = readJson(reader, err); vector<string> res; if (err) cerr << "[ ERROR ] " << err.what() << endl; // FIXME explicitly notify if path not found else { value emb = tree.at("_embedded"); value items = emb.at("items"); array files = items.as_array(); for (const auto &file : files) res.push_back(file.at("name").as_string().c_str()); } return res; } vector<string> contents(const string &dir, const string &token) { vector<string> res; try { size_t filecnt = loadCount(dir, token); if (filecnt > 0) res = loadItems(dir, filecnt, token); } catch (exception &ex) { cerr << "[ ERROR ] " << ex.what() << endl; } return res; }