@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user