Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b1ed5fe67 | ||
|
|
b3a3d57ee3 |
+4
-2
@@ -65,9 +65,11 @@ services:
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_PORT: 5432
|
||||
POSTGRES_HOST: db
|
||||
YANDEX_SEARCH_API_KEY: AQVNyaVaUmgUb1GMCtf5zSEqFxy0woXrcMOOB43q
|
||||
YANDEX_SEARCH_FOLDER_ID: b1gokpdbm6qfpsou8pcd
|
||||
YANDEX_API_KEY: AQVNyaVaUmgUb1GMCtf5zSEqFxy0woXrcMOOB43q
|
||||
YANDEX_FOLDER_ID: b1gokpdbm6qfpsou8pcd
|
||||
YANDEX_SEARCH_URL: "https://searchapi.api.cloud.yandex.net/v2/image/search_by_image"
|
||||
STORAGE_SERVICE_URL: http://storage:8081
|
||||
SPRING_PROFILES_ACTIVE: docker
|
||||
depends_on:
|
||||
- db
|
||||
ports:
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package ru.soune.nocopy.configuration.file;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yandex")
|
||||
public class YandexConfig {
|
||||
private String apiKey;
|
||||
private String folderId;
|
||||
private String searchUrl;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package ru.soune.nocopy.handler;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.soune.nocopy.dto.BaseRequest;
|
||||
import ru.soune.nocopy.dto.BaseResponse;
|
||||
@@ -18,6 +19,7 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Autowired
|
||||
private final YandexSearchService yandexSearchService;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,13 +32,13 @@ public class YandexSearchService {
|
||||
private final FileEntityRepository fileEntityRepository;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Value("${yandex.api-key}")
|
||||
@Value("${YANDEX_API_KEY}")
|
||||
private String apiKey;
|
||||
|
||||
@Value("${yandex.folder-id}")
|
||||
@Value("${YANDEX_FOLDER_ID}")
|
||||
private String folderId;
|
||||
|
||||
@Value("${yandex.search-url}")
|
||||
@Value("${YANDEX_SEARCH_URL}")
|
||||
private String searchUrl;
|
||||
|
||||
@PostConstruct
|
||||
@@ -54,6 +54,7 @@ public class YandexSearchService {
|
||||
MessageCode.FILE_NOT_FOUND.getCode(), MessageCode.FILE_NOT_FOUND.getDescription(),
|
||||
Map.of("fileId",fileId)));
|
||||
});
|
||||
byte[] fileBytes;
|
||||
|
||||
if (!isImageFile(fileEntity)) {
|
||||
log.error("File not image: {}", fileEntity.getMimeType());
|
||||
@@ -62,7 +63,14 @@ public class YandexSearchService {
|
||||
Map.of("file_type", fileEntity.getMimeType())));
|
||||
}
|
||||
|
||||
byte[] fileBytes = readFileFromDisk(fileEntity);
|
||||
try {
|
||||
fileBytes = readFileFromDisk(fileEntity);
|
||||
} catch (IOException e) {
|
||||
throw new NotValidFieldException("File not found or cannot read file", new BaseResponse(20007,
|
||||
MessageCode.FILE_NOT_FOUND.getCode(), MessageCode.FILE_NOT_FOUND.getDescription(),
|
||||
Map.of("fileId", fileId,
|
||||
"filePath", fileEntity.getFilePath())));
|
||||
}
|
||||
|
||||
return callYandexApi(fileBytes);
|
||||
}
|
||||
@@ -99,7 +107,6 @@ public class YandexSearchService {
|
||||
connection.setRequestProperty("Authorization", "Api-Key " + apiKey);
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setRequestProperty("Accept", "application/json");
|
||||
// connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
connection.setConnectTimeout(30000);
|
||||
connection.setReadTimeout(30000);
|
||||
connection.setDoOutput(true);
|
||||
|
||||
@@ -40,11 +40,6 @@ security:
|
||||
allowed-headers: "*"
|
||||
allow-credentials: true
|
||||
|
||||
yandex:
|
||||
api-key: ${YANDEX_SEARCH_API_KEY}
|
||||
folder-id: ${YANDEX_SEARCH_FOLDER_ID}
|
||||
search-url: "https://searchapi.api.cloud.yandex.net/v2/image/search_by_image"
|
||||
|
||||
server:
|
||||
port: ${SERVER_PORT:8080}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user