Update Names in api
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -19,3 +19,4 @@ cmake-build-release/
|
|||||||
CMakeSettings.json
|
CMakeSettings.json
|
||||||
|
|
||||||
Modules/Website/elm-stuff/
|
Modules/Website/elm-stuff/
|
||||||
|
Modules/Website/.vscode/settings.json
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
|
add_subdirectory(Website)
|
||||||
add_subdirectory(Server)
|
add_subdirectory(Server)
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "api.hpp"
|
#include "api.hpp"
|
||||||
#include "tables.hpp"
|
#include "tables.hpp"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
@@ -25,16 +26,15 @@ void Api::RegisterServerHandles(httplib::Server& server)
|
|||||||
|
|
||||||
server.Post("/api/add", std::bind_front(&Api::add, this));
|
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.Get("/api/file/(\\d+)", std::bind_front(&Api::file, this));
|
||||||
|
|
||||||
server.Options("/(.*)", [this](httplib::Request const& rq, httplib::Response& rp) {
|
server.Options("/(.*)", [this](httplib::Request const& rq, httplib::Response& rp) {});
|
||||||
spdlog::info("Optin");
|
|
||||||
});
|
|
||||||
|
|
||||||
server.set_pre_routing_handler([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);
|
this->set_cross_headers(rp);
|
||||||
|
spdlog::info("Request {}", rq.method);
|
||||||
return httplib::Server::HandlerResponse::Unhandled;
|
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
|
try
|
||||||
{
|
{
|
||||||
json res;
|
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)
|
for (auto const& el : data)
|
||||||
{
|
{
|
||||||
@@ -88,7 +88,25 @@ void Api::queue(httplib::Request const& rq, httplib::Response& rs)
|
|||||||
current["id"] = el.id;
|
current["id"] = el.id;
|
||||||
current["status"] = magic_enum::enum_name(el.status);
|
current["status"] = magic_enum::enum_name(el.status);
|
||||||
current["status_id"] = static_cast<int>(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);
|
res["queue"].push_back(current);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public:
|
|||||||
public: // Endpoints
|
public: // Endpoints
|
||||||
void add(httplib::Request const& rq, httplib::Response& rs);
|
void add(httplib::Request const& rq, httplib::Response& rs);
|
||||||
|
|
||||||
void queue(httplib::Request const& rq, httplib::Response& rs);
|
void files(httplib::Request const& rq, httplib::Response& rs);
|
||||||
void file(httplib::Request const& rq, httplib::Response& rs);
|
void file(httplib::Request const& rq, httplib::Response& rs);
|
||||||
|
|
||||||
void set_cross_headers(httplib::Response& rs);
|
void set_cross_headers(httplib::Response& rs);
|
||||||
|
|||||||
@@ -68,7 +68,8 @@ int main()
|
|||||||
Worker worker(sql);
|
Worker worker(sql);
|
||||||
|
|
||||||
httplib::Server srv;
|
httplib::Server srv;
|
||||||
srv.set_mount_point("/", "downloads/");
|
srv.set_mount_point("/", "www/");
|
||||||
|
srv.set_mount_point("/test", "www/");
|
||||||
|
|
||||||
Api api(sql, srv);
|
Api api(sql, srv);
|
||||||
|
|
||||||
|
|||||||
10
Modules/Test.http
Normal file
10
Modules/Test.http
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
POST 127.0.0.1:80/api/add
|
||||||
|
Content-Type: text/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"url": "https://www.youtube.com/watch?v=ZWIwLMpgcbI"
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
GET 127.0.0.1:80/api/queue
|
||||||
Reference in New Issue
Block a user