From eec3c35cb1eac47c4ac6a93eb461484a25bd1f59 Mon Sep 17 00:00:00 2001 From: "zokutyou2@gmail.com" Date: Wed, 14 Jul 2021 22:03:49 +0900 Subject: [PATCH] change command history into mitmproxy's one --- mitmproxy/tools/web/app.py | 4 ++-- web/src/js/components/CommandBar.tsx | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/mitmproxy/tools/web/app.py b/mitmproxy/tools/web/app.py index 0bf0f1d51..b0aa6f15e 100644 --- a/mitmproxy/tools/web/app.py +++ b/mitmproxy/tools/web/app.py @@ -462,14 +462,14 @@ class Commands(RequestHandler): } for parameter in command.parameters: commands[name]["args"].append(parameter.name) - self.write({"commands": commands, "history": self.master.commands.execute("commands.history.get")}) + self.write({"commands": commands}) def post(self): result = self.master.commands.execute(self.json["command"]) if result is None: self.write({"result": ""}) return - self.write({"result": result, "type": type(result).__name__}) + self.write({"result": result, "type": type(result).__name__, "history": self.master.commands.execute("commands.history.get")}) class Events(RequestHandler): diff --git a/web/src/js/components/CommandBar.tsx b/web/src/js/components/CommandBar.tsx index 2508c42f3..82bc4e60b 100644 --- a/web/src/js/components/CommandBar.tsx +++ b/web/src/js/components/CommandBar.tsx @@ -84,8 +84,6 @@ export default function CommandBar() { const onKeyDown = (e) => { if (e.keyCode === Key.ENTER) { const body = {"command": input} - const newHistory = Object.assign([], history) - newHistory.splice(currentPos, 0, input) fetchApi(`/commands`, { method: 'POST', @@ -96,13 +94,19 @@ export default function CommandBar() { }) .then(response => response.json()) .then(data => { - setHistory(newHistory) + setHistory(data.history) setCurrentPos(currentPos + 1) setNextArgs([]) - - setResults([...results, {"id": results.length, "result": data.result}]) + setResults([...results, { + "id": results.length, + "command": input, + "result": JSON.stringify(data.result) + }]) }) + setSignatureHelp("") + setDescription("") + setInput("") setOriginalInput("") } @@ -130,7 +134,6 @@ export default function CommandBar() { const onKeyUp = (e) => { if (input == "") return - console.log("keyup event") parseCommand(originalInput, input) e.stopPropagation() } @@ -143,6 +146,7 @@ export default function CommandBar() {
{results.map(result => (
+
$ {result.command}
{result.result}
))}