This commit is contained in:
@@ -35,6 +35,7 @@ import ru.soune.nocopy.repository.AuthTokenRepository;
|
||||
import ru.soune.nocopy.repository.FileEntityRepository;
|
||||
import ru.soune.nocopy.repository.UserRepository;
|
||||
import ru.soune.nocopy.service.FileSimilarityService;
|
||||
import ru.soune.nocopy.service.file.CheckCounterService;
|
||||
import ru.soune.nocopy.service.file.ProtectionsLimitService;
|
||||
import ru.soune.nocopy.service.register.AuthService;
|
||||
import ru.soune.nocopy.service.file.FileEntityService;
|
||||
@@ -74,6 +75,8 @@ public class ApiController {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
private final CheckCounterService checkCounterService;
|
||||
|
||||
@PostMapping("/v{version}/data")
|
||||
public ResponseEntity<?> handlePostRequest(@RequestBody BaseRequest request,
|
||||
@PathVariable("version") int version) {
|
||||
@@ -174,6 +177,7 @@ public class ApiController {
|
||||
|
||||
try {
|
||||
FileEntity fileEntity = fileEntityRepository.findByFileId(fileId);
|
||||
|
||||
if (fileEntity == null) {
|
||||
return ResponseEntity.ok().body(new BaseResponse(0, MessageCode.INVALID_FIELD.getCode(),
|
||||
MessageCode.INVALID_FIELD.getDescription(), null));
|
||||
@@ -188,6 +192,7 @@ public class ApiController {
|
||||
List<SimilarFileDTO> results = processNonImageFile(fileEntity, authToken);
|
||||
log.info("results: {}", results);
|
||||
response = buildSuccessResponse(results, MessageCode.SIMILAR_FILES_FOUND);
|
||||
checkCounterService.incrementCheckCount(fileEntity.getUserId(), fileEntity.getMimeType());
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package ru.soune.nocopy.handler;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -15,7 +14,6 @@ import ru.soune.nocopy.exception.NotValidFieldException;
|
||||
import ru.soune.nocopy.repository.FileEntityRepository;
|
||||
import ru.soune.nocopy.service.file.CheckCounterService;
|
||||
import ru.soune.nocopy.service.search.SearchImageService;
|
||||
import ru.soune.nocopy.service.search.GoogleVisionSearchService;
|
||||
import ru.soune.nocopy.service.tariff.TariffConstants;
|
||||
import ru.soune.nocopy.service.tariff.TariffInfoService;
|
||||
|
||||
@@ -32,8 +30,6 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
|
||||
private final SearchImageService searchImageService;
|
||||
|
||||
private final GoogleVisionSearchService googleVisionSearchService;
|
||||
|
||||
private final CheckCounterService checkCounterService;
|
||||
|
||||
private final FileEntityRepository fileEntityRepository;
|
||||
@@ -54,7 +50,7 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
Map.of("fileId",fileId)));
|
||||
});
|
||||
|
||||
String searchResponseYandex;
|
||||
// String searchResponseYandex;
|
||||
String searchResponseGoogle;
|
||||
List<YandexSearchResponse.ImageResult> allYandexImages = new ArrayList<>();
|
||||
List<YandexSearchResponse.ImageResult> allGoogleImages = new ArrayList<>();
|
||||
@@ -74,18 +70,18 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
log.error("Google search failed for file {}", fileId, e);
|
||||
}
|
||||
|
||||
try {
|
||||
searchResponseYandex = searchImageService.searchReverseByPublicUrl(fileEntity, "yandex_reverse_image",
|
||||
"visual_matches");
|
||||
log.info("searchResponseYandex OK");
|
||||
allYandexImages = searchImageService.getAllImagesWithoutPagination(
|
||||
searchResponseYandex, "visual_matches");
|
||||
} catch (TimeoutException e) {
|
||||
log.warn("Yandex search timeout for file {}", fileId);
|
||||
hasTimeout = true;
|
||||
} catch (IOException e) {
|
||||
log.error("Yandex search failed for file {}", fileId, e);
|
||||
}
|
||||
// try {
|
||||
// searchResponseYandex = searchImageService.searchReverseByPublicUrl(fileEntity, "yandex_reverse_image",
|
||||
// "visual_matches");
|
||||
// log.info("searchResponseYandex OK");
|
||||
// allYandexImages = searchImageService.getAllImagesWithoutPagination(
|
||||
// searchResponseYandex, "visual_matches");
|
||||
// } catch (TimeoutException e) {
|
||||
// log.warn("Yandex search timeout for file {}", fileId);
|
||||
// hasTimeout = true;
|
||||
// } catch (IOException e) {
|
||||
// log.error("Yandex search failed for file {}", fileId, e);
|
||||
// }
|
||||
|
||||
allUniqueImages = searchImageService.removeDuplicateUrls(allYandexImages, allGoogleImages);
|
||||
log.info("allUniqueImages OK: {} images", allUniqueImages.size());
|
||||
|
||||
@@ -56,15 +56,15 @@ public class MonitoringSearchService {
|
||||
try {
|
||||
tariffInfoService.writeOffTokens(monitoring.getUserId(), tariffMonitoring.getTokens());
|
||||
|
||||
String yandexResponse = searchImageService.searchReverseByPublicUrl(
|
||||
monitoring.getFile(), "yandex_reverse_image", "visual_matches");
|
||||
// String yandexResponse = searchImageService.searchReverseByPublicUrl(
|
||||
// monitoring.getFile(), "yandex_reverse_image", "visual_matches");
|
||||
|
||||
List<YandexSearchResponse.ImageResult> yandexImages =
|
||||
searchImageService.getAllImagesWithoutPagination(yandexResponse, "visual_matches");
|
||||
// List<YandexSearchResponse.ImageResult> yandexImages =
|
||||
// searchImageService.getAllImagesWithoutPagination(yandexResponse, "visual_matches");
|
||||
|
||||
for (YandexSearchResponse.ImageResult imageResult : yandexImages) {
|
||||
violationService.processViolation(imageResult, monitoring.getFile(), null);
|
||||
}
|
||||
// for (YandexSearchResponse.ImageResult imageResult : yandexImages) {
|
||||
// violationService.processViolation(imageResult, monitoring.getFile(), null);
|
||||
// }
|
||||
|
||||
try {
|
||||
String googleResponse = searchImageService.searchReverseByPublicUrl(
|
||||
|
||||
@@ -44,7 +44,6 @@ public class SearchImageService {
|
||||
.followRedirects(true)
|
||||
.followSslRedirects(true)
|
||||
.retryOnConnectionFailure(true)
|
||||
// .connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
|
||||
.build();
|
||||
|
||||
this.googleHttpClient = new OkHttpClient.Builder()
|
||||
@@ -56,7 +55,6 @@ public class SearchImageService {
|
||||
.followRedirects(true)
|
||||
.followSslRedirects(true)
|
||||
.retryOnConnectionFailure(true)
|
||||
// .connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
|
||||
.build();
|
||||
|
||||
this.objectMapper = new ObjectMapper();
|
||||
|
||||
Reference in New Issue
Block a user