From 6c6f2cd2a3abb47d42803a2c8497caa5e4daa5af Mon Sep 17 00:00:00 2001 From: James ZHOU Date: Sun, 18 Feb 2024 19:53:37 +0800 Subject: [PATCH] Use @Action annotation to instead of setAction. Update the tinystruct version to be 1.1.8. --- bin/dispatcher | 2 +- bin/dispatcher.cmd | 2 +- pom.xml | 2 +- .../java/custom/application/v1/smalltalk.java | 27 +++++++++---------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/bin/dispatcher b/bin/dispatcher index a01fd19..933847a 100755 --- a/bin/dispatcher +++ b/bin/dispatcher @@ -1,6 +1,6 @@ #!/usr/bin/env sh ROOT="$(pwd)" -VERSION="1.1.7" +VERSION="1.1.8" cd "$(dirname "$0")" || exit cd "../" # Navigate to the root directory diff --git a/bin/dispatcher.cmd b/bin/dispatcher.cmd index b43827e..c185571 100755 --- a/bin/dispatcher.cmd +++ b/bin/dispatcher.cmd @@ -15,6 +15,6 @@ @rem *************************************************************************** @echo off set "ROOT=%~dp0..\" -set "VERSION=1.1.7" +set "VERSION=1.1.8" set "classpath=%ROOT%target\classes:%ROOT%lib\*:%ROOT%WEB-INF\lib\*:%ROOT%WEB-INF\classes":%classpath% @java -cp "%ROOT%target\classes;%ROOT%lib\tinystruct-%VERSION%-jar-with-dependencies.jar;%ROOT%lib\*;%ROOT%WEB-INF\lib\*;%ROOT%WEB-INF\classes;%USERPROFILE%\.m2\repository\org\tinystruct\tinystruct\%VERSION%\tinystruct-%VERSION%-jar-with-dependencies.jar" org.tinystruct.system.Dispatcher %* \ No newline at end of file diff --git a/pom.xml b/pom.xml index b85a5ea..cd577c9 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ org.tinystruct tinystruct - 1.1.7 + 1.1.8 diff --git a/src/main/java/custom/application/v1/smalltalk.java b/src/main/java/custom/application/v1/smalltalk.java index 2ace6cd..d486be6 100644 --- a/src/main/java/custom/application/v1/smalltalk.java +++ b/src/main/java/custom/application/v1/smalltalk.java @@ -15,6 +15,7 @@ import org.tinystruct.handler.Reforward; import org.tinystruct.http.*; import org.tinystruct.system.ApplicationManager; +import org.tinystruct.system.annotation.Action; import org.tinystruct.system.template.variable.Variable; import org.tinystruct.system.util.Matrix; import org.tinystruct.transfer.DistributedMessageQueue; @@ -44,23 +45,10 @@ public class smalltalk extends DistributedMessageQueue implements SessionListene public void init() { super.init(); - this.setAction("talk", "index"); - this.setAction("talk/join", "join"); - this.setAction("talk/start", "start"); - this.setAction("talk/save", "save"); - this.setAction("talk/update", "update"); - this.setAction("talk/upload", "upload"); - this.setAction("talk/command", "command"); - this.setAction("talk/topic", "topic"); - this.setAction("talk/matrix", "matrix"); - this.setAction("files", "download"); - this.setAction("chat", "chat"); - this.commandLines.get("chat").setDescription("Chat with ChatGPT in command-line."); - this.setVariable("message", ""); this.setVariable("topic", ""); -// set env with LANG=en_US.UTF-8 +// Set env with LANG=en_US.UTF-8 System.setProperty("LANG", "en_US.UTF-8"); SessionManager.getInstance().addListener(this); @@ -76,6 +64,7 @@ public void init() { } } + @Action("talk") public smalltalk index() { final Request request = (Request) this.context.getAttribute(HTTP_REQUEST); final Response response = (Response) this.context.getAttribute(HTTP_RESPONSE); @@ -122,10 +111,12 @@ public smalltalk index() { return this; } + @Action("talk/update") public String update(String sessionId) throws ApplicationException { return this.take(sessionId); } + @Action("talk/matrix") public String matrix(String meetingCode) throws ApplicationException { final Request request = (Request) this.context.getAttribute(HTTP_REQUEST); final Response response = (Response) this.context.getAttribute(HTTP_RESPONSE); @@ -140,6 +131,7 @@ public String matrix(String meetingCode) throws ApplicationException { return ""; } + @Action("talk/join") public Object join(String meetingCode) throws ApplicationException { if (groups.containsKey(meetingCode)) { final Request request = (Request) this.context.getAttribute(HTTP_REQUEST); @@ -156,6 +148,7 @@ public Object join(String meetingCode) throws ApplicationException { } } + @Action("talk/start") public Object start(String name) throws ApplicationException { final Request request = (Request) this.context.getAttribute(HTTP_REQUEST); final Response response = (Response) this.context.getAttribute(HTTP_RESPONSE); @@ -173,6 +166,7 @@ public Object start(String name) throws ApplicationException { return name; } + @Action("talk/command") public String command() { final Request request = (Request) this.context.getAttribute(HTTP_REQUEST); final Object meetingCode = request.getSession().getAttribute("meeting_code"); @@ -195,6 +189,7 @@ public String command() { return "{ \"error\": \"expired\" }"; } + @Action("talk/save") public String save() { final Request request = (Request) this.context.getAttribute(HTTP_REQUEST); final Object meetingCode = request.getSession().getAttribute("meeting_code"); @@ -264,6 +259,7 @@ public void run() { return "{ \"error\": \"expired\" }"; } + @Action("chat") public void chat() { this.cli_mode = true; if (this.config.get("openai.api_key") == null || this.config.get("openai.api_key").isEmpty()) { @@ -755,6 +751,7 @@ public String update(String meetingCode, String sessionId) throws ApplicationExc return "{}"; } + @Action("talk/upload") public String upload() throws ApplicationException { final Request request = (Request) this.context.getAttribute(HTTP_REQUEST); final Object meetingCode = request.getSession().getAttribute("meeting_code"); @@ -845,10 +842,12 @@ public byte[] download(String fileName, boolean encoded) throws ApplicationExcep return arr; } + @Action("files") public byte[] download(String fileName) throws ApplicationException { return this.download(fileName, true); } + @Action("talk/topic") public boolean topic() { final Request request = (Request) this.context.getAttribute(HTTP_REQUEST); final Object meeting_code = request.getSession().getAttribute("meeting_code");