|
64 | 64 |
|
65 | 65 | import static utils.Constants.KILOBYTE_SIZE;
|
66 | 66 |
|
67 |
| - |
68 | 67 | @WebServlet(name = "IndexServlet", urlPatterns = {"/IndexServlet"})
|
69 | 68 | @MultipartConfig
|
70 | 69 | public class IndexServlet extends HttpServlet {
|
@@ -650,15 +649,43 @@ private static void reference(final HttpServletRequest request,
|
650 | 649 |
|
651 | 650 | JSONParser parser = new JSONParser();
|
652 | 651 | JSONObject body = (JSONObject) parser.parse(bodyString);
|
653 |
| - String instanceId = (String) body.get("instanceId"); |
654 |
| - JSONObject fileKey = (JSONObject) body.get("fileKey"); |
655 |
| - String fileKeyValue = gson.toJson(fileKey); |
| 652 | + JSONObject referenceDataObj = (JSONObject) body.get("referenceData"); |
| 653 | + String instanceId = (String) referenceDataObj.get("instanceId"); |
| 654 | + |
| 655 | + String fileKeyValue = ""; |
| 656 | + String userAddress = ""; |
| 657 | + String fileName = ""; |
| 658 | + |
| 659 | + if (instanceId.equals(DocumentManager.getServerUrl(false))) { |
| 660 | + JSONObject fileKey = (JSONObject) referenceDataObj.get("fileKey"); |
| 661 | + fileKeyValue = gson.toJson(fileKey); |
| 662 | + userAddress = (String) fileKey.get("userAddress"); |
| 663 | + if (userAddress.equals(DocumentManager.curUserHostAddress(null))) { |
| 664 | + fileName = (String) fileKey.get("fileName"); |
| 665 | + } |
| 666 | + } |
| 667 | + |
| 668 | + if (fileName.equals("") && !userAddress.equals("")) { |
| 669 | + try { |
| 670 | + String path = (String) body.get("path"); |
| 671 | + path = FileUtility.getFileName(path); |
| 672 | + File f = new File(DocumentManager.storagePath(path, userAddress)); |
| 673 | + if (f.exists()) { |
| 674 | + fileName = path; |
| 675 | + } |
| 676 | + } catch (Exception e) { |
| 677 | + e.printStackTrace(); |
| 678 | + writer.write("{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}"); |
| 679 | + } |
| 680 | + } |
656 | 681 |
|
657 |
| - String fileName = (String) fileKey.get("fileName"); |
658 |
| - String userAddress = (String) fileKey.get("userAddress"); |
| 682 | + if (fileName.equals("")) { |
| 683 | + writer.write("{ \"error\": \"File not found\"}"); |
| 684 | + return; |
| 685 | + } |
659 | 686 |
|
660 | 687 | HashMap<String, Object> referenceData = new HashMap<>();
|
661 |
| - referenceData.put("instanceId", DocumentManager.getServerUrl(true)); |
| 688 | + referenceData.put("instanceId", DocumentManager.getServerUrl(false)); |
662 | 689 | referenceData.put("fileKey", fileKeyValue);
|
663 | 690 |
|
664 | 691 | HashMap<String, Object> data = new HashMap<>();
|
|
0 commit comments