From decc0598b103845abf7458226992b3ed6f187c2d Mon Sep 17 00:00:00 2001 From: Steven Tracey Date: Wed, 20 Dec 2023 09:56:47 -0600 Subject: [PATCH] Fixed JSON as plaintext --- .idea/workspace.xml | 19 ++++--------------- .../java/tech/nevets/ngxinstaller/Server.java | 17 +++++++++++++++++ .../tech/nevets/ngxinstaller/TextStorage.java | 6 +++++- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9edef76..2f60d55 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,20 +5,9 @@ - - - - - - - - - - - - - - + + + diff --git a/src/main/java/tech/nevets/ngxinstaller/Server.java b/src/main/java/tech/nevets/ngxinstaller/Server.java index 9e56819..b3328cf 100644 --- a/src/main/java/tech/nevets/ngxinstaller/Server.java +++ b/src/main/java/tech/nevets/ngxinstaller/Server.java @@ -4,6 +4,8 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.Timer; import java.util.TimerTask; @@ -21,6 +23,21 @@ public class Server { get("/ngx/raw/*", (req, res) -> { String id = req.splat()[0]; TextStorage ts = TextStorage.getPaste(id); + res.type("text/plain"); + if (ts == null) { + res.status(404); + return "Content Not Found!"; + } + return URLDecoder.decode(ts.getText(), StandardCharsets.UTF_8); + }); + get("/ngx/json/*", (req, res) -> { + String id = req.splat()[0]; + TextStorage ts = TextStorage.getPaste(id); + res.type("application/json"); + if (ts == null) { + res.status(404); + return "{\"error\":\"content not found\"}"; + } return GSON.toJson(ts); }); diff --git a/src/main/java/tech/nevets/ngxinstaller/TextStorage.java b/src/main/java/tech/nevets/ngxinstaller/TextStorage.java index 6308365..3f96019 100644 --- a/src/main/java/tech/nevets/ngxinstaller/TextStorage.java +++ b/src/main/java/tech/nevets/ngxinstaller/TextStorage.java @@ -23,6 +23,10 @@ public class TextStorage { return this.id; } + public String getText() { + return this.text; + } + public static TextStorage getPaste(String id) { for (TextStorage ts : DB) { if (ts.id.equals(id)) { @@ -33,7 +37,7 @@ public class TextStorage { } public static TextStorage createPaste(String text) { - TextStorage ts = new TextStorage(generateId(), text, System.currentTimeMillis() + 3600000); + TextStorage ts = new TextStorage(generateId(), text, System.currentTimeMillis() + 1800000); DB.add(ts); return ts; }