dev add check similar
Test Workflow / test (push) Has been cancelled

This commit is contained in:
2026-04-29 18:14:15 +07:00
parent 9686eb453f
commit 18383b1b62
2 changed files with 18 additions and 1 deletions
@@ -25,6 +25,8 @@ import ru.soune.nocopy.service.search.SearchImageService;
import ru.soune.nocopy.service.tariff.TariffConstants;
import ru.soune.nocopy.service.tariff.TariffInfoService;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -150,7 +152,7 @@ public class ImageFoundRequestHandler implements RequestHandler {
String url = image.getUrl();
Path tempFile = null;
try {
tempFile = fileUploadService.downloadImageFromUrl(url);
tempFile = convertToSupportedFormat(fileUploadService.downloadImageFromUrl(url));
String filePath = tempFile.toAbsolutePath().toString();
@@ -191,4 +193,18 @@ public class ImageFoundRequestHandler implements RequestHandler {
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
message, finalResponse);
}
public Path convertToSupportedFormat(Path imagePath) throws IOException {
String fileName = imagePath.getFileName().toString().toLowerCase();
if (fileName.matches(".*\\.(jpg|jpeg|png|bmp)$")) {
return imagePath;
}
BufferedImage image = ImageIO.read(imagePath.toFile());
Path pngFile = Files.createTempFile("converted_", ".png");
ImageIO.write(image, "PNG", pngFile.toFile());
return pngFile;
}
}