@@ -1,6 +1,9 @@
|
||||
package ru.soune.nocopy.handler;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.vrt.NoCopyFileService;
|
||||
import com.vrt.fileprotection.FileProtector;
|
||||
import com.vrt.fileprotection.NoCopyCheckResult;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -59,6 +62,8 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
|
||||
private final FileSimilarityService fileSimilarityService;
|
||||
|
||||
private final NoCopyFileService noCopyFileService;
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) throws Exception {
|
||||
ImageSearchRequest imageSearchRequest = objectMapper.convertValue(request.getMessageBody(),
|
||||
@@ -144,7 +149,7 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
int page = imageSearchRequest.getPage() != null ? imageSearchRequest.getPage() : 1;
|
||||
int pageSize = 5;
|
||||
|
||||
boolean checkSimilar = imageSearchRequest.getCheckSimilarFirst() == null ? false:
|
||||
boolean checkSimilar = imageSearchRequest.getCheckSimilarFirst() != null &&
|
||||
imageSearchRequest.getCheckSimilarFirst();
|
||||
|
||||
if (checkSimilar && !allUniqueImages.isEmpty()) {
|
||||
@@ -154,31 +159,33 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
try {
|
||||
tempFile = convertToSupportedFormat(fileUploadService.downloadImageFromUrl(url));
|
||||
|
||||
String filePath = tempFile.toAbsolutePath().toString();
|
||||
// String filePath = tempFile.toAbsolutePath().toString();
|
||||
NoCopyCheckResult checkResult = noCopyFileService.checkFile(tempFile.toFile(),
|
||||
FileProtector.Type.IMAGE);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
log.info("checkResult: " + checkResult);
|
||||
// Map<String, Long> hashSearchApiFile = imageHashService.calculateHash(Paths.get(filePath));
|
||||
// ImageHashEntity checkFileHash = imageHashRepository.findByFileId(fileId);
|
||||
|
||||
Map<String, Long> hashSearchApiFile = imageHashService.calculateHash(Paths.get(filePath));
|
||||
// boolean hashesAreEqual = hashSearchApiFile.get("hi").equals(checkFileHash.getHash64Hi())
|
||||
// && hashSearchApiFile.get("low").equals(checkFileHash.getHash64Lo());
|
||||
|
||||
log.info("hashSearchApiFile: " + hashSearchApiFile);
|
||||
log.info("hashSearchApiFile: " + hashSearchApiFile);
|
||||
log.info("hashSearchApiFile: " + hashSearchApiFile);
|
||||
log.info("hashSearchApiFile: " + hashSearchApiFile);
|
||||
|
||||
ImageHashEntity checkFileHash = imageHashRepository.findByFileId(fileId);
|
||||
|
||||
log.info("checkFileHash hi: " + checkFileHash.getHash64Hi());
|
||||
log.info("checkFileHash hi: " + checkFileHash.getHash64Hi());
|
||||
log.info("checkFileHash hi: " + checkFileHash.getHash64Hi());
|
||||
log.info("checkFileHash low: " + checkFileHash.getHash64Lo());
|
||||
log.info("checkFileHash low: " + checkFileHash.getHash64Lo());
|
||||
log.info("checkFileHash low: " + checkFileHash.getHash64Lo());
|
||||
|
||||
boolean hashesAreEqual = hashSearchApiFile.get("hi").equals(checkFileHash.getHash64Hi())
|
||||
&& hashSearchApiFile.get("low").equals(checkFileHash.getHash64Lo());
|
||||
|
||||
if (!hashesAreEqual) {
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
"Not found similar pictures", new YandexSearchResponse());
|
||||
}
|
||||
// if (!hashesAreEqual) {
|
||||
// return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
// "Not found similar pictures", new YandexSearchResponse());
|
||||
// }
|
||||
} finally {
|
||||
if (tempFile != null) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user