minio
This commit is contained in:
@@ -201,6 +201,45 @@ public class MarketingController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает изображение поста по имени файла
|
||||
*
|
||||
* @param authHeader Authorization header с JWT токеном
|
||||
* @param imageFilename Имя файла изображения
|
||||
* @return Изображение в формате PNG
|
||||
*/
|
||||
@GetMapping("/images/{imageFilename}")
|
||||
public ResponseEntity<byte[]> getPostImage(
|
||||
@RequestHeader(value = "Authorization", required = false) String authHeader,
|
||||
@PathVariable String imageFilename) {
|
||||
|
||||
String userId = extractUserIdFromHeader(authHeader);
|
||||
if (userId == null) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||
}
|
||||
|
||||
// Проверяем существование файла в MinIO
|
||||
try {
|
||||
if (!minIOService.fileExists(imageFilename)) {
|
||||
logger.warn("Image file not found: {}", imageFilename);
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
// Загружаем изображение из MinIO
|
||||
InputStream inputStream = minIOService.downloadFile(imageFilename);
|
||||
byte[] bytes = inputStream.readAllBytes();
|
||||
inputStream.close();
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
|
||||
.header(HttpHeaders.CACHE_CONTROL, "public, max-age=3600")
|
||||
.body(bytes);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error loading image {}: {}", imageFilename, e.getMessage(), e);
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/strategy/generate")
|
||||
public ResponseEntity<?> generateStrategy(
|
||||
@RequestHeader(value = "Authorization", required = false) String authHeader,
|
||||
|
||||
Reference in New Issue
Block a user