Commit 91c96a8b authored by jan.koester's avatar jan.koester
Browse files

test

parent c4c663f2
Loading
Loading
Loading
Loading
+27 −4
Changes for plugins/staticpage/static.cpp: 27 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -523,19 +523,36 @@ bool blogi::StaticPage::Controller(const int tid,libhttppp::HttpRequest &req,lib
        std::string surl=req.getRequestURL().substr(Args->config->buildurl("staticpage/").length(),
                                                                                    req.getRequestURL().length()-Args->config->buildurl("staticpage/").length());

        static const std::string llmsSuffix = "/llms.txt";
        bool wantsLlmsTxt = false;
        if (surl.length() > llmsSuffix.length() &&
            surl.compare(surl.length()-llmsSuffix.length(), llmsSuffix.length(), llmsSuffix) == 0) {
            wantsLlmsTxt = true;
            surl = surl.substr(0, surl.length()-llmsSuffix.length());
        }

        libhttppp::HTTPException excep;

        dbpp::SQL sql;
        dbpp::DBResult res;
        std::vector<char> sbuf;

        sql << "select url,text,meta from static_content where url='" << sql.escaped(sbuf,surl.c_str()) << "' LIMIT 1";
        sql << "select url,text,meta,llms_txt from static_content where url='" << sql.escaped(sbuf,surl.c_str()) << "' LIMIT 1";

        if (Args->database[tid]->exec(sql,res)<1) {
            excep[libhttppp::HTTPException::Error] << "Staticpage with this url not found!";
            throw excep;
        }

        if (wantsLlmsTxt) {
            std::string llmsTxt = res[0][3] ? res[0][3] : "";
            libhttppp::HttpResponse resp;
            resp.setState(HTTP200);
            resp.setContentType("text/plain; charset=utf-8");
            sendCompressed(req,resp,llmsTxt.c_str(),llmsTxt.length());
            return true;
        }

        std::string text = res[0][1] ? res[0][1] : "";
        std::string pageTitle = res[0][0] ? res[0][0] : "";
        RenderPublished(tid, text, nullptr, *page);
@@ -704,7 +721,7 @@ void blogi::StaticPage::Publish(const int tid, const std::string &html, json_obj
    std::vector<char> sbuf;
    json_object *val_obj = nullptr;

    std::string url, meta, method, navbarLabel;
    std::string url, meta, method, navbarLabel, llmsTxt;
    std::string navbarId;

    if (params) {
@@ -716,6 +733,10 @@ void blogi::StaticPage::Publish(const int tid, const std::string &html, json_obj
            const char *v = json_object_get_string(val_obj);
            if (v) meta = v;
        }
        if (json_object_object_get_ex(params, "llms_txt", &val_obj)) {
            const char *v = json_object_get_string(val_obj);
            if (v) llmsTxt = v;
        }
        if (json_object_object_get_ex(params, "method", &val_obj)) {
            const char *v = json_object_get_string(val_obj);
            if (v) method = v;
@@ -752,6 +773,7 @@ void blogi::StaticPage::Publish(const int tid, const std::string &html, json_obj
            sql.clear();
            sql << "UPDATE static_content SET text='" << dbpp::SQL::escaped(sbuf, html.c_str())
                << "', meta='" << dbpp::SQL::escaped(sbuf, meta.c_str())
                << "', llms_txt='" << dbpp::SQL::escaped(sbuf, llmsTxt.c_str())
                << "' WHERE id='" << pageId.c_str() << "';";
            Args->database[tid]->exec(sql, res);

@@ -765,11 +787,12 @@ void blogi::StaticPage::Publish(const int tid, const std::string &html, json_obj
            id.generate();

            sql.clear();
            sql << "INSERT INTO static_content (id,url,meta,text) VALUES('"
            sql << "INSERT INTO static_content (id,url,meta,text,llms_txt) VALUES('"
                << id.c_str() << "','"
                << dbpp::SQL::escaped(sbuf, url.c_str()) << "','"
                << dbpp::SQL::escaped(sbuf, meta.c_str()) << "','"
                << dbpp::SQL::escaped(sbuf, html.c_str()) << "');";
                << dbpp::SQL::escaped(sbuf, html.c_str()) << "','"
                << dbpp::SQL::escaped(sbuf, llmsTxt.c_str()) << "');";
            Args->database[tid]->exec(sql, res);

            json_object_object_add(response, "status", json_object_new_string("success"));