@@ -127,72 +127,6 @@ public class SearchImageService {
|
||||
return mimeType != null && mimeType.startsWith("image");
|
||||
}
|
||||
|
||||
// private String callReverseImageApiByUrl(String imageUrl, String engine, String searchType) throws IOException {
|
||||
// if (searchApiKey == null || searchApiKey.isBlank()) {
|
||||
// throw new IllegalStateException("SearchAPI key not configured");
|
||||
// }
|
||||
//
|
||||
// OkHttpClient client = engine.contains("yandex_reverse_image") ? yandexHttpClient : googleHttpClient;
|
||||
//
|
||||
// HttpUrl url = HttpUrl.parse("https://www.searchapi.io/api/v1/search")
|
||||
// .newBuilder()
|
||||
// .addQueryParameter("engine", engine)
|
||||
// .addQueryParameter("api_key", searchApiKey)
|
||||
// .addQueryParameter("url", imageUrl)
|
||||
// .addQueryParameter("search_type", searchType)
|
||||
// .addQueryParameter("t_", String.valueOf(System.currentTimeMillis()))
|
||||
// .build();
|
||||
//
|
||||
// Request request = new Request.Builder()
|
||||
// .url(url)
|
||||
// .header("Accept", "application/json")
|
||||
// .header("User-Agent", "Mozilla/5.0")
|
||||
// .build();
|
||||
//
|
||||
// int maxAttempts = 2;
|
||||
// IOException lastException = null;
|
||||
//
|
||||
// for (int attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||
// long start = System.currentTimeMillis();
|
||||
//
|
||||
// try (Response response = client.newCall(request).execute()) {
|
||||
// long duration = System.currentTimeMillis() - start;
|
||||
// log.info("Yandex response code={}, duration={}ms, attempt={}",
|
||||
// response.code(), duration, attempt);
|
||||
//
|
||||
// if (!response.isSuccessful()) {
|
||||
// throw new IOException("API error: " + response.code());
|
||||
// }
|
||||
//
|
||||
// ResponseBody body = response.body();
|
||||
// if (body == null) {
|
||||
// throw new IOException("Empty response body");
|
||||
// }
|
||||
//
|
||||
// return body.string();
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// lastException = e;
|
||||
// log.warn("Attempt {} failed for image: {}, error: {}",
|
||||
// attempt, imageUrl, e.getMessage());
|
||||
//
|
||||
// if (attempt == maxAttempts) {
|
||||
// log.error("All {} attempts failed for image: {}", maxAttempts, imageUrl);
|
||||
// throw lastException;
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// Thread.sleep(500L * attempt);
|
||||
// } catch (InterruptedException ie) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// throw new IOException("Retry interrupted", ie);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// throw lastException;
|
||||
// }
|
||||
|
||||
private String callReverseImageApiByUrl(String imageUrl, String engine, String searchType) throws IOException {
|
||||
if (searchApiKey == null || searchApiKey.isBlank()) {
|
||||
throw new IllegalStateException("SearchAPI key not configured");
|
||||
|
||||
Reference in New Issue
Block a user