Revert "dev add violation notion"
Test Workflow / test (push) Successful in 3s

This reverts commit 4ff5c5ec13.
This commit is contained in:
vladp
2026-03-20 16:02:11 +07:00
parent a9b7b7ca6e
commit 726da25ddf
9 changed files with 153 additions and 350 deletions
@@ -5,11 +5,11 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.soune.nocopy.configuration.search.SearchProperties;
import ru.soune.nocopy.dto.file.YandexSearchResponse;
import ru.soune.nocopy.dto.tarriff.TariffDTO;
import ru.soune.nocopy.entity.monitoring.FileMonitoringEntity;
import ru.soune.nocopy.entity.monitoring.MonitoringType;
import ru.soune.nocopy.entity.search.GlobalSearchResult;
import ru.soune.nocopy.entity.tarif.TariffInfo;
import ru.soune.nocopy.entity.tarif.TariffType;
import ru.soune.nocopy.entity.user.User;
@@ -24,7 +24,6 @@ import ru.soune.nocopy.service.violation.ViolationService;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;
@@ -46,8 +45,6 @@ public class MonitoringSearchService {
private final ViolationService violationService;
private final SearchProperties searchProperties;
@Transactional
public void processFileSearch(FileMonitoringEntity monitoring) throws MessagingException, IOException {
monitoring.setLastRun(LocalDateTime.now());
@@ -56,78 +53,36 @@ public class MonitoringSearchService {
MonitoringType monitoringType = monitoring.getMonitoringType();
TariffDTO tariffMonitoring = tariffService.getTariffByType(TariffType.valueOf(monitoringType.name()));
try {
tariffInfoService.writeOffTokens(monitoring.getUserId(), tariffMonitoring.getTokens());
boolean useYandex = searchProperties.getEngines().getOrDefault("yandex",
new SearchProperties.EngineConfig()).isEnabled();
boolean useGoogle = searchProperties.getEngines().getOrDefault("google",
new SearchProperties.EngineConfig()).isEnabled();
String yandexResponse = searchImageService.searchReverseByPublicUrl(
monitoring.getFile(), "yandex_reverse_image", "visual_matches");
log.info("Monitoring search settings: useYandex={}, useGoogle={}", useYandex, useGoogle);
List<YandexSearchResponse.ImageResult> yandexImages =
searchImageService.getAllImagesWithoutPagination(yandexResponse, "visual_matches");
List<YandexSearchResponse.ImageResult> allResults = new ArrayList<>();
if (useYandex) {
try {
String yandexResponse = searchImageService.searchReverseByPublicUrl(
monitoring.getFile(), "yandex_reverse_image", "visual_matches");
List<YandexSearchResponse.ImageResult> yandexImages =
searchImageService.getAllImagesWithoutPagination(yandexResponse, "visual_matches");
allResults.addAll(yandexImages);
log.info("Yandex search found {} results", yandexImages.size());
} catch (TimeoutException e) {
log.warn("Yandex search timeout for monitoring file {}", monitoring.getFile().getId());
} catch (IOException e) {
log.error("Yandex search failed for monitoring file {}", monitoring.getFile().getId(), e);
}
} else {
log.info("Yandex search is disabled by settings");
}
if (useGoogle) {
try {
String googleResponse = searchImageService.searchReverseByPublicUrl(
monitoring.getFile(), "google_lens", "exact_matches");
List<YandexSearchResponse.ImageResult> googleImages =
searchImageService.getAllImagesWithoutPagination(googleResponse, "exact_matches");
allResults.addAll(googleImages);
log.info("Google search found {} results", googleImages.size());
} catch (TimeoutException e) {
log.warn("Google search timeout for monitoring file {}", monitoring.getFile().getId());
} catch (IOException e) {
log.error("Google search failed for monitoring file {}", monitoring.getFile().getId(), e);
}
} else {
log.info("Google search is disabled by settings");
}
List<YandexSearchResponse.ImageResult> uniqueResults = allResults;
if (useYandex && useGoogle) {
uniqueResults = searchImageService.removeDuplicateUrls(
useYandex ? allResults : new ArrayList<>(),
useGoogle ? allResults : new ArrayList<>()
);
log.info("After deduplication: {} unique results", uniqueResults.size());
}
for (YandexSearchResponse.ImageResult imageResult : uniqueResults) {
for (YandexSearchResponse.ImageResult imageResult : yandexImages) {
violationService.processViolation(imageResult, monitoring.getFile(), null);
}
// try {
// String googleResponse = searchImageService.searchReverseByPublicUrl(
// monitoring.getFile(), "google_lens", "exact_matches");
//
// List<YandexSearchResponse.ImageResult> googleImages =
// searchImageService.getAllImagesWithoutPagination(googleResponse, "exact_matches");
//
//
// for (YandexSearchResponse.ImageResult imageResult : googleImages) {
// violationService.processViolation(imageResult, monitoring.getFile(), null);
// }
//
// } catch (TimeoutException | IOException e) {
// log.warn("Google search failed");
// }
monitoring.setLastRunStatus("SUCCESS");
if (uniqueResults.isEmpty()) {
log.info("No results found for monitoring file {}", monitoring.getFile().getId());
}
} catch (TariffNotFoundException e) {
User user = userRepository.findById(monitoring.getUserId()).orElseThrow();
TariffInfo activeTariffInfo = user.getActiveTariffInfo();
@@ -136,12 +91,10 @@ public class MonitoringSearchService {
emailService.sendTokensNotFoundEmail(user, currentTokens, tariffMonitoring.getTokens());
monitoring.setLastRunStatus("ERROR: " + e.getMessage());
updateNextRun(monitoring);
monitoringRepository.save(monitoring);
} catch (Exception e) {
log.error("Error processing monitoring search", e);
monitoring.setLastRunStatus("ERROR: " + e.getMessage());
} finally {
updateNextRun(monitoring);
monitoringRepository.save(monitoring);