This commit is contained in:
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -24,18 +26,13 @@ import java.util.concurrent.*;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SearchImageService {
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
private final SearchProperties searchProperties;
|
||||
|
||||
public SearchImageService(SearchProperties searchProperties) {
|
||||
this.searchProperties = searchProperties;
|
||||
this.objectMapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
@Value("${yandex.api-key}")
|
||||
private String apiKey;
|
||||
|
||||
@@ -57,6 +54,11 @@ public class SearchImageService {
|
||||
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
}
|
||||
|
||||
@Cacheable(
|
||||
value = "reverseImageSearch",
|
||||
key = "#fileEntity.id + '_' + #engine + '_' + #searchType",
|
||||
unless = "#result == null || #result.isEmpty()"
|
||||
)
|
||||
public String searchReverseByPublicUrl(FileEntity fileEntity, String engine, String searchType)
|
||||
throws IOException, TimeoutException {
|
||||
|
||||
@@ -153,6 +155,12 @@ public class SearchImageService {
|
||||
}
|
||||
}
|
||||
|
||||
@Cacheable(
|
||||
value = "parsedImages",
|
||||
key = "#searchApiJson + '_' + #findType",
|
||||
condition = "#searchApiJson != null && #searchApiJson.length() > 0",
|
||||
unless = "#result == null || #result.isEmpty()"
|
||||
)
|
||||
public List<YandexSearchResponse.ImageResult> getAllImagesWithoutPagination(String searchApiJson, String findType)
|
||||
throws IOException {
|
||||
JsonNode root = objectMapper.readTree(searchApiJson);
|
||||
|
||||
Reference in New Issue
Block a user