Skip to content

Commit

Permalink
java: search for fileName by path added
Browse files Browse the repository at this point in the history
  • Loading branch information
rivexe committed Feb 17, 2023
1 parent 63b7641 commit bf5b8fb
Showing 1 changed file with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.*;

import static utils.Constants.KILOBYTE_SIZE;

Expand Down Expand Up @@ -650,15 +647,45 @@ 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 fileName = (String) fileKey.get("fileName");
String userAddress = (String) fileKey.get("userAddress");
String fileKeyValue = "";
String userAddress = "";
String fileName = "";

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

if (Objects.equals(fileName, "") && !Objects.equals(userAddress, ""))
{
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() + "\"}");
}
}

if (Objects.equals(fileName, "")) {
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 bf5b8fb

Please sign in to comment.