Skip to content

Commit

Permalink
java: search for fileName by path added + json-data fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rivexe committed Feb 17, 2023
1 parent 63b7641 commit e88c2e9
Showing 1 changed file with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@

import static utils.Constants.KILOBYTE_SIZE;


@WebServlet(name = "IndexServlet", urlPatterns = {"/IndexServlet"})
@MultipartConfig
public class IndexServlet extends HttpServlet {
Expand Down Expand Up @@ -650,15 +649,43 @@ private static void reference(final HttpServletRequest request,

JSONParser parser = new JSONParser();
JSONObject body = (JSONObject) parser.parse(bodyString);
String instanceId = (String) body.get("instanceId");
JSONObject fileKey = (JSONObject) body.get("fileKey");
String fileKeyValue = gson.toJson(fileKey);
JSONObject referenceDataObj = (JSONObject) body.get("referenceData");
String instanceId = (String) referenceDataObj.get("instanceId");

String fileKeyValue = "";
String userAddress = "";
String fileName = "";

if (instanceId.equals(DocumentManager.getServerUrl(false))) {
JSONObject fileKey = (JSONObject) referenceDataObj.get("fileKey");
fileKeyValue = gson.toJson(fileKey);
userAddress = (String) fileKey.get("userAddress");
if (userAddress.equals(DocumentManager.curUserHostAddress(null))) {
fileName = (String) fileKey.get("fileName");
}
}

if (fileName.equals("") && !userAddress.equals("")) {
try {
String path = (String) body.get("path");
path = FileUtility.getFileName(path);
File f = new File(DocumentManager.storagePath(path, userAddress));
if (f.exists()) {
fileName = path;
}
} catch (Exception e) {
e.printStackTrace();
writer.write("{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}");
}
}

String fileName = (String) fileKey.get("fileName");
String userAddress = (String) fileKey.get("userAddress");
if (fileName.equals("")) {
writer.write("{ \"error\": \"File not found\"}");
return;
}

HashMap<String, Object> referenceData = new HashMap<>();
referenceData.put("instanceId", DocumentManager.getServerUrl(true));
referenceData.put("instanceId", DocumentManager.getServerUrl(false));
referenceData.put("fileKey", fileKeyValue);

HashMap<String, Object> data = new HashMap<>();
Expand Down

0 comments on commit e88c2e9

Please sign in to comment.