|
57 | 57 | import java.nio.file.Files;
|
58 | 58 | import java.nio.file.Path;
|
59 | 59 | import java.nio.file.Paths;
|
60 |
| -import java.util.ArrayList; |
61 |
| -import java.util.HashMap; |
62 |
| -import java.util.Map; |
63 |
| -import java.util.Scanner; |
| 60 | +import java.util.*; |
64 | 61 |
|
65 | 62 | import static utils.Constants.KILOBYTE_SIZE;
|
66 | 63 |
|
@@ -650,15 +647,45 @@ private static void reference(final HttpServletRequest request,
|
650 | 647 |
|
651 | 648 | JSONParser parser = new JSONParser();
|
652 | 649 | 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); |
| 650 | + JSONObject referenceDataObj = (JSONObject) body.get("referenceData"); |
| 651 | + String instanceId = (String) referenceDataObj.get("instanceId"); |
656 | 652 |
|
657 |
| - String fileName = (String) fileKey.get("fileName"); |
658 |
| - String userAddress = (String) fileKey.get("userAddress"); |
| 653 | + String fileKeyValue = ""; |
| 654 | + String userAddress = ""; |
| 655 | + String fileName = ""; |
| 656 | + |
| 657 | + if (Objects.equals(instanceId, DocumentManager.getServerUrl(false))) { |
| 658 | + JSONObject fileKey = (JSONObject) referenceDataObj.get("fileKey"); |
| 659 | + fileKeyValue = gson.toJson(fileKey); |
| 660 | + userAddress = (String) fileKey.get("userAddress"); |
| 661 | + if (Objects.equals(userAddress, DocumentManager.curUserHostAddress(null))) { |
| 662 | + fileName = (String) fileKey.get("fileName"); |
| 663 | + } |
| 664 | + } |
| 665 | + |
| 666 | + if (Objects.equals(fileName, "") && !Objects.equals(userAddress, "")) |
| 667 | + { |
| 668 | + try { |
| 669 | + String path = (String) body.get("path"); |
| 670 | + path = FileUtility.getFileName(path); |
| 671 | + File f = new File(DocumentManager.storagePath(path, userAddress)); |
| 672 | + if (f.exists()) |
| 673 | + { |
| 674 | + fileName = path; |
| 675 | + } |
| 676 | + } catch (Exception e) { |
| 677 | + e.printStackTrace(); |
| 678 | + writer.write("{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}"); |
| 679 | + } |
| 680 | + } |
| 681 | + |
| 682 | + if (Objects.equals(fileName, "")) { |
| 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