Skip to content

Commit

Permalink
Use @action annotation to instead of setAction. Update the tinystruct…
Browse files Browse the repository at this point in the history
… version to be 1.1.8.
  • Loading branch information
m0ver committed Feb 18, 2024
1 parent 35f50c6 commit 6c6f2cd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bin/dispatcher
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/dispatcher.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 %*
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>org.tinystruct</groupId>
<artifactId>tinystruct</artifactId>
<version>1.1.7</version>
<version>1.1.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/custom/application/v1/smalltalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 6c6f2cd

Please sign in to comment.