|
13 | 13 | import edu.caltech.ipac.firefly.server.events.ServerEventManager; |
14 | 14 | import edu.caltech.ipac.firefly.server.security.SsoAdapter; |
15 | 15 | import edu.caltech.ipac.firefly.server.util.Logger; |
| 16 | +import edu.caltech.ipac.firefly.server.visualize.imageretrieve.URLFileRetriever; |
16 | 17 | import edu.caltech.ipac.util.AppProperties; |
| 18 | +import edu.caltech.ipac.util.FileUtil; |
| 19 | +import org.json.simple.JSONArray; |
17 | 20 | import org.json.simple.JSONObject; |
18 | 21 | import org.json.simple.parser.JSONParser; |
19 | 22 | import org.json.simple.parser.ParseException; |
@@ -56,6 +59,38 @@ public String doCommand(SrvParam params) throws Exception { |
56 | 59 | } |
57 | 60 | } |
58 | 61 |
|
| 62 | + public static class TextFile extends ServCommand { |
| 63 | + |
| 64 | + public String doCommand(SrvParam sp) throws Exception { |
| 65 | + long maxSize= sp.getOptionalLong(ServerParams.MAX_FILE_SIZE, FileUtil.MEG); |
| 66 | + JSONObject obj= new JSONObject(); |
| 67 | + JSONArray retAry= new JSONArray(); |
| 68 | + retAry.add(obj); |
| 69 | + var fileInfo= new URLFileRetriever().getFile(sp.getRequired(ServerParams.URL)); |
| 70 | + if (fileInfo.getResponseCode() != 200) { |
| 71 | + obj.put("success", false); |
| 72 | + obj.put("error", "Error retrieving file, status: "+fileInfo.getResponseCode()); |
| 73 | + obj.put("cause", "Error retrieving file, status: "+fileInfo.getResponseCode()); |
| 74 | + } |
| 75 | + if (fileInfo.getFile().length() > maxSize) { |
| 76 | + var sizeStr= FileUtil.getSizeAsString(fileInfo.getFile().length()); |
| 77 | + obj.put("success", false); |
| 78 | + obj.put("error", "File too large, size: "+sizeStr); |
| 79 | + obj.put("cause", "File too large, size: "+sizeStr); |
| 80 | + } |
| 81 | + else { |
| 82 | + String data= FileUtil.readFile(fileInfo.getFile()); |
| 83 | + obj.put("success", true); |
| 84 | + obj.put("data", data); |
| 85 | + } |
| 86 | + return retAry.toString(); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
59 | 94 | public static class JsonProperty extends ServCommand { |
60 | 95 | static final String INVENTORY_PROP = "inventory.serverURLAry"; |
61 | 96 | static final String FIREFLY_OPTIONS = "FIREFLY_OPTIONS"; |
|
0 commit comments