From 28dadbec14aa50d96335548b8ba32231aceedda1 Mon Sep 17 00:00:00 2001 From: Kodai Aoyama Date: Sun, 10 Apr 2022 23:47:28 +0900 Subject: [PATCH 1/2] add query on api component --- command/cmd/api.go | 32 +++++++++++++++---- ui/src/rete.jsx | 12 ++++--- ui/src/rete/components/ApiComponent.js | 14 +++++--- ui/src/rete/components/MySQLComponent.js | 11 ++++--- ui/src/rete/components/PostgreSQLComponent.js | 11 ++++--- ui/src/rete/components/SQLiteComponent.js | 11 ++++--- .../components/input/DummyJsonComponent.js | 23 +++++++++++++ 7 files changed, 84 insertions(+), 30 deletions(-) create mode 100644 ui/src/rete/components/input/DummyJsonComponent.js diff --git a/command/cmd/api.go b/command/cmd/api.go index 1aa1c71..032a21e 100644 --- a/command/cmd/api.go +++ b/command/cmd/api.go @@ -110,7 +110,7 @@ func isDBNode(name string) bool { } func isJSONNode(name string) bool { - return isDBNode(name) || name == "JSON" || name == "API" || name == "JSONManager" || name == "Request" + return isDBNode(name) || name == "JSON" || name == "DummyJSON" || name == "API" || name == "JSONManager" || name == "Request" } func isJSONorHTMLNode(name string) bool { @@ -213,9 +213,17 @@ func contentBuilder(contents map[int]map[string]map[string]interface{}) func(req url := fmt.Sprintf("%v", content["url"]) cached := fmt.Sprintf("%v", content["cached"]) method := fmt.Sprintf("%v", content["method"]) + query := "" + for _, v1 := range c[i+1] { + if v1["parent"] == k { + if v1["name"] != "DummyJSON" { + query = v1["content"].(string) + } + } + } if cached == "true" { - v, ok := gache.Get(url) + v, ok := gache.Get(url+query) if ok { apiResponses = append(apiResponses, apiResponse{method, url, "cached"}) c[i][k]["content"] = v @@ -224,6 +232,18 @@ func contentBuilder(contents map[int]map[string]map[string]interface{}) func(req } req, _ := http.NewRequest(method, url, nil) + if(query != ""){ + params := request.URL.Query() + tmp := map[string]string{} + err := json.Unmarshal([]byte(query), &tmp) + if err != nil { + log.Fatal(err) + } + for k, v := range tmp { + params.Add(k,v) + } + req.URL.RawQuery = params.Encode() + } resp, err := client.Do(req) if err == nil && resp.StatusCode >= 400 { apiResponses = append(apiResponses, apiResponse{method, url, strconv.Itoa(resp.StatusCode)}) @@ -247,13 +267,13 @@ func contentBuilder(contents map[int]map[string]map[string]interface{}) func(req if cached == "true" { cacheTime := fmt.Sprintf("%v", content["cacheTime"]) if cacheTime == "" { - gache.Set(url, res) + gache.Set(url+query, res) } else { cacheTime, err := strconv.Atoi(cacheTime) if err != nil { - gache.Set(url, res) + log.Fatal(err) } else { - gache.SetWithExpire(url, res, time.Second*time.Duration(cacheTime)) + gache.SetWithExpire(url+query, res, time.Second*time.Duration(cacheTime)) } } } @@ -318,7 +338,7 @@ func contentBuilder(contents map[int]map[string]map[string]interface{}) func(req if v1["parent"] == k { if v1["name"] == "SQL" { query = v1["content"].(string) - } else if v1["name"] == "JSON" { + } else if v1["name"] == "DummyJSON" { dummyJSON = v1["content"].(string) } } diff --git a/ui/src/rete.jsx b/ui/src/rete.jsx index 7e9daad..37e8474 100644 --- a/ui/src/rete.jsx +++ b/ui/src/rete.jsx @@ -12,6 +12,7 @@ import AutoArrangePlugin from "rete-auto-arrange-plugin"; import HistoryPlugin from "rete-history-plugin"; import { JsonComponent } from "./rete/components/input/JsonComponent"; +import { DummyJsonComponent } from "./rete/components/input/DummyJsonComponent"; import { HtmlComponent } from "./rete/components/input/HtmlComponent"; import { SqlComponent } from "./rete/components/input/SqlComponent"; import { TemplateComponent } from "./rete/components/template/TemplateComponent"; @@ -39,6 +40,8 @@ export async function createEditor(container) { rawJsonSocket.combineWith(errorSocket); rawJsonSocket.combineWith(jsonSocket); rawJsonSocket.combineWith(stringSocket); + // dummyJson + const dummyJsonSocket = new Rete.Socket("DummyJson value"); // template const templateSocket = new Rete.Socket("Template value"); templateSocket.combineWith(stringSocket); @@ -62,15 +65,16 @@ export async function createEditor(container) { new EndpointWithErrorComponent(stringSocket, errorSocket), new JsonManagerComponent(jsonSocket), new JsonComponent(rawJsonSocket), + new DummyJsonComponent(dummyJsonSocket), new HtmlComponent(rawHtmlSocket), new TemplateComponent(jsonSocket, templateSocket, htmlSocket), new HandlebarsComponent(handlebarsSocket), new PugComponent(pugSocket), new SqlComponent(sqlSocket), - new ApiComponent(jsonSocket), - new MySQLComponent(jsonSocket, sqlSocket), - new PostgreSQLComponent(jsonSocket, sqlSocket), - new SQLiteComponent(jsonSocket, sqlSocket), + new ApiComponent(jsonSocket, dummyJsonSocket), + new MySQLComponent(jsonSocket, dummyJsonSocket, sqlSocket), + new PostgreSQLComponent(jsonSocket, dummyJsonSocket, sqlSocket), + new SQLiteComponent(jsonSocket, dummyJsonSocket, sqlSocket), new RequestComponent(jsonSocket), new RedirectEndpointComponent(), ]; diff --git a/ui/src/rete/components/ApiComponent.js b/ui/src/rete/components/ApiComponent.js index ecfe81d..470f340 100644 --- a/ui/src/rete/components/ApiComponent.js +++ b/ui/src/rete/components/ApiComponent.js @@ -8,22 +8,25 @@ import { SelectControl } from "../controls/SelectControl"; export class ApiComponent extends Rete.Component { path = ["New"]; - constructor(jsonSocket) { + constructor(jsonSocket, dummyJsonSocket) { super("API"); this.data.component = DefaultNode; // optional this.jsonSocket = jsonSocket; + this.dummyJsonSocket = dummyJsonSocket; } builder(node) { - const jsonInput = new Rete.Input( + const queryInput = new Rete.Input("query", "Query (JSON)", this.jsonSocket); + const dummyJsonInput = new Rete.Input( "json", - "Dummy Output (JSON)", - this.jsonSocket + "Output (DummyJSON)", + this.dummyJsonSocket ); const out = new Rete.Output("json", "JSON", this.jsonSocket); return node - .addInput(jsonInput) + .addInput(queryInput) + .addInput(dummyJsonInput) .addControl( new SelectControl(this.editor, "method", node, false, "Method", [ "GET", @@ -67,6 +70,7 @@ export class ApiComponent extends Rete.Component { } worker(node, inputs, outputs) { + outputs.query = inputs.query.length ? inputs.query[0] : node.data.query; outputs.json = inputs.json.length ? inputs.json[0] : node.data.json; outputs.url = node.data.url; outputs.cached = node.data.cached; diff --git a/ui/src/rete/components/MySQLComponent.js b/ui/src/rete/components/MySQLComponent.js index 81651f5..348ef6a 100644 --- a/ui/src/rete/components/MySQLComponent.js +++ b/ui/src/rete/components/MySQLComponent.js @@ -8,25 +8,26 @@ import { DbNode } from "../nodes/DbNode"; export class MySQLComponent extends Rete.Component { path = ["New"]; - constructor(jsonSocket, sqlSocket) { + constructor(jsonSocket, dummyJsonSocket, sqlSocket) { super("MySQL"); this.data.component = DbNode; // optional + this.dummyJsonSocket = dummyJsonSocket; this.jsonSocket = jsonSocket; this.sqlSocket = sqlSocket; } builder(node) { - const jsonInput = new Rete.Input( + const dummyJsonInput = new Rete.Input( "json", - "Dummy Output (JSON)", - this.jsonSocket + "Output (DummyJSON)", + this.dummyJsonSocket ); const out = new Rete.Output("json", "JSON", this.jsonSocket); const sqlInput = new Rete.Input("sql", "SQL", this.sqlSocket); return node .addInput(sqlInput) - .addInput(jsonInput) + .addInput(dummyJsonInput) .addControl( new SelectControl(this.editor, "tls", node, false, "TLS", [ "false", diff --git a/ui/src/rete/components/PostgreSQLComponent.js b/ui/src/rete/components/PostgreSQLComponent.js index b87547c..465d142 100644 --- a/ui/src/rete/components/PostgreSQLComponent.js +++ b/ui/src/rete/components/PostgreSQLComponent.js @@ -8,25 +8,26 @@ import { DbNode } from "../nodes/DbNode"; export class PostgreSQLComponent extends Rete.Component { path = ["New"]; - constructor(jsonSocket, sqlSocket) { + constructor(jsonSocket, dummyJsonSocket, sqlSocket) { super("PostgreSQL"); this.data.component = DbNode; // optional + this.dummyJsonSocket = dummyJsonSocket; this.jsonSocket = jsonSocket; this.sqlSocket = sqlSocket; } builder(node) { - const jsonInput = new Rete.Input( + const dummyJsonInput = new Rete.Input( "json", - "Dummy Output (JSON)", - this.jsonSocket + "Output (DummyJSON)", + this.dummyJsonSocket ); const out = new Rete.Output("json", "JSON", this.jsonSocket); const sqlInput = new Rete.Input("sql", "SQL", this.sqlSocket); return node .addInput(sqlInput) - .addInput(jsonInput) + .addInput(dummyJsonInput) .addControl( new SelectControl(this.editor, "tls", node, false, "SSLMODE", [ "disable", diff --git a/ui/src/rete/components/SQLiteComponent.js b/ui/src/rete/components/SQLiteComponent.js index eeb191f..b40318f 100644 --- a/ui/src/rete/components/SQLiteComponent.js +++ b/ui/src/rete/components/SQLiteComponent.js @@ -7,25 +7,26 @@ import { SQLiteNode } from "../nodes/SQLiteNode"; export class SQLiteComponent extends Rete.Component { path = ["New"]; - constructor(jsonSocket, sqlSocket) { + constructor(jsonSocket, dummyJsonSocket, sqlSocket) { super("SQLite"); this.data.component = SQLiteNode; // optional + this.dummyJsonSocket = dummyJsonSocket; this.jsonSocket = jsonSocket; this.sqlSocket = sqlSocket; } builder(node) { - const jsonInput = new Rete.Input( + const dummyJsonInput = new Rete.Input( "json", - "Dummy Output (JSON)", - this.jsonSocket + "Output (DummyJSON)", + this.dummyJsonSocket ); const out = new Rete.Output("json", "JSON", this.jsonSocket); const sqlInput = new Rete.Input("sql", "SQL", this.sqlSocket); return node .addInput(sqlInput) - .addInput(jsonInput) + .addInput(dummyJsonInput) .addControl( new TextControl( this.editor, diff --git a/ui/src/rete/components/input/DummyJsonComponent.js b/ui/src/rete/components/input/DummyJsonComponent.js new file mode 100644 index 0000000..81bfdbf --- /dev/null +++ b/ui/src/rete/components/input/DummyJsonComponent.js @@ -0,0 +1,23 @@ +import Rete from "rete"; +import { JsonControl } from "../../controls/JsonControl"; + +export class DummyJsonComponent extends Rete.Component { + path = ["New"]; + + constructor(socket) { + super("DummyJSON"); + this.socket = socket; + } + + builder(node) { + const out = new Rete.Output("json", "JSON", this.socket); + + return node + .addControl(new JsonControl(this.editor, "json", node)) + .addOutput(out); + } + + worker(node, inputs, outputs) { + outputs.json = node.data.json; + } +} From ab14212f5bc83b70094e923d97299ce396fbf540 Mon Sep 17 00:00:00 2001 From: Kodai Aoyama Date: Sun, 10 Apr 2022 23:48:55 +0900 Subject: [PATCH 2/2] update README --- README.ja.md | 2 +- README.md | 48 ++++++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/README.ja.md b/README.ja.md index 2430972..944fd22 100644 --- a/README.ja.md +++ b/README.ja.md @@ -72,7 +72,7 @@ brew upgrade tuna ```sh # wget または curl でインストール ## releasesタブの最新のバージョンを指定してください。 -VERSION=v0.0.16 +VERSION=v0.0.17 ## 利用OSを指定してください。 OS=linux_amd64 ## wget経由の場合 diff --git a/README.md b/README.md index 390fb42..65c1971 100644 --- a/README.md +++ b/README.md @@ -18,25 +18,33 @@ TUNA-Mayonnaise is a CommandLineTool to generate and serve JSON/HTML on the node
CLICK -- [Why](#why) -- [Get Started](#get-started) - - [Install](#install) - - [Usage](#usage) -- [Tool Features](#tool-features) - - [Template Engine](#template-engine) - - [API](#api) - - [Database](#database) -- [API Features](#api-features) - - [Monitoring](#monitoring) -- [UseCases](#usecases) - - [1. Serve Static JSON](#1-serve-static-json) - - [2. Serve Static HTML](#2-serve-static-html) - - [3. Serve Dynamic JSON](#3-serve-dynamic-json) - - [4. Serve Dynamic HTML](#4-serve-dynamic-html) -- [Dependencies](#dependencies) - - [BACKEND Dependencies](#backend-dependencies) - - [FRONTEND Dependencies](#frontend-dependencies) - - [FRONTEND DEV Dependencies](#frontend-dev-dependencies) +- [!tuna-mayonnaise](#) + - [Table of Contents](#table-of-contents) + - [Why](#why) + - [Get Started](#get-started) + - [Install](#install) + - [For MacOS (Homebrew)](#for-macos-homebrew) + - [For Others (Binary Releases)](#for-others-binary-releases) + - [Usage](#usage) + - [1. Launch a tool on your browser](#1-launch-a-tool-on-your-browser) + - [2. Serve your JSON/HTML](#2-serve-your-jsonhtml) + - [Tool Features](#tool-features) + - [Template Engine](#template-engine) + - [API](#api) + - [Database](#database) + - [Connection Options](#connection-options) + - [TLS / SSL](#tls--ssl) + - [API Features](#api-features) + - [Monitoring](#monitoring) + - [UseCases](#usecases) + - [1. Serve Static JSON](#1-serve-static-json) + - [2. Serve Static HTML](#2-serve-static-html) + - [3. Serve Dynamic JSON](#3-serve-dynamic-json) + - [4. Serve Dynamic HTML](#4-serve-dynamic-html) + - [Dependencies](#dependencies) + - [BACKEND Dependencies](#backend-dependencies) + - [FRONTEND Dependencies](#frontend-dependencies) + - [FRONTEND DEV Dependencies](#frontend-dev-dependencies)
@@ -74,7 +82,7 @@ you can download a binary release [here](https://github.com/solaoi/tuna-mayonnai ```sh # Install with wget or curl ## set the latest version on releases. -VERSION=v0.0.16 +VERSION=v0.0.17 ## set the OS you use. OS=linux ## case you use wget