Overhaul cmake configuration, add console api, fix http code that caused issues with cgi-bin

This commit is contained in:
2026-05-27 03:02:16 -05:00
parent 266ef5f830
commit 8413c67ec6
177 changed files with 20088 additions and 17948 deletions

View File

@@ -7,83 +7,84 @@ using namespace Tesses::Framework::Filesystem;
std::shared_ptr<VFS> vfs;
int main(int argc, char** argv)
{
int main(int argc, char **argv) {
TF_InitWithConsole();
vfs = std::make_shared<SubdirFilesystem>(LocalFS,Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory());
vfs = std::make_shared<SubdirFilesystem>(
LocalFS,
Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory());
std::shared_ptr<CallbackServer> cb = std::make_shared<CallbackServer>([](ServerContext& ctx)->bool{
if(ctx.path == "/")
{
std::shared_ptr<CallbackServer> cb = std::make_shared<
CallbackServer>([](ServerContext &ctx) -> bool {
if (ctx.path == "/") {
ctx.WithMimeType("text/html")
.SendText(
"<!DOCTYPE html>"
"<html>"
"<head><meta charset=\"UTF-8\"><title>AnonyDrop</title><meta name=\"color-scheme\" content=\"dark light\"></head>"
"<body>"
"<h1>AnonyDrop</h1>"
"<a href=\"./files/\">Files</a>"
"<form action=\"./upload\" method=\"post\" enctype=\"multipart/form-data\" accept-charset=\"UTF-8\">"
"<input type=\"file\" name=\"file\" multiple>"
"<input type=\"submit\" value=\"Upload\">"
"</form>"
"</body>"
"</html>"
);
return true;
}
else if(ctx.path == "/upload")
{
if(ctx.NeedToParseFormData())
{
ctx.ParseFormData([](std::string mime, std::string filename,std::string name)->std::shared_ptr<Stream> {
if(name != "file") return nullptr;
VFSPath path("/"+filename);
auto strm = vfs->OpenFile(path,"wb");
return strm;
});
ctx.WithMimeType("text/html")
.SendText(
"<!DOCTYPE html>"
"<html>"
"<head><meta name=\"color-scheme\" content=\"dark light\"><title>AnonyDrop - Uploaded successfully</title></head>"
"<head><meta "
"charset=\"UTF-8\"><title>AnonyDrop</title><meta "
"name=\"color-scheme\" content=\"dark light\"></head>"
"<body>"
"<h1>Uploaded successfully</h1>"
"<a href=\"./\">Back</a>"
"</body>"
"</html>"
);
return true;
}
else {
ctx.statusCode= Tesses::Framework::Http::BadRequest;
ctx.WithMimeType("text/html")
.SendText(
"<!DOCTYPE html>"
"<html>"
"<head><title>AnonyDump - Error: Must contain multipart and POST</title>"
"<body>"
"<h1>Error: Must contain multipart and POST</h1>"
"<a href=\"./\">Back</a>"
"<h1>AnonyDrop</h1>"
"<a href=\"./files/\">Files</a>"
"<form action=\"./upload\" method=\"post\" "
"enctype=\"multipart/form-data\" accept-charset=\"UTF-8\">"
"<input type=\"file\" name=\"file\" multiple>"
"<input type=\"submit\" value=\"Upload\">"
"</form>"
"</body>"
"</html>"
);
"</html>");
return true;
} else if (ctx.path == "/upload") {
if (ctx.NeedToParseFormData()) {
ctx.ParseFormData(
[](std::string mime, std::string filename,
std::string name) -> std::shared_ptr<Stream> {
if (name != "file")
return nullptr;
VFSPath path("/" + filename);
auto strm = vfs->OpenFile(path, "wb");
return strm;
});
ctx.WithMimeType("text/html")
.SendText("<!DOCTYPE html>"
"<html>"
"<head><meta name=\"color-scheme\" "
"content=\"dark light\"><title>AnonyDrop - "
"Uploaded successfully</title></head>"
"<body>"
"<h1>Uploaded successfully</h1>"
"<a href=\"./\">Back</a>"
"</body>"
"</html>");
return true;
} else {
ctx.statusCode = Tesses::Framework::Http::BadRequest;
ctx.WithMimeType("text/html")
.SendText("<!DOCTYPE html>"
"<html>"
"<head><title>AnonyDump - Error: Must contain "
"multipart and POST</title>"
"<body>"
"<h1>Error: Must contain multipart and POST</h1>"
"<a href=\"./\">Back</a>"
"</form>"
"</body>"
"</html>");
}
}
return false;
});
auto mountable = std::make_shared<Tesses::Framework::Http::MountableServer>(cb);
mountable->Mount("/files/",std::make_shared<FileServer>(vfs,true,false));
auto mountable =
std::make_shared<Tesses::Framework::Http::MountableServer>(cb);
mountable->Mount("/files/", std::make_shared<FileServer>(vfs, true, false));
HttpServer srv(4985,mountable);
HttpServer srv(4985, mountable);
srv.StartAccepting();
TF_RunEventLoop();