Commit 6720876a authored by jan.koester's avatar jan.koester
Browse files

test

parent f3de00c9
Loading
Loading
Loading
Loading
+55 −27
Original line number Diff line number Diff line
@@ -99,7 +99,21 @@ bool queryNodeWidgetDescriptor(const std::string &scriptPath, NodeWidgetDescript
    writeFile(reqPath, reqJson ? reqJson : "{}");
    json_object_put(req);

    try {
        (void)blogi::webedit::embedded::runNodeRunner(reqPath, resPath);
    } catch (const std::exception &e) {
        std::cerr << "[webedit] node metadata failed for " << scriptPath
                  << ": " << e.what() << std::endl;
        std::remove(reqPath.c_str());
        std::remove(resPath.c_str());
        return false;
    } catch (...) {
        std::cerr << "[webedit] node metadata failed for " << scriptPath
                  << ": unknown exception" << std::endl;
        std::remove(reqPath.c_str());
        std::remove(resPath.c_str());
        return false;
    }

    std::string raw = readFile(resPath);
    json_object *res = raw.empty() ? nullptr : json_tokener_parse(raw.c_str());
@@ -178,6 +192,7 @@ std::vector<NodeWidgetDescriptor> nodeWidgetCatalog() {
        if (!std::filesystem::exists(widgetsDir, ec) || ec)
            continue;

        try {
            for (const auto &entry : std::filesystem::directory_iterator(widgetsDir, ec)) {
                if (ec) break;
                if (!entry.is_regular_file()) continue;
@@ -201,6 +216,13 @@ std::vector<NodeWidgetDescriptor> nodeWidgetCatalog() {
                namesSeen.insert(desc.name);
                catalog.push_back(std::move(desc));
            }
        } catch (const std::exception &e) {
            std::cerr << "[webedit] failed to scan widget dir '" << widgetsDir
                      << "': " << e.what() << std::endl;
        } catch (...) {
            std::cerr << "[webedit] failed to scan widget dir '" << widgetsDir
                      << "': unknown exception" << std::endl;
        }
    }

    std::sort(catalog.begin(), catalog.end(), [](const NodeWidgetDescriptor &a, const NodeWidgetDescriptor &b) {
@@ -586,6 +608,7 @@ bool webedit::Api::handleRequest(libhttppp::HttpRequest &curreq, const int tid,
void webedit::Api::handleGetPlugins(libhttppp::HttpRequest &curreq) {
    json_object *arr = json_object_new_array();

    try {
        const auto catalog = nodeWidgetCatalog();
        for (const auto &desc : catalog) {
            json_object *obj = json_object_new_object();
@@ -596,6 +619,11 @@ void webedit::Api::handleGetPlugins(libhttppp::HttpRequest &curreq) {
            json_object_object_add(obj, "can_have_children", json_object_new_boolean(desc.canHaveChildren));
            json_object_array_add(arr, obj);
        }
    } catch (const std::exception &e) {
        std::cerr << "[webedit] handleGetPlugins failed: " << e.what() << std::endl;
    } catch (...) {
        std::cerr << "[webedit] handleGetPlugins failed: unknown exception" << std::endl;
    }

    json_object *resp = json_object_new_object();
    json_object_object_add(resp, "plugins", arr);