From ba9ddefbee6aad8b282f3990250a23e4f881729c Mon Sep 17 00:00:00 2001 From: Hiroyasu Nishiyama Date: Wed, 25 Jan 2023 16:06:37 +0900 Subject: [PATCH] removed endpoint --- .../editor-api/lib/editor/editor-libs.js | 33 ------------- .../@node-red/editor-api/lib/editor/index.js | 5 -- .../editor-client/src/js/ui/mermaid.js | 2 +- .../editor-api/lib/editor/editor-libs_spec.js | 49 ------------------- 4 files changed, 1 insertion(+), 88 deletions(-) delete mode 100644 packages/node_modules/@node-red/editor-api/lib/editor/editor-libs.js delete mode 100644 test/unit/@node-red/editor-api/lib/editor/editor-libs_spec.js diff --git a/packages/node_modules/@node-red/editor-api/lib/editor/editor-libs.js b/packages/node_modules/@node-red/editor-api/lib/editor/editor-libs.js deleted file mode 100644 index 98391dc12..000000000 --- a/packages/node_modules/@node-red/editor-api/lib/editor/editor-libs.js +++ /dev/null @@ -1,33 +0,0 @@ -// Dynamic loading support for editor libraries - -var apiUtils = require("../util"); -var fs = require("fs"); -var path = require("path"); - -var lib2path = { - "mermaid": "../../../editor-client/public/vendor/mermaid/mermaid.min.js", -}; - -module.exports = { - init: function(_settings, _runtimeAPI) { - settings = _settings; - }, - - get: function(req,res) { - var name = req.params.name; - - if (name in lib2path) { - try { - var lib = path.join(__dirname, lib2path[name]); - var code = fs.readFileSync(lib); - res.send(code); - } - catch (e) { - res.status(500).json({code: "runtime_error", message: e.toString()}); - } - } - else { - res.status(400).json({code: "invalid_request", message: `no library: ${name}`}); - } - }, -} diff --git a/packages/node_modules/@node-red/editor-api/lib/editor/index.js b/packages/node_modules/@node-red/editor-api/lib/editor/index.js index 66d088f3a..f210d90fe 100644 --- a/packages/node_modules/@node-red/editor-api/lib/editor/index.js +++ b/packages/node_modules/@node-red/editor-api/lib/editor/index.js @@ -116,11 +116,6 @@ module.exports = { // SSH keys editorApp.use("/settings/user/keys",needsPermission("settings.write"),info.sshkeys()); - // Editor Libraries - var editorLibs = require("./editor-libs"); - editorLibs.init(settings, runtimeAPI); - editorApp.get("/editor-libs/:name", needsPermission("editor-libs.read"), editorLibs.get, apiUtil.errorHandler); - return editorApp; } }, diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/mermaid.js b/packages/node_modules/@node-red/editor-client/src/js/ui/mermaid.js index f16aae5a0..d126cf188 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/mermaid.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/mermaid.js @@ -18,7 +18,7 @@ var mermaid = (function () { } if (enabled) { initializing = true; - $.getScript("/editor-libs/mermaid", + $.getScript("vendor/mermaid/mermaid.min.js", function (data, stat, jqxhr) { $(".mermaid").show(); // invoke loaded mermaid API diff --git a/test/unit/@node-red/editor-api/lib/editor/editor-libs_spec.js b/test/unit/@node-red/editor-api/lib/editor/editor-libs_spec.js deleted file mode 100644 index 4a8158d74..000000000 --- a/test/unit/@node-red/editor-api/lib/editor/editor-libs_spec.js +++ /dev/null @@ -1,49 +0,0 @@ -const should = require("should"); -const request = require('supertest'); -const express = require('express'); -const bodyParser = require("body-parser"); -const sinon = require('sinon'); - -let app; - -const NR_TEST_UTILS = require("nr-test-utils"); -const editorLibs = NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/editor-libs"); - -describe("api/editor/editor-libs", function() { - before(function() { - app = express(); - app.use(bodyParser.json()); - app.get("/editor-libs/:name", editorLibs.get); - }); - - it("returns the editor library for mermaid", function(done) { - const settings = {}; - const runtimeAPI = {}; - - editorLibs.init(settings, runtimeAPI); - - request(app) - .get("/editor-libs/mermaid") - .expect(200) - .end(function(err,res) { - if (err || (typeof res.error === "object")) { - return done(err || res.error); - } - res.should.have.property("statusCode",200); - res.should.have.property("_body"); - done(); - }); - }); - - it('should error when called with unknown library', function(done) { - const settings = {}; - const runtimeAPI = {}; - - editorLibs.init(settings, runtimeAPI); - - request(app) - .get("/editor-libs/unknown") - .expect(400) - .end(done); - }); -});