Skip to content

Commit 0c31c2e

Browse files
authored
Firefly-1701: Merge PR #1741 from FIREFLY-1701-mpv-more-support
Firefly-1701: DataProductViewer: add pdf, yaml, json html, and text files
2 parents 244cf6e + 8742de7 commit 0c31c2e

27 files changed

Lines changed: 482 additions & 151 deletions

src/firefly/java/edu/caltech/ipac/firefly/core/FileAnalysis.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static FileAnalysisReport analyze(FileInfo fileInfo,
6868
if (responseCode>=400) {
6969
return analyzeError(infile, responseCode, contentType);
7070
}
71-
if (contentType!=null && contentType.toLowerCase().equals("text/html")) {
71+
if (contentType!=null && contentType.equalsIgnoreCase("text/html")) {
7272
return analyzeLoadInBrowser(infile, contentType);
7373
}
7474
switch (format) {

src/firefly/java/edu/caltech/ipac/firefly/data/ServerParams.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ public class ServerParams {
179179

180180
public static final String INIT_APP = "CmdInitApp";
181181
public static final String JSON_PROPERTY= "CmdJsonProperty";
182+
public static final String TEXT_FILE= "CmdTextFile";
182183
public static final String LOGOUT = "CmdLogout";
184+
public static final String MAX_FILE_SIZE = "maxFileSize";
183185
public static final String TILE_SIZE = "tileSize";
184186
public static final String DATA_COMPRESS = "dataCompress";
185187
public static final String POINT_SIZE= "pointSize";

src/firefly/java/edu/caltech/ipac/firefly/server/AppServerCommands.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
import edu.caltech.ipac.firefly.server.events.ServerEventManager;
1414
import edu.caltech.ipac.firefly.server.security.SsoAdapter;
1515
import edu.caltech.ipac.firefly.server.util.Logger;
16+
import edu.caltech.ipac.firefly.server.visualize.imageretrieve.URLFileRetriever;
1617
import edu.caltech.ipac.util.AppProperties;
18+
import edu.caltech.ipac.util.FileUtil;
19+
import org.json.simple.JSONArray;
1720
import org.json.simple.JSONObject;
1821
import org.json.simple.parser.JSONParser;
1922
import org.json.simple.parser.ParseException;
@@ -56,6 +59,38 @@ public String doCommand(SrvParam params) throws Exception {
5659
}
5760
}
5861

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+
5994
public static class JsonProperty extends ServCommand {
6095
static final String INVENTORY_PROP = "inventory.serverURLAry";
6196
static final String FIREFLY_OPTIONS = "FIREFLY_OPTIONS";

src/firefly/java/edu/caltech/ipac/firefly/server/ServerCommandAccess.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ private static void initCommand() {
103103
_cmdMap.put(ServerParams.LOGOUT, new AppServerCommands.Logout());
104104
_cmdMap.put(ServerParams.GET_USER_INFO, new AppServerCommands.GetUserInfo());
105105
_cmdMap.put(ServerParams.GET_ALERTS, new AppServerCommands.GetAlerts());
106+
_cmdMap.put(ServerParams.TEXT_FILE, new AppServerCommands.TextFile());
106107

107108
}
108109

src/firefly/java/edu/caltech/ipac/firefly/server/SrvParam.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,20 @@ public float getOptionalFloat(String key, float defValue) {
216216
}
217217
}
218218

219+
public long getOptionalLong(String key, long defValue) {
220+
String[] ary = paramMap.get(key);
221+
if (ary != null && ary.length>0) {
222+
try {
223+
return Long.parseLong(ary[0]);
224+
} catch (NumberFormatException e) {
225+
return defValue;
226+
}
227+
}
228+
else {
229+
return defValue;
230+
}
231+
}
232+
219233
public int getOptionalInt(String key, int defValue) {
220234
String[] ary = paramMap.get(key);
221235
if (ary != null && ary.length>0) {

src/firefly/java/edu/caltech/ipac/firefly/server/servlets/AnyFileDownload.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private void handleExternalURLRequest(HttpServletRequest req, HttpServletRespons
159159
File dFile= File.createTempFile("tmp-","-"+fileName ,ServerContext.getUploadDir());
160160
FileInfo fi;
161161
try {
162-
fi = URLDownload.getDataToFile(url, dFile);
162+
fi = URLDownload.getDataToFile(url, dFile, null, null, URLDownload.Options.defWithRedirect());
163163
} catch (FailedRequestException e) {
164164
res.sendError(404, e.toString());
165165
return;

src/firefly/java/edu/caltech/ipac/firefly/server/visualize/imageretrieve/URLFileRetriever.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public FileInfo getFile(WebPlotRequest request) throws FailedRequestException, G
4646
return getFile(request,true);
4747
}
4848

49+
public FileInfo getFile(String urlStr) throws FailedRequestException, GeomException, SecurityException {
50+
WebPlotRequest request = WebPlotRequest.makeURLPlotRequest(urlStr);
51+
request.setUrlCheckForNewer(true);
52+
return getFile(request,true);
53+
}
54+
4955
public FileInfo getFile(WebPlotRequest request, boolean handleAllErrors) throws FailedRequestException, GeomException, SecurityException {
5056
FileInfo fitsFileInfo;
5157
String urlStr = request.getURL();

src/firefly/java/edu/caltech/ipac/visualize/net/AnyUrlParams.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class AnyUrlParams extends BaseNetParams {
1818
public static List<String> DEF_EXT_LIST=
1919
Arrays.asList(
2020
"ul", FileUtil.FITS, FileUtil.GZ, FileUtil.TAR, FileUtil.PDF, FileUtil.GZ, FileUtil.REG,
21-
"votable", FileUtil.VOT, FileUtil.XML, FileUtil.TBL, FileUtil.CSV, FileUtil.TSV,
21+
"votable", FileUtil.VOT, FileUtil.XML, FileUtil.TBL, FileUtil.CSV, FileUtil.TSV, FileUtil.TXT,
2222
FileUtil.jpeg, FileUtil.jpg, FileUtil.png, FileUtil.bmp, FileUtil.gif, FileUtil.tiff, FileUtil.tif);
2323

2424
private final static int MAX_LENGTH = 30;

src/firefly/js/core/JsonUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function jsonFetch(url, params, doPost, useBigInt) {
3737
if (toBoolean(result[0].success)) {
3838
resolve(result[0].data ? result[0].data : result[0]);
3939
} else if (has(result, '0.error')) {
40-
reject(new Error(result[0].error, { cause: result[0].cause1}));
40+
reject(new Error(result[0].error, { cause: result[0].cause1 ?? result[0].cause}));
4141
} else {
4242
reject(new Error(`Unrecognized result: ${result}`));
4343
}

src/firefly/js/data/ServerParams.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export const ServerParams = {
159159
LOG_OUT: 'CmdLogout',
160160
INIT_APP: 'CmdInitApp',
161161
JSON_PROPERTY: 'CmdJsonProperty',
162+
TEXT_FILE: 'CmdTextFile',
162163
GET_IMAGE_MASTER_DATA: 'getImageMasterData',
163164
GET_FLOAT_DATA: 'getFloatData',
164165
GET_BYTE_DATA: 'getStretchedByteData',
@@ -167,6 +168,7 @@ export const ServerParams = {
167168
VIS_PUSH_ALIVE_CHECK: 'pushAliveCheck',
168169
VIS_PUSH_ALIVE_COUNT: 'pushAliveCount',
169170
VIS_PUSH_ACTION: 'pushAction',
171+
MAX_FILE_SIZE: 'maxFileSize',
170172
TILE_SIZE: 'tileSize',
171173
DATA_COMPRESS: 'dataCompress',
172174
POINT_SIZE: 'pointSize',

0 commit comments

Comments
 (0)