Update Names in api
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "api.hpp"
|
||||
#include "tables.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
|
||||
@@ -25,16 +26,15 @@ void Api::RegisterServerHandles(httplib::Server& server)
|
||||
|
||||
server.Post("/api/add", std::bind_front(&Api::add, this));
|
||||
|
||||
server.Get("/api/queue", std::bind_front(&Api::queue, this));
|
||||
server.Get("/api/files", std::bind_front(&Api::files, this));
|
||||
|
||||
server.Get("/api/file/(\\d+)", std::bind_front(&Api::file, this));
|
||||
|
||||
server.Options("/(.*)", [this](httplib::Request const& rq, httplib::Response& rp) {
|
||||
spdlog::info("Optin");
|
||||
});
|
||||
server.Options("/(.*)", [this](httplib::Request const& rq, httplib::Response& rp) {});
|
||||
|
||||
server.set_pre_routing_handler([this](httplib::Request const& rq, httplib::Response& rp) {
|
||||
this->set_cross_headers(rp);
|
||||
spdlog::info("Request {}", rq.method);
|
||||
return httplib::Server::HandlerResponse::Unhandled;
|
||||
});
|
||||
}
|
||||
@@ -74,13 +74,13 @@ void Api::add(const httplib::Request& rq, httplib::Response& rs)
|
||||
}
|
||||
}
|
||||
|
||||
void Api::queue(httplib::Request const& rq, httplib::Response& rs)
|
||||
void Api::files(httplib::Request const& rq, httplib::Response& rs)
|
||||
{
|
||||
try
|
||||
{
|
||||
json res;
|
||||
|
||||
soci::rowset<File> data = (sql.prepare << "SELECT * FROM Files");
|
||||
soci::rowset<File> data = (sql.prepare << "SELECT * FROM Files ORDER BY id DESC");
|
||||
|
||||
for (auto const& el : data)
|
||||
{
|
||||
@@ -88,7 +88,25 @@ void Api::queue(httplib::Request const& rq, httplib::Response& rs)
|
||||
current["id"] = el.id;
|
||||
current["status"] = magic_enum::enum_name(el.status);
|
||||
current["status_id"] = static_cast<int>(el.status);
|
||||
current["url"] = el.url;
|
||||
current["source"] = el.url;
|
||||
current["name"] = fmt::format("File {}", el.id);
|
||||
|
||||
current["file_name"] = "Unknown";
|
||||
|
||||
if (el.status == FileStatus::COMPLETE && false)
|
||||
{
|
||||
std::string filename;
|
||||
soci::rowset<std::string> ret =
|
||||
(sql.prepare << "SELECT path From Downloads WHERE id=:id",
|
||||
soci::use(el.id, "id"));
|
||||
|
||||
if (ret.begin() != ret.end())
|
||||
{
|
||||
std::filesystem::path p(*ret.begin());
|
||||
|
||||
current["file_name"] = p.filename();
|
||||
}
|
||||
}
|
||||
|
||||
res["queue"].push_back(current);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user