Commit dd32aad3 authored by jan.koester's avatar jan.koester
Browse files

test

parent 6b00a3ec
Loading
Loading
Loading
Loading
+53 −6
Changes for client/localapi.cpp: 53 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -177,12 +177,15 @@ void LocalApi::publishToServer() {
        return;
    }

    emit statusMessage("Publishing...");
    _pub->publish(rendered, [this](bool ok, const QString &msg) {
        if (ok)
            emit statusMessage("Published: " + msg);
        else
            emit statusMessage("Publish failed: " + msg);
    emit statusMessage("Rendering on server...");
    _pub->renderOnServer(rendered, "main", false, [this](bool ok, const QString &msg) {
        if (ok) {
            emit statusMessage("Render complete");
            emit publishCompleted(true, msg);
        } else {
            emit statusMessage("Render failed: " + msg);
            emit publishCompleted(false, msg);
        }
    });
}

@@ -280,6 +283,50 @@ void LocalApi::fetchMedia(const QString &albumId) {
    });
}

void LocalApi::fetchPublishTargets() {
    QJsonArray cmds;
    QJsonObject cmd;
    cmd["command"] = "webedit_list_targets";
    cmds.append(cmd);

    _pub->apiRequest(cmds, [this](bool ok, const QJsonArray &resp) {
        if (!ok) {
            emit statusMessage("Failed to fetch publish targets");
            return;
        }
        for (int i = 0; i < resp.size(); ++i) {
            QJsonObject obj = resp.at(i).toObject();
            if (obj.contains("targets")) {
                emit publishTargetsLoaded(QString::fromUtf8(QJsonDocument(obj).toJson(QJsonDocument::Compact)));
                return;
            }
        }
        emit publishTargetsLoaded("{}");
    });
}

void LocalApi::publishToTarget(const QString &target, const QString &paramsJson) {
    if (!_pub->isConfigured()) {
        emit publishCompleted(false, "Not connected");
        return;
    }

    QString rendered = _doc->renderToHtml();
    if (rendered.isEmpty()) {
        emit publishCompleted(false, "Document is empty");
        return;
    }

    emit statusMessage("Publishing to " + target + "...");
    _pub->renderOnServer(rendered, "main", false, [this](bool ok, const QString &msg) {
        emit publishCompleted(ok, msg);
        if (ok)
            emit statusMessage("Published successfully");
        else
            emit statusMessage("Publish failed: " + msg);
    });
}

void LocalApi::refresh() {
    emit documentChanged();
}
+43 −0
Changes for client/publishclient.cpp: 43 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QUrlQuery>

PublishClient::PublishClient(QObject *parent)
    : QObject(parent)
@@ -200,6 +201,48 @@ void PublishClient::publish(const QString &html, Callback cb) {
    });
}

void PublishClient::renderOnServer(const QString &html, const QString &rootel, bool mobile, Callback cb) {
    if (_serverUrl.isEmpty()) {
        cb(false, "Server URL not configured");
        return;
    }

    QUrl url(_serverUrl + "/render");
    QNetworkRequest req(url);
    req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    req.setAttribute(QNetworkRequest::Http2AllowedAttribute, false);

    QUrlQuery params;
    if (!_authToken.isEmpty())
        params.addQueryItem("authid", _authToken);
    params.addQueryItem("html", html);
    params.addQueryItem("rootel", rootel.isEmpty() ? "main" : rootel);
    params.addQueryItem("mobile", mobile ? "true" : "false");

    QByteArray postData = params.query(QUrl::FullyEncoded).toUtf8();

    QNetworkReply *reply = _nam->post(req, postData);
    _activeReply = reply;
    if (_ignoreSsl)
        connect(reply, &QNetworkReply::sslErrors, reply, qOverload<>(&QNetworkReply::ignoreSslErrors));
    connect(reply, &QNetworkReply::finished, this, [this, reply, cb]() {
        if (_activeReply == reply) _activeReply = nullptr;
        reply->deleteLater();
        if (reply->error() == QNetworkReply::OperationCanceledError) {
            cb(false, "Aborted");
            return;
        }
        int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
        if (status == 200) {
            cb(true, QString::fromUtf8(reply->readAll()));
        } else if (reply->error() != QNetworkReply::NoError) {
            cb(false, reply->errorString());
        } else {
            cb(false, "Server returned HTTP " + QString::number(status));
        }
    });
}

void PublishClient::apiRequest(const QJsonArray &commands, std::function<void(bool, const QJsonArray &)> cb) {
    if (_serverUrl.isEmpty()) {
        cb(false, QJsonArray());
+1 −0
Changes for client/publishclient.h: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public:
    using Callback = std::function<void(bool ok, const QString &message)>;

    void publish(const QString &html, Callback cb);
    void renderOnServer(const QString &html, const QString &rootel, bool mobile, Callback cb);
    void login(const QString &user, const QString &password, Callback cb);
    void testConnection(Callback cb);
    void apiRequest(const QJsonArray &commands, std::function<void(bool, const QJsonArray &)> cb);
+23 −11
Changes for src/blogi.cpp: 23 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -2046,15 +2046,6 @@ RETRY_REQUEST:
                return;
            }else if(curreq.getRequestURL().compare(0,PlgArgs->config->buildurl("render").length(),PlgArgs->config->buildurl("render"))==0){

                std::string sessionid;

                if(!PlgArgs->auth->isLoggedIn(tid,curreq,sessionid)){
                    libhttppp::HTTPException err;
                    err[libhttppp::HTTPException::Error] << "you are not logged in permission denied";
                    throw err;
                }


                libhttppp::HttpForm renderopts;
                renderopts.parse(curreq);

@@ -2062,6 +2053,8 @@ RETRY_REQUEST:

                std::string rootel;
                std::string publishTarget;
                std::string authid;
                std::string html;
                json_object *publishParams = nullptr;

                for(const auto &curdat : renderopts.urlData()){
@@ -2071,7 +2064,11 @@ RETRY_REQUEST:
                        rootel=curdat.value;
                    }else if(curdat.key=="target"){
                        publishTarget=curdat.value;
                    }else if(curdat.key!="authid"){
                    }else if(curdat.key=="authid"){
                        authid=curdat.value;
                    }else if(curdat.key=="html"){
                        html=curdat.value;
                    }else{
                        // Collect remaining params for the publish preview
                        if(!publishParams)
                            publishParams = json_object_new_object();
@@ -2080,6 +2077,21 @@ RETRY_REQUEST:
                    }
                }

                // Auth check: try authid from form data first, then cookie
                std::string sessionid;
                bool authenticated = false;
                if(!authid.empty()){
                    authenticated = PlgArgs->auth->isLoggedIn(tid, uuid::uuid(authid));
                }
                if(!authenticated){
                    authenticated = PlgArgs->auth->isLoggedIn(tid, curreq, sessionid);
                }
                if(!authenticated){
                    libhttppp::HTTPException err;
                    err[libhttppp::HTTPException::Error] << "you are not logged in permission denied";
                    throw err;
                }

                if(mobile)
                    index=MIndex;
                else
@@ -2092,7 +2104,7 @@ RETRY_REQUEST:
                        curplg->getInstace()->Rendering(tid,curreq,&index,RenderingType::Desktop);
                }

                testedit->Renderer(curreq,tid,sessid,index,rootel,BlogiPlg.get(),publishTarget,publishParams);
                testedit->Renderer(curreq,tid,sessid,index,rootel,BlogiPlg.get(),publishTarget,publishParams,html);
                if(publishParams)
                    json_object_put(publishParams);
                return;
+13 −2
Changes for src/edit.cpp: 13 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2900,7 +2900,8 @@ void blogi::webedit::WebEditor::Renderer(
    const std::string &rootEl,
    Plugin *plugins,
    const std::string &publishTarget,
    json_object *publishParams
    json_object *publishParams,
    const std::string &html
){
    libhtmlpp::HtmlString out;
    libhtmlpp::HtmlElement ridx=index;
@@ -2921,7 +2922,16 @@ void blogi::webedit::WebEditor::Renderer(
            root->appendChild(globalStyle);
        }

        // Render user-created document elements into root
        if (!html.empty()) {
            // Client sent pre-rendered HTML — inject it directly
            libhtmlpp::HtmlString htmlStr;
            htmlStr << html.c_str();
            libhtmlpp::HtmlElement *parsed = htmlStr.parse();
            if (parsed) {
                root->appendChild(*parsed);
            }
        } else {
            // Render user-created document elements into root (server-side fallback)
            if (DocRoot) {
                const EditPlugin *el = DocRoot;
                while (el) {
@@ -2929,6 +2939,7 @@ void blogi::webedit::WebEditor::Renderer(
                    el = el->nextElement();
                }
            }
        }

        // Inject click-to-select and highlight script into rendered preview
        libhtmlpp::HtmlElement selectScript("script");
Loading