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

test

parent 7fc9b079
Loading
Loading
Loading
Loading
+2 −0
Changes for editor/config.yaml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ WEBEDIT:
  NODE:
    BINARY: "/usr/lib/blogi-editor/node/bin/node"
    RUNNER: "/usr/share/blogi-editor/node/node_widget_runner.js"
    WIDGETDIR:
      - "/usr/share/blogi-editor/node/widgets"
  AUTHDB:
    - URL: "https://localhost:8443"
      CLIENTNAME: "blogi-editor"
+12 −0
Changes for editor/src/main.cpp: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -85,6 +85,18 @@ int main(int argc, char *argv[]) {
            setenv("BLOGI_WEBEDIT_NODE_RUNNER", config.getNodeRunner().c_str(), 1);
            std::cout << "Configured Node.js widget runner: " << config.getNodeRunner() << std::endl;
        }
        {
            const auto &dirs = config.getNodeWidgetDirs();
            std::string joined;
            for (size_t i = 0; i < dirs.size(); ++i) {
                if (i) joined += ':';
                joined += dirs[i];
            }
            if (!joined.empty()) {
                setenv("BLOGI_WEBEDIT_NODE_WIDGET_DIRS", joined.c_str(), 1);
                std::cout << "Configured Node.js widget directories: " << joined << std::endl;
            }
        }

        // Initialize database (with retry for container network setup)
        std::cout << "Initializing database: " << config.getDbDriver()
+31 −2
Changes for editor/src/webedit_api.cpp: 31 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <set>

#include <htmlpp/html.h>
#include <httppp/exception.h>
@@ -161,11 +162,34 @@ bool queryNodeWidgetDescriptor(const std::string &scriptPath, NodeWidgetDescript

std::vector<NodeWidgetDescriptor> nodeWidgetCatalog() {
    std::vector<NodeWidgetDescriptor> catalog;
    const std::string widgetsDir = getEnvOrDefault("BLOGI_WEBEDIT_NODE_WIDGET_DIR", "/usr/share/blogi-editor/node/widgets");
    std::vector<std::string> widgetDirs;

    const std::string dirsEnv = getEnvOrDefault("BLOGI_WEBEDIT_NODE_WIDGET_DIRS", "");
    if (!dirsEnv.empty()) {
        size_t start = 0;
        while (start <= dirsEnv.size()) {
            size_t pos = dirsEnv.find(':', start);
            std::string part = (pos == std::string::npos) ? dirsEnv.substr(start) : dirsEnv.substr(start, pos - start);
            if (!part.empty())
                widgetDirs.push_back(part);
            if (pos == std::string::npos)
                break;
            start = pos + 1;
        }
    }

    if (widgetDirs.empty()) {
        const std::string singleDir = getEnvOrDefault("BLOGI_WEBEDIT_NODE_WIDGET_DIR", "/usr/share/blogi-editor/node/widgets");
        if (!singleDir.empty())
            widgetDirs.push_back(singleDir);
    }

    std::set<std::string> namesSeen;
    std::error_code ec;

    for (const auto &widgetsDir : widgetDirs) {
        if (!std::filesystem::exists(widgetsDir, ec) || ec)
        return catalog;
            continue;

        for (const auto &entry : std::filesystem::directory_iterator(widgetsDir, ec)) {
            if (ec) break;
@@ -184,8 +208,13 @@ std::vector<NodeWidgetDescriptor> nodeWidgetCatalog() {
            if (!queryNodeWidgetDescriptor(desc.scriptPath, desc))
                continue;

            if (namesSeen.find(desc.name) != namesSeen.end())
                continue;

            namesSeen.insert(desc.name);
            catalog.push_back(std::move(desc));
        }
    }

    std::sort(catalog.begin(), catalog.end(), [](const NodeWidgetDescriptor &a, const NodeWidgetDescriptor &b) {
        return a.name < b.name;
+26 −0
Changes for editor/src/webedit_config.cpp: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
 *******************************************************************************/

#include <iostream>
#include <algorithm>
#include <confplus/exception.h>

#include "webedit_config.h"
@@ -115,6 +116,31 @@ webedit::Config::Config(const std::string &path) : confplus::Config(path) {
        _nodeRunner = "/usr/share/blogi-editor/node/node_widget_runner.js";
    }

    try {
        auto *widgetDirKey = getKey("/WEBEDIT/NODE/WIDGETDIR");
        size_t cnt = getElements(widgetDirKey);
        for (size_t i = 0; i < cnt; ++i) {
            std::string v = getValue(widgetDirKey, i);
            if (!v.empty())
                _nodeWidgetDirs.push_back(v);
        }
    } catch (...) {
        try {
            // Backward-compatible scalar form.
            std::string single = getValue(getKey("/WEBEDIT/NODE/WIDGETDIR"), 0);
            if (!single.empty())
                _nodeWidgetDirs.push_back(single);
        } catch (...) {
        }
    }

    if (_nodeWidgetDirs.empty()) {
        _nodeWidgetDirs.push_back("/usr/share/blogi-editor/node/widgets");
    }

    std::sort(_nodeWidgetDirs.begin(), _nodeWidgetDirs.end());
    _nodeWidgetDirs.erase(std::unique(_nodeWidgetDirs.begin(), _nodeWidgetDirs.end()), _nodeWidgetDirs.end());

    // Parse AUTHDB sources (indexed sequence-of-mappings:
    // /WEBEDIT/AUTHDB/<i>/URL, .../CLIENTNAME, .../CLIENTSECRET, .../DOMAIN)
    for (size_t i = 0; ; ++i) {
+2 −0
Changes for editor/src/webedit_config.h: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ namespace webedit {
        const std::string &getLanguage() const     { return _language; }
        const std::string &getNodeBinary() const   { return _nodeBinary; }
        const std::string &getNodeRunner() const   { return _nodeRunner; }
        const std::vector<std::string> &getNodeWidgetDirs() const { return _nodeWidgetDirs; }

        size_t getAuthSourceCount() const { return _authSources.size(); }
        const blogi::AuthSource &getAuthSource(size_t i) const { return _authSources[i]; }
@@ -84,6 +85,7 @@ namespace webedit {
        std::string _language;
        std::string _nodeBinary;
        std::string _nodeRunner;
        std::vector<std::string> _nodeWidgetDirs;

        std::vector<blogi::AuthSource> _authSources;
    };